Fixed issue 1962, postgres INSERT ... RETURING id, thanks perakojotgenije

This commit is contained in:
mdipierro
2014-08-07 23:43:22 -05:00
parent a858f811a1
commit 6db3b0621c
2 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.9.5-trunk+timestamp.2014.08.07.23.32.34
Version 2.9.5-trunk+timestamp.2014.08.07.23.42.12
+21 -3
View File
@@ -2884,10 +2884,28 @@ class PostgreSQLAdapter(BaseAdapter):
self.execute("SET standard_conforming_strings=on;")
self.try_json()
def lastrowid(self, table=None):
self.execute("select lastval()")
return int(self.cursor.fetchone()[0])
def _insert(self, table, fields):
table_rname = table.sqlsafe
if fields:
keys = ','.join(f.sqlsafe_name for f, v in fields)
values = ','.join(self.expand(v, f.type) for f, v in fields)
if table._id:
self._last_insert = (table._id, 1)
return 'INSERT INTO %s(%s) VALUES (%s) RETURNING %s;' % (
table_rname, keys, values, table._id.name)
else:
self._last_insert = None
return 'INSERT INTO %s(%s) VALUES (%s);' % (table_rname, keys, values)
else:
return self._insert_empty(table)
def lastrowid(self, table=None):
if self._last_insert:
return int(self.cursor.fetchone()[0])
else:
self.execute("select lastval()")
return int(self.cursor.fetchone()[0])
def try_json(self):
# check JSON data type support
# (to be added to after_connection)