diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-10-15 16:09:59 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-10-15 16:09:59 +0000 |
commit | bc351a2dc423987f05f4bf88db4987be507ee0a1 (patch) | |
tree | 9f6f8c8ab74abfa8d2d03690178693d0412ca462 /lib/sqlalchemy/dialects/postgresql | |
parent | ad89932715193275d37b5e22b830f092e350b1fe (diff) | |
download | sqlalchemy-bc351a2dc423987f05f4bf88db4987be507ee0a1.tar.gz |
- DefaultRunner and subclasses have been removed. The job
of this object has been simplified and moved into
ExecutionContext. Dialects which support sequences should
add a `fire_sequence()` method to their execution context
implementation. [ticket:1566]
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 69 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pg8000.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pypostgresql.py | 10 |
4 files changed, 40 insertions, 47 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 19d9224e2..0bc5f08b0 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -332,40 +332,6 @@ class PGDDLCompiler(compiler.DDLCompiler): return text -class PGDefaultRunner(base.DefaultRunner): - - def get_column_default(self, column, isinsert=True): - if column.primary_key: - 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 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 - - 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) - - return self.execute_string(exc) - - return super(PGDefaultRunner, self).get_column_default(column) - - def visit_sequence(self, seq): - if not seq.optional: - return self.execute_string(("select nextval('%s')" % \ - self.dialect.identifier_preparer.format_sequence(seq))) - else: - return None - - class PGTypeCompiler(compiler.GenericTypeCompiler): def visit_INET(self, type_): return "INET" @@ -438,6 +404,39 @@ class PGInspector(reflection.Inspector): info_cache=self.info_cache) + +class PGExecutionContext(default.DefaultExecutionContext): + def fire_sequence(self, seq): + if not seq.optional: + return self._execute_scalar(("select nextval('%s')" % \ + self.dialect.identifier_preparer.format_sequence(seq))) + else: + return None + + def get_insert_default(self, column): + if column.primary_key: + 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_scalar("select %s" % column.server_default.arg) + + 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 + + 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) + + return self._execute_scalar(exc) + + return super(PGExecutionContext, self).get_insert_default(column) + class PGDialect(default.DefaultDialect): name = 'postgresql' supports_alter = True @@ -459,7 +458,7 @@ class PGDialect(default.DefaultDialect): ddl_compiler = PGDDLCompiler type_compiler = PGTypeCompiler preparer = PGIdentifierPreparer - defaultrunner = PGDefaultRunner + execution_ctx_cls = PGExecutionContext inspector = PGInspector isolation_level = None diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 1c45b50f2..17fe86be6 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -23,7 +23,7 @@ from sqlalchemy.engine import default import decimal from sqlalchemy import util from sqlalchemy import types as sqltypes -from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer +from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext class _PGNumeric(sqltypes.Numeric): def bind_processor(self, dialect): @@ -41,7 +41,7 @@ class _PGNumeric(sqltypes.Numeric): return process -class PostgreSQL_pg8000ExecutionContext(default.DefaultExecutionContext): +class PostgreSQL_pg8000ExecutionContext(PGExecutionContext): pass diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index a09697e79..50e4bec3b 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -42,7 +42,7 @@ from sqlalchemy.engine import base, default from sqlalchemy.sql import expression from sqlalchemy.sql import operators as sql_operators from sqlalchemy import types as sqltypes -from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer +from sqlalchemy.dialects.postgresql.base import PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext class _PGNumeric(sqltypes.Numeric): def bind_processor(self, dialect): @@ -65,7 +65,7 @@ SERVER_SIDE_CURSOR_RE = re.compile( r'\s*SELECT', re.I | re.UNICODE) -class PostgreSQL_psycopg2ExecutionContext(default.DefaultExecutionContext): +class PostgreSQL_psycopg2ExecutionContext(PGExecutionContext): def create_cursor(self): # TODO: coverage for server side cursors + select.for_update() is_server_side = \ diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py index 975006d92..517d41aaf 100644 --- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py +++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py @@ -11,7 +11,7 @@ from sqlalchemy.engine import default import decimal from sqlalchemy import util from sqlalchemy import types as sqltypes -from sqlalchemy.dialects.postgresql.base import PGDialect, PGDefaultRunner +from sqlalchemy.dialects.postgresql.base import PGDialect, PGExecutionContext class PGNumeric(sqltypes.Numeric): def bind_processor(self, dialect): @@ -28,13 +28,9 @@ class PGNumeric(sqltypes.Numeric): return value return process -class PostgreSQL_pypostgresqlExecutionContext(default.DefaultExecutionContext): +class PostgreSQL_pypostgresqlExecutionContext(PGExecutionContext): pass -class PostgreSQL_pypostgresqlDefaultRunner(PGDefaultRunner): - def execute_string(self, stmt, params=None): - return PGDefaultRunner.execute_string(self, stmt, params or ()) - class PostgreSQL_pypostgresql(PGDialect): driver = 'pypostgresql' @@ -43,8 +39,6 @@ class PostgreSQL_pypostgresql(PGDialect): supports_unicode_binds = True description_encoding = None - defaultrunner = PostgreSQL_pypostgresqlDefaultRunner - default_paramstyle = 'format' supports_sane_rowcount = False # alas....posting a bug now |