Adding patch from Ticket #2176, extracts the sequence name from the default value for the primary key and returns it's last value

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4572 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-03-04 04:54:48 +00:00
parent f05ab47e94
commit b3b1c80a69

View file

@ -357,7 +357,13 @@ class DboPostgres extends DboSource {
return null;
}
$sql = "SELECT last_value AS max FROM \"{$source}_{$field}_seq\"";
if (preg_match('/^nextval\(\'(\w+)\'/', $sourceinfo['default'], $matches)) {
$seq = $matches[1];
} else {
$seq = "{$source}_{$field}_seq";
}
$sql = "SELECT last_value AS max FROM \"{$seq}\"";
$res = $this->rawQuery($sql);
$data = $this->fetchRow($res);
return $data[0]['max'];