diff --git a/VERSION b/VERSION index 549f7805..f75be63a 100644 --- a/VERSION +++ b/VERSION @@ -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 diff --git a/gluon/dal.py b/gluon/dal.py index 2677b723..5abee708 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -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)