summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/databases/postgres.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-09-01 19:49:26 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-09-01 19:49:26 +0000
commit69f7084c9b79b0b70f2b24400fb150a0a40d0424 (patch)
tree1da7f3a6b0a873472b57ad0e093339be6cff0b48 /lib/sqlalchemy/databases/postgres.py
parent15ab87994ced6f27e0403ce16fd7ffada31e6858 (diff)
downloadsqlalchemy-69f7084c9b79b0b70f2b24400fb150a0a40d0424.tar.gz
- merged inline inserts branch
- all executemany() style calls put all sequences and SQL defaults inline into a single SQL statement and don't do any pre-execution - regular Insert and Update objects can have inline=True, forcing all executions to be inlined. - no last_inserted_ids(), lastrow_has_defaults() available with inline execution - calculation of pre/post execute pushed into compiler; DefaultExecutionContext greatly simplified - fixed postgres reflection of primary key columns with no sequence/default generator, sets autoincrement=False - fixed postgres executemany() behavior regarding sequences present, not present, passivedefaults, etc. - all tests pass for sqlite, mysql, postgres; oracle tests pass as well as they did previously including all insert/update/default functionality
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r--lib/sqlalchemy/databases/postgres.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py
index eecdcebbd..a5c77f206 100644
--- a/lib/sqlalchemy/databases/postgres.py
+++ b/lib/sqlalchemy/databases/postgres.py
@@ -227,6 +227,7 @@ class PGDialect(default.DefaultDialect):
supports_unicode_statements = False
max_identifier_length = 63
supports_sane_rowcount = True
+ supports_sane_multi_rowcount = False
def __init__(self, use_oids=False, server_side_cursors=False, **kwargs):
default.DefaultDialect.__init__(self, default_paramstyle='pyformat', **kwargs)
@@ -297,19 +298,6 @@ class PGDialect(default.DefaultDialect):
else:
return None
- def do_executemany(self, c, statement, parameters, context=None):
- """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)
- rowcount += c.rowcount
- if context is not None:
- context._rowcount = rowcount
-
def has_table(self, connection, table_name, schema=None):
# seems like case gets folded in pg_class...
if schema is None:
@@ -473,7 +461,10 @@ class PGDialect(default.DefaultDialect):
c = connection.execute(t, table=table_oid)
for row in c.fetchall():
pk = row[0]
- table.primary_key.add(table.c[pk])
+ col = table.c[pk]
+ table.primary_key.add(col)
+ if col.default is None:
+ col.autoincrement=False
# Foreign keys
FK_SQL = """
@@ -555,6 +546,12 @@ class PGCompiler(compiler.DefaultCompiler):
def uses_sequences_for_inserts(self):
return True
+ def visit_sequence(self, seq):
+ if seq.optional:
+ return None
+ else:
+ return "nextval('%s')" % self.preparer.format_sequence(seq)
+
def limit_clause(self, select):
text = ""
if select._limit is not None: