misc fixes to ensure logilab.db compatibility stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Mar 2010 10:49:57 +0100
branchstable
changeset 4837 54969eec48eb
parent 4836 3e3c4917e94e
child 4838 d4187a08ccdf
misc fixes to ensure logilab.db compatibility
server/__init__.py
server/serverctl.py
server/test/unittest_rql2sql.py
--- a/server/__init__.py	Tue Mar 09 10:48:46 2010 +0100
+++ b/server/__init__.py	Tue Mar 09 10:49:57 2010 +0100
@@ -145,12 +145,9 @@
     # can't skip entities table even if system source doesn't support them,
     # they are used sometimes by generated sql. Keeping them empty is much
     # simpler than fixing this...
-    if sqlcnx.logged_user != source['db-user']:
-        schemasql = sqlschema(schema, driver, user=source['db-user'])
-    else:
-        schemasql = sqlschema(schema, driver)
-        #skip_entities=[str(e) for e in schema.entities()
-        #               if not repo.system_source.support_entity(str(e))])
+    schemasql = sqlschema(schema, driver)
+    #skip_entities=[str(e) for e in schema.entities()
+    #               if not repo.system_source.support_entity(str(e))])
     sqlexec(schemasql, execute, pbtitle=_title)
     sqlcursor.close()
     sqlcnx.commit()
--- a/server/serverctl.py	Tue Mar 09 10:48:46 2010 +0100
+++ b/server/serverctl.py	Tue Mar 09 10:49:57 2010 +0100
@@ -63,9 +63,18 @@
             password = getpass('password: ')
     extra_args = source.get('db-extra-arguments')
     extra = extra_args and {'extra_args': extra_args} or {}
-    return get_connection(driver, dbhost, dbname, user, password=password,
-                          port=source.get('db-port'),
-                          **extra)
+    cnx = get_connection(driver, dbhost, dbname, user, password=password,
+                         port=source.get('db-port'),
+                         **extra)
+    if not hasattr(cnx, 'logged_user'): # XXX logilab.db compat
+        try:
+            cnx.logged_user = user
+        except AttributeError:
+            # C object, __slots__
+            from logilab.db import _SimpleConnectionWrapper
+            cnx = _SimpleConnectionWrapper(cnx)
+            cnx.logged_user = user
+    return cnx
 
 def system_source_cnx(source, dbms_system_base=False,
                       special_privs='CREATE/DROP DATABASE', verbose=True):
--- a/server/test/unittest_rql2sql.py	Tue Mar 09 10:48:46 2010 +0100
+++ b/server/test/unittest_rql2sql.py	Tue Mar 09 10:49:57 2010 +0100
@@ -1068,7 +1068,7 @@
 WHERE rel_is0.eid_to=2'''),
 
     ]
-from logilab.common.adbh import ADV_FUNC_HELPER_DIRECTORY
+from logilab.common.adbh import get_adv_func_helper
 
 class CWRQLTC(RQLGeneratorTC):
     schema = schema
@@ -1103,7 +1103,7 @@
     def setUp(self):
         RQLGeneratorTC.setUp(self)
         indexer = get_indexer('postgres', 'utf8')
-        dbms_helper = ADV_FUNC_HELPER_DIRECTORY['postgres']
+        dbms_helper = get_adv_func_helper('postgres')
         dbms_helper.fti_uid_attr = indexer.uid_attr
         dbms_helper.fti_table = indexer.table
         dbms_helper.fti_restriction_sql = indexer.restriction_sql
@@ -1406,7 +1406,7 @@
     def setUp(self):
         RQLGeneratorTC.setUp(self)
         indexer = get_indexer('sqlite', 'utf8')
-        dbms_helper = ADV_FUNC_HELPER_DIRECTORY['sqlite']
+        dbms_helper = get_adv_func_helper('sqlite')
         dbms_helper.fti_uid_attr = indexer.uid_attr
         dbms_helper.fti_table = indexer.table
         dbms_helper.fti_restriction_sql = indexer.restriction_sql
@@ -1514,7 +1514,7 @@
     def setUp(self):
         RQLGeneratorTC.setUp(self)
         indexer = get_indexer('mysql', 'utf8')
-        dbms_helper = ADV_FUNC_HELPER_DIRECTORY['mysql']
+        dbms_helper = get_adv_func_helper('mysql')
         dbms_helper.fti_uid_attr = indexer.uid_attr
         dbms_helper.fti_table = indexer.table
         dbms_helper.fti_restriction_sql = indexer.restriction_sql