]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- engine_from_config() now accepts 'debug' for
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 15 Oct 2010 15:43:59 +0000 (11:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 15 Oct 2010 15:43:59 +0000 (11:43 -0400)
'echo', 'echo_pool', 'force' for 'convert_unicode',
boolean values for 'use_native_unicode'.
[ticket:1899]

CHANGES
lib/sqlalchemy/engine/__init__.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/util.py
test/engine/test_parseconnect.py

diff --git a/CHANGES b/CHANGES
index 788aa12c9f2e363b9b8ec26f4459c78e0856fbd6..1d78847145291d85d6299d7d9b370f05158cb3a9 100644 (file)
--- 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 
index 43d3dd0381e75c7866662267ff488e5cb2050f90..36b86cabf04c464a7b8105100a88128f0a289169 100644 (file)
@@ -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
index 390094c7dec0fec815a20be777d78d2c0a4a96bf..13755d49a3e5da5570a0ffeaf753edd374f6e9ba 100644 (file)
@@ -565,7 +565,6 @@ class DefaultExecutionContext(base.ExecutionContext):
         in all cases.
         
         """
-        
         return self.cursor.lastrowid
 
     def handle_dbapi_exception(self, e):
index 21026d53ca267dfc5c4f6aafa1886db70529f56f..922d5bee527f63251c4929bf590532b9604cb3d3 100644 (file)
@@ -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
index 7fb8d8a9074132bca6d6383f94a07017765c4c35..78b75ad2f47a438bfb93af0d26cd339ecad52f70 100644 (file)
@@ -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')