From 2e44749b76af4e9e1a2fd6e52dd329dc1e980216 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Sat, 26 Jul 2014 18:56:56 +0100 Subject: Remove spurious print statements in pg8000 dialect --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 68da5b6d7..2793b048d 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -172,11 +172,9 @@ class PGDialect_pg8000(PGDialect): ) def do_begin_twophase(self, connection, xid): - print("begin twophase", xid) connection.connection.tpc_begin((0, xid, '')) def do_prepare_twophase(self, connection, xid): - print("prepare twophase", xid) connection.connection.tpc_prepare() def do_rollback_twophase( -- cgit v1.2.1 From 0dbe9d9aaf22d69e44c486472ff3b412a96cf216 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Sat, 2 Aug 2014 16:19:46 +0100 Subject: pg8000 now supports sane_multi_rowcount From pg8000-1.9.14 sane_multi_rowcount is supported so this commit updates the dialect accordingly. --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 2793b048d..909b41b82 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -119,7 +119,7 @@ class PGDialect_pg8000(PGDialect): supports_unicode_binds = True default_paramstyle = 'format' - supports_sane_multi_rowcount = False + supports_sane_multi_rowcount = True execution_ctx_cls = PGExecutionContext_pg8000 statement_compiler = PGCompiler_pg8000 preparer = PGIdentifierPreparer_pg8000 -- cgit v1.2.1 From 589f205d53f031ceb297af760f2acfc777a5bc5d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 16 Aug 2014 13:57:46 -0400 Subject: - changelog for pullreq github:125 - add pg8000 version detection for the "sane multi rowcount" feature --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 909b41b82..4ccc90208 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -133,6 +133,16 @@ class PGDialect_pg8000(PGDialect): } ) + def initialize(self, connection): + if self.dbapi and hasattr(self.dbapi, '__version__'): + self._dbapi_version = tuple([ + int(x) for x in + self.dbapi.__version__.split(".")]) + else: + self._dbapi_version = (99, 99, 99) + self.supports_sane_multi_rowcount = self._dbapi_version >= (1, 9, 14) + super(PGDialect_pg8000, self).initialize(connection) + @classmethod def dbapi(cls): return __import__('pg8000') -- cgit v1.2.1 From ef6042ff461e490c2a3040f18f0a3688b2e601a0 Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Wed, 13 Aug 2014 01:39:09 +0200 Subject: Adding a tablespace options for postgresql create table --- lib/sqlalchemy/dialects/postgresql/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index c2b1d66f4..0f008642e 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1448,6 +1448,13 @@ class PGDDLCompiler(compiler.DDLCompiler): text += self.define_constraint_deferrability(constraint) return text + def post_create_table(self, table): + table_opts = [] + if table.dialect_options['postgresql']['tablespace']: + table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace']) + + return ' '.join(table_opts) + class PGTypeCompiler(compiler.GenericTypeCompiler): @@ -1707,7 +1714,8 @@ class PGDialect(default.DefaultDialect): "ops": {} }), (schema.Table, { - "ignore_search_path": False + "ignore_search_path": False, + "tablespace": None }) ] -- cgit v1.2.1 From d6873904c40134df787ffe5459d61d3663bf5d5f Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Sun, 17 Aug 2014 00:39:36 +0200 Subject: Adding oids and on_commit table options --- lib/sqlalchemy/dialects/postgresql/base.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 0f008642e..9b30bf894 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1450,6 +1450,14 @@ class PGDDLCompiler(compiler.DDLCompiler): def post_create_table(self, table): table_opts = [] + if table.dialect_options['postgresql']['withoids'] is not None: + if table.dialect_options['postgresql']['withoids']: + table_opts.append('WITH OIDS') + else: + table_opts.append('WITHOUT OIDS') + if table.dialect_options['postgresql']['on_commit']: + on_commit_options = table.dialect_options['postgresql']['on_commit'].replace("_", " ").upper() + table_opts.append('ON COMMIT %s' % on_commit_options) if table.dialect_options['postgresql']['tablespace']: table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace']) @@ -1715,7 +1723,9 @@ class PGDialect(default.DefaultDialect): }), (schema.Table, { "ignore_search_path": False, - "tablespace": None + "tablespace": None, + "withoids" : None, + "on_commit" : None, }) ] -- cgit v1.2.1 From 8e03430acdb98d7e5fef4a48a3120b928ed3266d Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Sun, 17 Aug 2014 01:39:14 +0200 Subject: quoting tablespace name in create table command in postgresql dialect --- lib/sqlalchemy/dialects/postgresql/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 9b30bf894..b09eaba72 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1459,7 +1459,8 @@ class PGDDLCompiler(compiler.DDLCompiler): on_commit_options = table.dialect_options['postgresql']['on_commit'].replace("_", " ").upper() table_opts.append('ON COMMIT %s' % on_commit_options) if table.dialect_options['postgresql']['tablespace']: - table_opts.append('TABLESPACE %s' % table.dialect_options['postgresql']['tablespace']) + tablespace_name = table.dialect_options['postgresql']['tablespace'] + table_opts.append('TABLESPACE %s' % self.preparer.quote(tablespace_name)) return ' '.join(table_opts) -- cgit v1.2.1 From 9eacc8d42ad49527c7fd0fe7e37100edba9eb1dc Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Sun, 17 Aug 2014 02:48:21 +0200 Subject: Correcting options name from withoids to with_oids --- lib/sqlalchemy/dialects/postgresql/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b09eaba72..057a5e072 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1450,8 +1450,8 @@ class PGDDLCompiler(compiler.DDLCompiler): def post_create_table(self, table): table_opts = [] - if table.dialect_options['postgresql']['withoids'] is not None: - if table.dialect_options['postgresql']['withoids']: + if table.dialect_options['postgresql']['with_oids'] is not None: + if table.dialect_options['postgresql']['with_oids']: table_opts.append('WITH OIDS') else: table_opts.append('WITHOUT OIDS') @@ -1725,7 +1725,7 @@ class PGDialect(default.DefaultDialect): (schema.Table, { "ignore_search_path": False, "tablespace": None, - "withoids" : None, + "with_oids" : None, "on_commit" : None, }) ] -- cgit v1.2.1 From faa5a9067661039dcc8663e00bdcea2d098c9989 Mon Sep 17 00:00:00 2001 From: Malik Diarra Date: Sun, 17 Aug 2014 16:56:53 +0200 Subject: Adding postgres create table options documentation --- lib/sqlalchemy/dialects/postgresql/base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 057a5e072..34932520f 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -417,6 +417,22 @@ of :class:`.PGInspector`, which offers additional methods:: .. autoclass:: PGInspector :members: +PostgreSQL specific table options +--------------------------------- + +PostgreSQL provides several CREATE TABLE specific options allowing to +specify how table data are stored. The following options are currently +supported: ``TABLESPACE``, ``ON COMMIT``, ``WITH OIDS``. + +``postgresql_tablespace`` is probably the more common and allows to specify +where in the filesystem the data files for the table will be created (see +http://www.postgresql.org/docs/9.3/static/manage-ag-tablespaces.html) + +.. seealso:: + + `Postgresql CREATE TABLE options + `_ - + on the PostgreSQL website """ from collections import defaultdict -- cgit v1.2.1 From b490534657229cbc44f1f5735a39539ceaf776a3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 23 Aug 2014 15:21:16 -0400 Subject: - pep8 formatting for pg table opts feature, tests - add support for PG INHERITS - fix mis-named tests - changelog fixes #2051 --- lib/sqlalchemy/dialects/postgresql/base.py | 83 +++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 24 deletions(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 34932520f..39de0cf92 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -417,22 +417,42 @@ of :class:`.PGInspector`, which offers additional methods:: .. autoclass:: PGInspector :members: -PostgreSQL specific table options ---------------------------------- +.. postgresql_table_options: + +PostgreSQL Table Options +------------------------- + +Several options for CREATE TABLE are supported directly by the PostgreSQL +dialect in conjunction with the :class:`.Table` construct: + +* ``TABLESPACE``:: + + Table("some_table", metadata, ..., postgresql_tablespace='some_tablespace') + +* ``ON COMMIT``:: + + Table("some_table", metadata, ..., postgresql_on_commit='PRESERVE ROWS') -PostgreSQL provides several CREATE TABLE specific options allowing to -specify how table data are stored. The following options are currently -supported: ``TABLESPACE``, ``ON COMMIT``, ``WITH OIDS``. +* ``WITH OIDS``:: -``postgresql_tablespace`` is probably the more common and allows to specify -where in the filesystem the data files for the table will be created (see -http://www.postgresql.org/docs/9.3/static/manage-ag-tablespaces.html) + Table("some_table", metadata, ..., postgresql_with_oids=True) + +* ``WITHOUT OIDS``:: + + Table("some_table", metadata, ..., postgresql_with_oids=False) + +* ``INHERITS``:: + + Table("some_table", metadata, ..., postgresql_inherits="some_supertable") + + Table("some_table", metadata, ..., postgresql_inherits=("t1", "t2", ...)) + +.. versionadded:: 1.0.0 .. seealso:: `Postgresql CREATE TABLE options - `_ - - on the PostgreSQL website + `_ """ from collections import defaultdict @@ -1466,19 +1486,33 @@ class PGDDLCompiler(compiler.DDLCompiler): def post_create_table(self, table): table_opts = [] - if table.dialect_options['postgresql']['with_oids'] is not None: - if table.dialect_options['postgresql']['with_oids']: - table_opts.append('WITH OIDS') - else: - table_opts.append('WITHOUT OIDS') - if table.dialect_options['postgresql']['on_commit']: - on_commit_options = table.dialect_options['postgresql']['on_commit'].replace("_", " ").upper() - table_opts.append('ON COMMIT %s' % on_commit_options) - if table.dialect_options['postgresql']['tablespace']: - tablespace_name = table.dialect_options['postgresql']['tablespace'] - table_opts.append('TABLESPACE %s' % self.preparer.quote(tablespace_name)) + pg_opts = table.dialect_options['postgresql'] + + inherits = pg_opts.get('inherits') + if inherits is not None: + if not isinstance(inherits, (list, tuple)): + inherits = (inherits, ) + table_opts.append( + '\n INHERITS ( ' + + ', '.join(self.preparer.quote(name) for name in inherits) + + ' )') + + if pg_opts['with_oids'] is True: + table_opts.append('\n WITH OIDS') + elif pg_opts['with_oids'] is False: + table_opts.append('\n WITHOUT OIDS') + + if pg_opts['on_commit']: + on_commit_options = pg_opts['on_commit'].replace("_", " ").upper() + table_opts.append('\n ON COMMIT %s' % on_commit_options) + + if pg_opts['tablespace']: + tablespace_name = pg_opts['tablespace'] + table_opts.append( + '\n TABLESPACE %s' % self.preparer.quote(tablespace_name) + ) - return ' '.join(table_opts) + return ''.join(table_opts) class PGTypeCompiler(compiler.GenericTypeCompiler): @@ -1741,8 +1775,9 @@ class PGDialect(default.DefaultDialect): (schema.Table, { "ignore_search_path": False, "tablespace": None, - "with_oids" : None, - "on_commit" : None, + "with_oids": None, + "on_commit": None, + "inherits": None }) ] -- cgit v1.2.1 From a16ee423e4528bd7a6ba6375cccd88b7450c58d3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 25 Aug 2014 17:06:28 -0400 Subject: - mention that FOUND_ROWS is hardcoded; fixes #3146 --- lib/sqlalchemy/dialects/mysql/base.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lib/sqlalchemy/dialects') diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 374960765..012d178e7 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -190,15 +190,13 @@ SQLAlchemy standardizes the DBAPI ``cursor.rowcount`` attribute to be the usual definition of "number of rows matched by an UPDATE or DELETE" statement. This is in contradiction to the default setting on most MySQL DBAPI drivers, which is "number of rows actually modified/deleted". For this reason, the -SQLAlchemy MySQL dialects always set the ``constants.CLIENT.FOUND_ROWS`` flag, -or whatever is equivalent for the DBAPI in use, on connect, unless the flag -value is overridden using DBAPI-specific options -(such as ``client_flag`` for the MySQL-Python driver, ``found_rows`` for the -OurSQL driver). +SQLAlchemy MySQL dialects always add the ``constants.CLIENT.FOUND_ROWS`` +flag, or whatever is equivalent for the target dialect, upon connection. +This setting is currently hardcoded. -See also: +.. seealso:: -:attr:`.ResultProxy.rowcount` + :attr:`.ResultProxy.rowcount` CAST Support -- cgit v1.2.1