summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py25
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py1
-rw-r--r--lib/sqlalchemy/engine/default.py2
-rw-r--r--lib/sqlalchemy/sql/compiler.py3
4 files changed, 14 insertions, 17 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 \
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index 935d1e087..78164e459 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -254,8 +254,8 @@ class DefaultExecutionContext(base.ExecutionContext):
else:
self.statement = statement
self.isinsert = self.isupdate = self.isdelete = False
- self.cursor = self.create_cursor()
self.should_autocommit = self.should_autocommit_text(statement)
+ self.cursor = self.create_cursor()
else:
# no statement. used for standalone ColumnDefault execution.
self.statement = self.compiled = None
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 78529ee6d..7bd0c1b05 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -844,8 +844,7 @@ class SQLCompiler(engine.Compiled):
self.dialect.supports_sequences or
not isinstance(c.default, schema.Sequence)
)
- ) or \
- self.dialect.preexecute_autoincrement_sequences:
+ ) or self.dialect.preexecute_autoincrement_sequences:
values.append((c, self._create_crud_bind_param(c, None)))
self.prefetch.append(c)