diff options
author | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2008-07-25 15:17:45 +0200 |
---|---|---|
committer | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2008-07-25 15:17:45 +0200 |
commit | b6ffa93dadbe824a36c40816cc1dfcbae4991993 (patch) | |
tree | edd44e166aeb95791c141929cc2ab4d7113a930f | |
parent | 9c7fa04117c6b197850edce1262966318d35acc5 (diff) | |
parent | 7be444bc244bc2dab5117c051a8f4b56246a1c42 (diff) | |
download | logilab-common-b6ffa93dadbe824a36c40816cc1dfcbae4991993.tar.gz |
merge
-rw-r--r-- | adbh.py | 12 | ||||
-rw-r--r-- | test/unittest_db.py | 36 |
2 files changed, 27 insertions, 21 deletions
@@ -88,6 +88,14 @@ class LENGTH(FunctionDescr): class DATE(FunctionDescr): rtype = 'Date' +class RANDOM(FunctionDescr): + supported_backends = ('postgres', 'mysql',) + rtype = 'Float' + minargs = maxargs = 0 + name_mapping = {'postgres': 'RANDOM', + 'mysql': 'RAND', + } + class _GenericAdvFuncHelper: """Generic helper, trying to provide generic way to implement specific functionnalities from others DBMS @@ -113,6 +121,7 @@ class _GenericAdvFuncHelper: 'UPPER': UPPER, 'LOWER': LOWER, 'LENGTH': LENGTH, 'DATE': DATE, + 'RANDOM': RANDOM, # keyword function 'IN': IN } @@ -405,7 +414,8 @@ class _SqliteAdvFuncHelper(_GenericAdvFuncHelper): backend_name = 'sqlite' # modifiable but should not be shared FUNCTIONS = _GenericAdvFuncHelper.FUNCTIONS.copy() - + FUNCTIONS.pop('RANDOM') # not defined in sqlite + users_support = groups_support = False ilike_support = False union_parentheses_support = False diff --git a/test/unittest_db.py b/test/unittest_db.py index 9610ae8..9d10aba 100644 --- a/test/unittest_db.py +++ b/test/unittest_db.py @@ -194,39 +194,35 @@ class DBAPIAdaptersTC(TestCase): def test_auto_register_funcdef(self): - class RANDOM(FunctionDescr): + class MYFUNC(FunctionDescr): supported_backends = ('postgres', 'sqlite',) - rtype = 'Float' - minargs = maxargs = 0 - name_mapping = {'postgres': 'RANDOM', - 'mysql': 'RAND', - 'sqlite': 'SQLITE_RANDOM'} - auto_register_function(RANDOM) + name_mapping = {'postgres': 'MYFUNC', + 'mysql': 'MYF', + 'sqlite': 'SQLITE_MYFUNC'} + auto_register_function(MYFUNC) pghelper = get_adv_func_helper('postgres') mshelper = get_adv_func_helper('mysql') slhelper = get_adv_func_helper('sqlite') - self.failUnless('RANDOM' in pghelper.FUNCTIONS) - self.failUnless('RANDOM' in slhelper.FUNCTIONS) - self.failIf('RANDOM' in mshelper.FUNCTIONS) + self.failUnless('MYFUNC' in pghelper.FUNCTIONS) + self.failUnless('MYFUNC' in slhelper.FUNCTIONS) + self.failIf('MYFUNC' in mshelper.FUNCTIONS) def test_funcname_with_different_backend_names(self): - class RANDOM(FunctionDescr): + class MYFUNC(FunctionDescr): supported_backends = ('postgres', 'mysql', 'sqlite') - rtype = 'Float' - minargs = maxargs = 0 - name_mapping = {'postgres': 'RANDOM', - 'mysql': 'RAND', - 'sqlite': 'SQLITE_RANDOM'} - auto_register_function(RANDOM) + name_mapping = {'postgres': 'MYFUNC', + 'mysql': 'MYF', + 'sqlite': 'SQLITE_MYFUNC'} + auto_register_function(MYFUNC) pghelper = get_adv_func_helper('postgres') mshelper = get_adv_func_helper('mysql') slhelper = get_adv_func_helper('sqlite') - self.assertEquals(pghelper.func_sqlname('RANDOM'), 'RANDOM') - self.assertEquals(mshelper.func_sqlname('RANDOM'), 'RAND') - self.assertEquals(slhelper.func_sqlname('RANDOM'), 'SQLITE_RANDOM') + self.assertEquals(pghelper.func_sqlname('MYFUNC'), 'MYFUNC') + self.assertEquals(mshelper.func_sqlname('MYFUNC'), 'MYF') + self.assertEquals(slhelper.func_sqlname('MYFUNC'), 'SQLITE_MYFUNC') if __name__ == '__main__': |