]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Oct 2005 07:10:35 +0000 (07:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 Oct 2005 07:10:35 +0000 (07:10 +0000)
lib/sqlalchemy/databases/postgres.py

index 6a7bf6acc265223f0391da4a514a0f09fa99e6ed..cfaf63b57fa8ec46d8b98b788cd8e1f5eb9c896c 100644 (file)
@@ -112,6 +112,8 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
             self.context.last_inserted_ids = last_inserted_ids
 
     def _executemany(self, c, statement, parameters):
+        """we need accurate rowcounts for updates, inserts and deletes.  psycopg2 is not nice enough
+        to produce this correctly for an executemany, so we do our own executemany here."""
         rowcount = 0
         for param in parameters:
             c.execute(statement, param)
@@ -121,11 +123,15 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
     def post_exec(self, connection, cursor, statement, parameters, echo = None, compiled = None, **kwargs):
         if compiled is None: return
         if getattr(compiled, "isinsert", False):
-            # psycopg wants to make it hard on us and give us an OID.  well, pre-select a sequence,
-            # or post-select the row, I guess not much diff.
+            # psycopg wants to return internal rowids, which I guess is what DBAPI2 really 
+            # specifies.
+            # well then post exec to get the row.  I guess this could be genericised to 
+            # be for all inserts somehow if the "rowid" col could be gotten off a table.
             table = compiled.statement.table
             if len(table.primary_keys):
                 # TODO: cache this statement against the table to avoid multiple re-compiles
+                # TODO: instead of "oid" have the Table object have a "rowid_col" property
+                # that gives this col generically
                 row = sql.select(table.primary_keys, sql.ColumnClause("oid",table) == bindparam('oid', cursor.lastrowid) ).execute().fetchone()
                 self.context.last_inserted_ids = [v for v in row]