From: Mike Bayer Date: Sat, 22 Oct 2005 07:10:35 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~473 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a716f3b12b71b3506a08a226fd51fd199c54c2a1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 6a7bf6acc2..cfaf63b57f 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -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]