From: Mike Bayer Date: Fri, 15 Oct 2010 15:43:59 +0000 (-0400) Subject: - engine_from_config() now accepts 'debug' for X-Git-Tag: rel_0_6_5~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35508a30d7f0e92bd699da375316c75d9d6dd8dc;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - engine_from_config() now accepts 'debug' for 'echo', 'echo_pool', 'force' for 'convert_unicode', boolean values for 'use_native_unicode'. [ticket:1899] --- diff --git a/CHANGES b/CHANGES index 788aa12c9f..1d78847145 100644 --- a/CHANGES +++ b/CHANGES @@ -179,6 +179,11 @@ CHANGES - added "views=True" option to metadata.reflect(), will add the list of available views to those being reflected. [ticket:1936] + + - engine_from_config() now accepts 'debug' for + 'echo', 'echo_pool', 'force' for 'convert_unicode', + boolean values for 'use_native_unicode'. + [ticket:1899] - informix - *Major* cleanup / modernization of the Informix diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py index 43d3dd0381..36b86cabf0 100644 --- a/lib/sqlalchemy/engine/__init__.py +++ b/lib/sqlalchemy/engine/__init__.py @@ -278,14 +278,15 @@ def _coerce_config(configuration, prefix): for key in configuration if key.startswith(prefix)) for option, type_ in ( - ('convert_unicode', bool), + ('convert_unicode', util.bool_or_str('force')), ('pool_timeout', int), - ('echo', bool), - ('echo_pool', bool), + ('echo', util.bool_or_str('debug')), + ('echo_pool', util.bool_or_str('debug')), ('pool_recycle', int), ('pool_size', int), ('max_overflow', int), ('pool_threadlocal', bool), + ('use_native_unicode', bool), ): util.coerce_kw_type(options, option, type_) return options diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 390094c7de..13755d49a3 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -565,7 +565,6 @@ class DefaultExecutionContext(base.ExecutionContext): in all cases. """ - return self.cursor.lastrowid def handle_dbapi_exception(self, e): diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 21026d53ca..922d5bee52 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -584,6 +584,18 @@ def asbool(obj): raise ValueError("String is not true/false: %r" % obj) return bool(obj) +def bool_or_str(*text): + """Return a callable that will evaulate a string as + boolean, or one of a set of "alternate" string values. + + """ + def bool_or_value(obj): + if obj in text: + return obj + else: + return asbool(obj) + return bool_or_value + def coerce_kw_type(kw, key, type_, flexi_bool=True): """If 'key' is present in dict 'kw', coerce its value to type 'type\_' if necessary. If 'flexi_bool' is True, the string '0' is considered false diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index 7fb8d8a907..78b75ad2f4 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -3,6 +3,7 @@ import ConfigParser import StringIO import sqlalchemy.engine.url as url from sqlalchemy import create_engine, engine_from_config +from sqlalchemy.engine import _coerce_config import sqlalchemy as tsa from sqlalchemy.test import TestBase @@ -138,6 +139,21 @@ pool_timeout=10 'z=somevalue') assert e.echo is True + for param, values in [ + ('convert_unicode', ('true', 'false', 'force')), + ('echo', ('true', 'false', 'debug')), + ('echo_pool', ('true', 'false', 'debug')), + ('use_native_unicode', ('true', 'false')), + ]: + for value in values: + config = { + 'sqlalchemy.url': 'postgresql://scott:tiger@somehost/test', + 'sqlalchemy.%s' % param : value + } + cfg = _coerce_config(config, 'sqlalchemy.') + assert cfg[param] == {'true':True, 'false':False}.get(value, value) + + def test_custom(self): dbapi = MockDBAPI(foober=12, lala=18, hoho={'this': 'dict'}, fooz='somevalue')