From dd9b7357fd64eb0b0dd7337ef7d36574e12b7f02 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Fri, 9 May 2014 21:34:30 +0100 Subject: pg8000.dbapi is now just pg8000 --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index bc73f9757..01a250f9a 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -111,7 +111,7 @@ class PGDialect_pg8000(PGDialect): @classmethod def dbapi(cls): - return __import__('pg8000').dbapi + return __import__('pg8000') def create_connect_args(self, url): opts = url.translate_connect_args(username='user') -- cgit v1.2.1 From 32bae567fe487ca78d23d775792e6dbd7657ba53 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Mon, 12 May 2014 21:47:18 +0100 Subject: Updated doc string for postgresql+pg8000 dialect --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 01a250f9a..788bfc5c8 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -9,21 +9,19 @@ :name: pg8000 :dbapi: pg8000 :connectstring: postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...] - :url: http://pybrary.net/pg8000/ + :url: https://pythonhosted.org/pg8000/ Unicode ------- -pg8000 requires that the postgresql client encoding be -configured in the postgresql.conf file in order to use encodings -other than ascii. Set this value to the same value as the -"encoding" parameter on create_engine(), usually "utf-8". +When communicating with the server, pg8000 uses the character set that the +server asks it to use (the client encoding). By default the client encoding is +the database's character set (chosen when the database is created), but the +client encoding can be changed in a number of ways (eg. setting CLIENT_ENCODING +in postgresql.conf). -Interval --------- - -Passing data from/to the Interval type is not supported as of -yet. +Set the "encoding" parameter on create_engine(), to the same as the client +encoding, usually "utf-8". """ from ... import util, exc -- cgit v1.2.1 From 66e0a7771f66b352e6712cf2d71936c6f8238617 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Wed, 14 May 2014 14:36:08 +0100 Subject: Autocommit isolation level for postgresql+pg8000 As with postgresql+psycopg2, execution_options(isolation_level='AUTOCOMMIT') now works for the postgresql+pg8000 dialect. Also enabled the autocommit test in test_dialect.py for pg8000. --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 788bfc5c8..27b867b09 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -121,4 +121,28 @@ class PGDialect_pg8000(PGDialect): def is_disconnect(self, e, connection, cursor): return "connection is closed" in str(e) + def set_isolation_level(self, connection, level): + level = level.replace('_', ' ') + print("level is", level) + print("autocommit is", connection.autocommit) + print("class is", connection) + + if level == 'AUTOCOMMIT': + connection.connection.autocommit = True + elif level in self._isolation_lookup: + connection.connection.autocommit = False + cursor = connection.cursor() + cursor.execute( + "SET SESSION CHARACTERISTICS AS TRANSACTION " + "ISOLATION LEVEL %s" % level) + cursor.execute("COMMIT") + cursor.close() + else: + raise exc.ArgumentError( + "Invalid value '%s' for isolation_level. " + "Valid isolation levels for %s are %s or AUTOCOMMIT" % + (level, self.name, ", ".join(self._isolation_lookup)) + ) + print("autocommit is now", connection.autocommit) + dialect = PGDialect_pg8000 -- cgit v1.2.1 From f8f29d0a105a4a84f09a05b519142002cee1f5f6 Mon Sep 17 00:00:00 2001 From: Tony Locke Date: Wed, 14 May 2014 14:47:26 +0100 Subject: PEP 8 tidy of pg8000 dialect and postgresql/test_dialect.py --- lib/sqlalchemy/dialects/postgresql/pg8000.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/pg8000.py') diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 27b867b09..edb1afc39 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -1,5 +1,6 @@ # postgresql/pg8000.py -# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors +# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors # # This module is part of SQLAlchemy and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php @@ -8,7 +9,8 @@ .. dialect:: postgresql+pg8000 :name: pg8000 :dbapi: pg8000 - :connectstring: postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...] + :connectstring: \ +postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...] :url: https://pythonhosted.org/pg8000/ Unicode @@ -28,9 +30,9 @@ from ... import util, exc import decimal from ... import processors from ... import types as sqltypes -from .base import PGDialect, \ - PGCompiler, PGIdentifierPreparer, PGExecutionContext,\ - _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES +from .base import ( + PGDialect, PGCompiler, PGIdentifierPreparer, PGExecutionContext, + _DECIMAL_TYPES, _FLOAT_TYPES, _INT_TYPES) class _PGNumeric(sqltypes.Numeric): @@ -38,14 +40,13 @@ class _PGNumeric(sqltypes.Numeric): if self.asdecimal: if coltype in _FLOAT_TYPES: return processors.to_decimal_processor_factory( - decimal.Decimal, - self._effective_decimal_return_scale) + decimal.Decimal, self._effective_decimal_return_scale) elif coltype in _DECIMAL_TYPES or coltype in _INT_TYPES: # pg8000 returns Decimal natively for 1700 return None else: raise exc.InvalidRequestError( - "Unknown PG numeric type: %d" % coltype) + "Unknown PG numeric type: %d" % coltype) else: if coltype in _FLOAT_TYPES: # pg8000 returns float natively for 701 @@ -54,7 +55,7 @@ class _PGNumeric(sqltypes.Numeric): return processors.to_float else: raise exc.InvalidRequestError( - "Unknown PG numeric type: %d" % coltype) + "Unknown PG numeric type: %d" % coltype) class _PGNumericNoBind(_PGNumeric): @@ -69,7 +70,7 @@ class PGExecutionContext_pg8000(PGExecutionContext): class PGCompiler_pg8000(PGCompiler): def visit_mod_binary(self, binary, operator, **kw): return self.process(binary.left, **kw) + " %% " + \ - self.process(binary.right, **kw) + self.process(binary.right, **kw) def post_process_text(self, text): if '%%' in text: @@ -123,9 +124,6 @@ class PGDialect_pg8000(PGDialect): def set_isolation_level(self, connection, level): level = level.replace('_', ' ') - print("level is", level) - print("autocommit is", connection.autocommit) - print("class is", connection) if level == 'AUTOCOMMIT': connection.connection.autocommit = True @@ -143,6 +141,5 @@ class PGDialect_pg8000(PGDialect): "Valid isolation levels for %s are %s or AUTOCOMMIT" % (level, self.name, ", ".join(self._isolation_lookup)) ) - print("autocommit is now", connection.autocommit) dialect = PGDialect_pg8000 -- cgit v1.2.1