changeset 514:ea547649a1b8

fix case in oracle queries
author catherine.devlin@gmail.com
date Tue, 02 Nov 2010 04:14:00 -0400
parents c2d0b2aea925
children 86d5408e596b
files sqlpython/connections.py
diffstat 1 files changed, 12 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/connections.py	Tue Nov 02 03:16:58 2010 -0400
+++ b/sqlpython/connections.py	Tue Nov 02 04:14:00 2010 -0400
@@ -87,8 +87,6 @@
     mode = 0
     connection_uri_parser = re.compile('(?P<rdbms>postgres|oracle|mysql|sqlite|mssql)://?(?P<connect_string>.*$)', re.IGNORECASE)    
     connection_parser = re.compile('((?P<database>\S+)(\s+(?P<username>\S+))?)?')    
-    def object_name_case(self, name):
-        return name.lower()
     def __init__(self, arg, opts, default_rdbms = 'oracle'):
         'no docstring'
         '''
@@ -233,7 +231,7 @@
         else:
             identifier['sort_direction'] = 'ASC'
         curs = self.connection.cursor()
-        dbapiext.execute_f(curs, self.all_object_qry, **identifier)
+        dbapiext.execute_f(curs, self.all_object_qry, paramstyle = self.paramstyle, **identifier)
         return curs
     def columns(self, target, opts):
         target = self.sql_format_wildcards(target)
@@ -244,7 +242,7 @@
             identifier['owner'] = self.username
         self.set_operators(identifier)
         curs = self.connection.cursor()
-        dbapiext.execute_f(curs, self.column_qry, **identifier)
+        dbapiext.execute_f(curs, self.column_qry, paramstyle = self.paramstyle, **identifier)
         return curs
     def _source(self, target, opts):
         identifier = {'text': '%%%s%%' % target.upper()}
@@ -254,7 +252,7 @@
             identifier['owner'] = self.username
         self.set_operators(identifier)
         curs = self.connection.cursor()
-        dbapiext.execute_f(curs, self.source_qry, **identifier)
+        dbapiext.execute_f(curs, self.source_qry, paramstyle = self.paramstyle, **identifier)
         return curs
     def source(self, target, opts):
         curs = self._source(target, opts)
@@ -292,6 +290,7 @@
 
 class MySQLInstance(DatabaseInstance):
     rdbms = 'mysql'
+    paramstyle = 'format'
     default_port = 3306
     def set_defaults(self):
         self.port = self.default_port       
@@ -330,8 +329,8 @@
    
 class PostgresInstance(DatabaseInstance):
     rdbms = 'postgres'
+    paramstyle = 'pyformat'
     default_port = 5432
-    case = str.lower
     def set_defaults(self):
         self.port = os.getenv('PGPORT') or self.default_port
         self.database = os.getenv('ORACLE_SID')
@@ -367,12 +366,10 @@
 
 class OracleInstance(DatabaseInstance):
     rdbms = 'oracle'
+    paramstyle = 'named'
     default_port = 1521
     connection_parser = re.compile('(?P<username>[^/\s@]*)(/(?P<password>[^/\s@]*))?(@((?P<hostname>[^/\s:]*)(:(?P<port>\d{1,4}))?/)?(?P<database>[^/\s:]*))?(\s+as\s+(?P<mode>sys(dba|oper)))?',
                                      re.IGNORECASE)
-    case = str.upper
-    def object_name_case(self, name):
-        return name.upper()
     def uri(self):
         if self.hostname:
             uri = '%s://%s:%s@%s:%s/%s' % (self.rdbms, self.username, self.password,
@@ -405,18 +402,18 @@
                                   dsn = self.dsn, mode = self.mode)    
     all_object_qry = """SELECT owner, object_type, object_name 
                         FROM   all_objects 
-                        WHERE  owner %(owner_op)s %(owner)S
-                        AND    object_type %(type_op)s %(type)S
-                        AND    object_name %(name_op)s %(name)S
+                        WHERE  owner %(owner_op)s UPPER(%(owner)S)
+                        AND    object_type %(type_op)s UPPER(%(type)S)
+                        AND    object_name %(name_op)s UPPER(%(name)S)
                         ORDER BY owner, object_type, object_name %(sort_direction)s"""
     column_qry = """SELECT atc.owner, ao.object_type, atc.table_name, atc.column_name      
                     FROM   all_tab_columns atc
                     JOIN   all_objects ao ON (atc.table_name = ao.object_name AND atc.owner = ao.owner)
-                    WHERE  atc.owner %(owner_op)s %(owner)S
-                    AND    atc.column_name %(column_name_op)s %(column_name)S """
+                    WHERE  atc.owner %(owner_op)s UPPER(%(owner)S)
+                    AND    atc.column_name %(column_name_op)s UPPER(%(column_name)S) """
     source_qry = """SELECT owner, type, name, line, text
                     FROM   all_source
-                    WHERE  owner %(owner_op)s %(owner)S
+                    WHERE  owner %(owner_op)s UPPER(%(owner)S)
                     AND    UPPER(text) LIKE %(text)S"""
     def source(self, target, opts):
         return self._source(target, opts)