summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-01-01 21:08:22 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-01-01 21:08:22 +0000
commit705f308452b0741747c27ee4edcd75f2ec0e6ae8 (patch)
tree9f23719ca0098f8d5a933aefc86a8abe32509f80 /lib/sqlalchemy/databases/postgres.py
parent943bb0b0e08fec9bc0ccc784a4dd154783031e8d (diff)
downloadsqlalchemy-705f308452b0741747c27ee4edcd75f2ec0e6ae8.tar.gz
rowid_column becomes more like the "order by column". 'default_ordering' flag sent to create_engine enables whether or not the rowid_column on a Table will be None or not. mappers/relations will by default use the rowid_column for ordering if its not None, else theres no default ordering.
still should better define 'default_ordering'/'rowid_column' relationship since its a little kludgy.
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index 3ae83cb8c..e00d16d04 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -106,7 +106,8 @@ def descriptor():
]}
class PGSQLEngine(ansisql.ANSISQLEngine):
- def __init__(self, opts, module = None, **params):
+ def __init__(self, opts, module=None, use_oids=False, **params):
+ self.use_oids = use_oids
if module is None:
if psycopg is None:
raise "Couldnt locate psycopg1 or psycopg2: specify postgres module argument"
@@ -153,20 +154,28 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
def last_inserted_ids(self):
return self.context.last_inserted_ids
+ def rowid_column_name(self):
+ if self.use_oids:
+ return "oid"
+ else:
+ return None
+
def pre_exec(self, proxy, statement, parameters, **kwargs):
return
def post_exec(self, proxy, compiled, parameters, **kwargs):
if getattr(compiled, "isinsert", False) and self.context.last_inserted_ids is None:
- raise "cant use cursor.lastrowid without OIDs enabled"
- table = compiled.statement.table
- cursor = proxy()
- if cursor.lastrowid is not None and table is not None and len(table.primary_key):
- s = sql.select(table.primary_key, table.rowid_column == cursor.lastrowid)
- c = s.compile()
- cursor = proxy(str(c), c.get_params())
- row = cursor.fetchone()
- self.context.last_inserted_ids = [v for v in row]
+ if not self.use_oids:
+ raise "cant use cursor.lastrowid without OIDs enabled"
+ else:
+ table = compiled.statement.table
+ cursor = proxy()
+ if cursor.lastrowid is not None and table is not None and len(table.primary_key):
+ s = sql.select(table.primary_key, table.rowid_column == cursor.lastrowid)
+ c = s.compile()
+ cursor = proxy(str(c), c.get_params())
+ row = cursor.fetchone()
+ self.context.last_inserted_ids = [v for v in row]
def _executemany(self, c, statement, parameters):
"""we need accurate rowcounts for updates, inserts and deletes. psycopg2 is not nice enough
@@ -177,7 +186,6 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
rowcount += c.rowcount
self.context.rowcount = rowcount
-
def dbapi(self):
return self.module