[Checkins] SVN: Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/ Added 'add_extra_engine_options' method to set additional engine options for sqlalchemy.create_engine.

Abdul Kader Maliyakkal akm.mail at gmail.com
Tue May 4 00:07:10 EDT 2010


Log message for revision 111909:
  Added 'add_extra_engine_options' method to set  additional engine options for sqlalchemy.create_engine.
  
  

Changed:
  U   Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/da.py
  U   Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/tests/testSQLAlchemyDA.py

-=-
Modified: Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/da.py
===================================================================
--- Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/da.py	2010-05-04 03:35:14 UTC (rev 111908)
+++ Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/da.py	2010-05-04 04:07:07 UTC (rev 111909)
@@ -64,7 +64,8 @@
     transactional = True
     quoting_style = 'standard'
     _isAnSQLConnection = True
-
+    extra_engine_options = ()
+    
     security = ClassSecurityInfo()
 
     def __init__(self, id, title=''):
@@ -94,17 +95,33 @@
         if self.dsn:
             try:
                 return getSAWrapper(self.util_id)
-            except ValueError:               
+            except ValueError:
                 return createSAWrapper(self.dsn, 
                                        forZope=True, 
                                        transactional=self.transactional,
                                        extension_options={'initial_state': 'invalidated'},
-                                       engine_options={'convert_unicode' : self.convert_unicode,
-                                                       'encoding' : self.encoding},
+                                       engine_options=self.engine_options,
                                        name=self.util_id)
         return None
 
+    @property
+    def engine_options(self):
+        engine_options = dict(self.extra_engine_options)
+        engine_options.update(convert_unicode=self.convert_unicode,
+                              encoding=self.encoding)
+        return engine_options
 
+    def add_extra_engine_options(self, engine_options):
+        """ engine_options is a tuple containing additional
+            options for sqlalchemy.create_engine.
+            Say you need to pass some engine options
+            to SQLAlchemy.create_engine::
+            wrapper = SAWrapper(id)
+            wrapper.add_extra_engine_options((('echo', True),
+                                              ('pool_size', 20)))
+        """
+        self.extra_engine_options = engine_options
+
     security.declareProtected(view_management_screens, 'getInfo')
     def getInfo(self):
         """ return a dict with additional information """

Modified: Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/tests/testSQLAlchemyDA.py
===================================================================
--- Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/tests/testSQLAlchemyDA.py	2010-05-04 03:35:14 UTC (rev 111908)
+++ Products.SQLAlchemyDA/branches/zsql_commit_fix/Products/SQLAlchemyDA/tests/testSQLAlchemyDA.py	2010-05-04 04:07:07 UTC (rev 111909)
@@ -73,7 +73,13 @@
         da = self.makeOne()
         rows = da.query("update test set text='bar'")
 
+    def testExtraEngineOptions(self):
+        da = self.makeOne()
+        da.add_extra_engine_options((('echo', True),
+                                     ('pool_size', 20)))
+        self.assertEqual(da.engine_options['pool_size'], 20)
 
+
 class SQLAlchemyDAFunctionalTests(TestBase, ZopeTestCase.FunctionalTestCase):
 
     def afterSetUp(self):



More information about the checkins mailing list