Created
September 8, 2011 14:32
-
-
Save yury-n/1203531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calculate_row_id($log_id) { | |
if ($this->get_autoinc_type() == self::AUTOINC_ODD_EVEN) { | |
$row_id = ceil($log_id / 2) % $this->get_max_rows(); | |
} | |
elseif ($this->get_autoinc_type() == self::AUTOINC_NORMAL) { | |
$row_id = ($log_id - 1) % $this->get_max_rows() + 1; | |
} | |
return $row_id; | |
} | |
protected function _get_invariant_columns() { | |
if ($this->get_autoinc_type() == self::AUTOINC_NORMAL) { | |
$ddb_expression = '(SELECT COALESCE(MAX('.$this->get_log_id_column().'), 0) ' . | |
'% '.$this->get_max_rows().' + 1 ' . | |
'FROM '.$this->get_table_name().' AS t)'; | |
} | |
elseif ($this->get_autoinc_type() == self::AUTOINC_ODD_EVEN) { | |
$ddb_expression = '(SELECT CEIL(COALESCE(MAX('.$this->get_log_id_column().'), -1) + 2 / 2)' . | |
'% '.$this->get_max_rows() . | |
'FROM '.$this->get_table_name().' AS t)'; | |
} | |
return array($this->get_row_id_column() => DDBExpression($ddb_expression)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment