diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-31 20:38:14 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-31 20:38:14 +0000 |
| commit | 3d38969fd4f88d996d438df63f7cbb1833b63429 (patch) | |
| tree | 33f33709c5abcfad827bcc0460f9a51558e36542 /lib/sqlalchemy/dialects/postgresql | |
| parent | f3480a7ff4d0994bf201f830f31f416a7b1e9f0f (diff) | |
| download | sqlalchemy-3d38969fd4f88d996d438df63f7cbb1833b63429.tar.gz | |
- Inserting NULL into a primary key + foreign key column
will allow the "not null constraint" error to raise,
not an attempt to execute a nonexistent "col_id_seq"
sequence. [ticket:1516]
- autoincrement SELECT statements, i.e. those which
select from a procedure that modifies rows, now work
with server-side cursor mode (the named cursor isn't
used for such statements.)
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 25 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 1 |
2 files changed, 12 insertions, 14 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 321601a83..7f9cc889a 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -333,32 +333,29 @@ class PGDDLCompiler(compiler.DDLCompiler): class PGDefaultRunner(base.DefaultRunner): - def __init__(self, context): - base.DefaultRunner.__init__(self, context) - # craete cursor which won't conflict with a server-side cursor - self.cursor = context._connection.connection.cursor() - + def get_column_default(self, column, isinsert=True): if column.primary_key: - # pre-execute passive defaults on primary keys if (isinstance(column.server_default, schema.DefaultClause) and column.server_default.arg is not None): + + # pre-execute passive defaults on primary key columns return self.execute_string("select %s" % column.server_default.arg) - elif (isinstance(column.type, sqltypes.Integer) and column.autoincrement) \ + + elif column is column.table._autoincrement_column \ and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)): + + # execute the sequence associated with a SERIAL primary key column. + # for non-primary-key SERIAL, the ID just generates server side. sch = column.table.schema - # TODO: this has to build into the Sequence object so we can get the quoting - # logic from it + if sch is not None: exc = "select nextval('\"%s\".\"%s_%s_seq\"')" % (sch, column.table.name, column.name) else: exc = "select nextval('\"%s_%s_seq\"')" % (column.table.name, column.name) - if self.dialect.supports_unicode_statements: - return self.execute_string(exc) - else: - return self.execute_string(exc.encode(self.dialect.encoding)) - + return self.execute_string(exc) + return super(PGDefaultRunner, self).get_column_default(column) def visit_sequence(self, seq): diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 973bacd06..a09697e79 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -70,6 +70,7 @@ class PostgreSQL_psycopg2ExecutionContext(default.DefaultExecutionContext): # TODO: coverage for server side cursors + select.for_update() is_server_side = \ self.dialect.server_side_cursors and \ + not self.should_autocommit and \ ((self.compiled and isinstance(self.compiled.statement, expression.Selectable) and not getattr(self.compiled.statement, 'for_update', False)) \ or \ |
