commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src/dbdrivers cxoracle/DBdriver.py ...


From: Jason Cater
Subject: gnue/common/src/dbdrivers cxoracle/DBdriver.py ...
Date: Thu, 17 Jan 2002 19:11:28 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/01/17 19:11:28

Modified files:
        common/src/dbdrivers/cxoracle: DBdriver.py 
        common/src/dbdrivers/oracle: DBdriver.py 
Added files:
        common/src/dbdrivers/_oracle: DBdriver.py __init__.py 

Log message:
        merged common features of oracle drivers plus fixed problems during 
schema testing

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/_oracle/DBdriver.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/_oracle/__init__.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/cxoracle/DBdriver.py.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/oracle/DBdriver.py.diff?tr1=1.13&tr2=1.14&r1=text&r2=text

Patches:
Index: gnue/common/src/dbdrivers/cxoracle/DBdriver.py
diff -c gnue/common/src/dbdrivers/cxoracle/DBdriver.py:1.7 
gnue/common/src/dbdrivers/cxoracle/DBdriver.py:1.8
*** gnue/common/src/dbdrivers/cxoracle/DBdriver.py:1.7  Thu Jan 17 18:11:33 2002
--- gnue/common/src/dbdrivers/cxoracle/DBdriver.py      Thu Jan 17 19:11:28 2002
***************
*** 32,44 ****
  #     service=    This is the Oracle TNS name for your connection  (required)
  #
  
! from string import lower
! import sys
  from gnue.common import GDebug, GDataObjects, GConnections
  from gnue.common.dbdrivers._dbsig.DBdriver \
     import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, \
            DBSIG_DataObject_SQL, DBSIG_DataObject_Object
  
  try:
    import cx_Oracle as SIG2api
  except ImportError, message:
--- 32,45 ----
  #     service=    This is the Oracle TNS name for your connection  (required)
  #
  
! import sys, string
  from gnue.common import GDebug, GDataObjects, GConnections
  from gnue.common.dbdrivers._dbsig.DBdriver \
     import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, \
            DBSIG_DataObject_SQL, DBSIG_DataObject_Object
  
+ from gnue.common.dbdrivers._oracle.DBdriver import Oracle_Schema
+ 
  try:
    import cx_Oracle as SIG2api
  except ImportError, message:
***************
*** 57,64 ****
      self._recordSetClass = Oracle_RecordSet
  
  
! class Oracle_DataObject(DBSIG_DataObject):
    def __init__(self):
      DBSIG_DataObject.__init__(self)
      self._DatabaseError = SIG2api.DatabaseError
      self._resultSetClass = Oracle_ResultSet
--- 58,66 ----
      self._recordSetClass = Oracle_RecordSet
  
  
! class Oracle_DataObject(Oracle_Schema, DBSIG_DataObject):
    def __init__(self):
+     Oracle_Schema.__init__(self)
      DBSIG_DataObject.__init__(self)
      self._DatabaseError = SIG2api.DatabaseError
      self._resultSetClass = Oracle_ResultSet
***************
*** 77,226 ****
      self._postConnect()
  
  
-   def _postConnect(self):
-     self.triggerExtensions = TriggerExtensions(self._dataConnection)
- 
-   #
-   # Schema (metadata) functions
-   #
- 
-   # Return a list of the types of Schema objects this driver provides
-   def getSchemaTypes(self):
-     return [ ('user_table',   'User Table',1),
-              ('user_view',    'User View',1),
-              ('user_synonym', 'User Synonym',1),
-              ('all_table',    'System Table',1),
-              ('all_view',     'System View',1),
-              ('all_synonym',  'System Synonym',1) ]
- 
-   # Return a list of Schema objects
-   def getSchemaList(self, type=None):
- 
-     where_user = ""
-     if type == None:
-       where_type = ['TABLE', 'VIEW', 'SYNONYM']
-     else:
-       scope, type = string.split(type,'_')
-       where_type = [string.upper(type)]
-       if scope == 'user':
-         where_user = " AND OWNER = USER"
- 
- 
-     statement = \
-       "select owner||'.'||table_name||'.'||table_type full_name, " + \
-         "decode(owner,user,null,owner||'.')||table_name table_name, " + \
-         "decode(owner,user,'user_','all_')||lower(table_type) table_type " + \
-         "from all_catalog where table_type in ('%s') %s " \
-               % (string.join(where_type,"','"), where_user) + \
-           "order by table_name "
- 
-     GDebug.printMesg(5,statement)
- 
-     cursor = self._dataConnection.cursor()
-     cursor.execute(statement)
- 
-     list = []
-     for rs in cursor.fetchall():
-       list.append(GDataObjects.Schema(attrs={'id':string.lower(rs[0]), 
'name':rs[1],
-                          'type':rs[2]},
-                          getChildSchema=self.__getFieldSchema))
- 
-     cursor.close()
-     return list
- 
- 
-   # Find a schema object with specified name
-   def getSchemaByName(self, name, type=None):
- 
-     spl = string.split(string.upper(name),'.')
-     where = "TABLE_NAME='%s" % spl[-1]
-     if len(spl) > 1:
-       where += " AND OWNER=%s" % spl[-2]
- 
-     statement = \
-       "select owner||'.'||table_name||'.'||table_type full_name, " + \
-         "decode(owner,user,null,owner||'.')||table_name table_name, " + \
-         "decode(owner,user,'user_','all_')||lower(table_type) table_type " + \
-         "from all_catalog where %s " \
-               % (where) + \
-           "order by table_name "
- 
-     GDebug.printMesg(5,statement)
- 
-     cursor = self._dataConnection.cursor()
-     cursor.execute(statement)
- 
-     list = []
-     rs = cursor.fetchone()
-     rv = GDataObjects.Schema(attrs={'id':string.lower(rs[0]), 'name':rs[1],
-                          'type':rs[2]},
-                          getChildSchema=self.__getFieldSchema)
- 
-     cursor.close()
-     return rv
- 
- 
-   # Get fields for a table
-   def __getFieldSchema(self, parent):
- 
-     owner, name, type = string.split(parent.id,'.')
- 
-     cursor = self._dataConnection.cursor()
- 
-     if type == 'SYNONYM': 
-       statement = "select table_owner, table_name, " + \
-                   "decode(db_link,null,null,'@'||db_link) name " + \
-                   "from all_synonyms " + \
-                   "where owner = '%s' and synonym_name='%s'" % (owner, name)
- 
-       GDebug.printMesg(5,statement)
- 
-       cursor.execute(statement)
-       rs = cursor.fetchone()
-       owner, name, link = rs
-     else: 
-       link = ""
- 
-     statement = \
-        "select owner||'.'||table_name||'.'||column_name||'.%s', " % (link) + \
-        "column_name, data_type, nullable, data_length, data_scale " + \
-        "from all_tab_columns%s " % (link) + \
-        "where owner = '%s' and table_name = '%s' " % (owner, name) + \
-        "order by column_id"
- 
-     GDebug.printMesg(5,statement)
- 
-     cursor.execute(statement)
-   
-     list = []
-     for rs in cursor.fetchall():
- 
-       attrs={'id': rs[0], 'name': rs[1],
-              'type':'field', 'nativetype': rs[2],
-              'required': rs[3] == 'Y'}
- 
-       if rs[2] in ('NUMBER','LONG','LONG RAW'):
-         attrs['precision'] = rs[5]
-         attrs['datatype'] = 'number'
-       elif rs[2] in ('DATE'):
-         attrs['datatype'] = 'date'
-       else:
-         attrs['datatype'] = 'text'
- 
-       if rs[5] != 0:
-         attrs['length'] = rs[4]
- 
-       list.append(GDataObjects.Schema(attrs=attrs))
- 
-     cursor.close()
-     return tuple(list)
- 
  
  
  class Oracle_DataObject_Object(Oracle_DataObject, \
        DBSIG_DataObject_Object):
  
!   def __init__(self): 
      Oracle_DataObject.__init__(self)
  
    def _buildQuery(self, conditions={}):
--- 79,90 ----
      self._postConnect()
  
  
  
  
  class Oracle_DataObject_Object(Oracle_DataObject, \
        DBSIG_DataObject_Object):
  
!   def __init__(self):
      Oracle_DataObject.__init__(self)
  
    def _buildQuery(self, conditions={}):
***************
*** 237,287 ****
  
    def _buildQuery(self, conditions={}):
      return DBSIG_DataObject_SQL._buildQuery(self, conditions)
- 
- 
- #
- #  Extensions to Trigger Namespaces
- #
- class TriggerExtensions:
- 
-   def __init__(self, connection):
-     self.__connection = connection
- 
-   # Return the current date, according to database
-   def getTimeStamp(self):
-     return self.__singleQuery("select sysdate from dual")
- 
-   # Return a sequence number from sequence 'name'
-   def getSequence(self, name):
-     return self.__singleQuery("select %s.nextval from dual" % name)
- 
-   # Run the SQL statement 'statement'
-   def sql(self, statement):
-     cursor = self.__connection.cursor()
-     try:
-       cursor.execute(statement)
-       cursor.close()
-     except:
-       cursor.close()
-       raise
- 
-   # Used internally
-   def __singleQuery(self, statement):
-     cursor = self.__connection.cursor()
-     try:
-       cursor.execute(statement)
-       rv = cursor.fetchone()
-       cursor.close()
-     except mesg:
-       GDebug.printMesg(1,"**** Unable to execute extension query")
-       GDebug.printMesg(1,"**** %s" % mesg)
-       cursor.close()
-       return None
- 
-     try:
-       return rv[0]
-     except:
-       return None
  
  
  
--- 101,106 ----
Index: gnue/common/src/dbdrivers/oracle/DBdriver.py
diff -c gnue/common/src/dbdrivers/oracle/DBdriver.py:1.13 
gnue/common/src/dbdrivers/oracle/DBdriver.py:1.14
*** gnue/common/src/dbdrivers/oracle/DBdriver.py:1.13   Thu Jan 10 15:59:18 2002
--- gnue/common/src/dbdrivers/oracle/DBdriver.py        Thu Jan 17 19:11:28 2002
***************
*** 39,44 ****
--- 39,46 ----
     import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, \
            DBSIG_DataObject_SQL, DBSIG_DataObject_Object
  
+ from gnue.common.dbdrivers._oracle.DBdriver import Oracle_Schema
+ 
  try:
    import DCOracle2 as SIG2api
  except ImportError, message:
***************
*** 61,68 ****
  
  
  
! class Oracle_DataObject(DBSIG_DataObject):
    def __init__(self):
      DBSIG_DataObject.__init__(self)
      self._DatabaseError = SIG2api.DatabaseError
      self._resultSetClass = Oracle_ResultSet
--- 63,71 ----
  
  
  
! class Oracle_DataObject(Oracle_Schema, DBSIG_DataObject):
    def __init__(self):
+     Oracle_Schema.__init__(self)
      DBSIG_DataObject.__init__(self)
      self._DatabaseError = SIG2api.DatabaseError
      self._resultSetClass = Oracle_ResultSet
***************
*** 81,199 ****
      self._postConnect()
  
  
-   def _postConnect(self):
-     self.triggerExtensions = TriggerExtensions(self._dataConnection)
- 
- 
-   #
-   # Schema (metadata) functions
-   #
- 
-   # Return a list of the types of Schema objects this driver provides
-   def getSchemaTypes(self):
-     return [ ('user_table',   'User Table',1),
-              ('user_view',    'User View',1), 
-              ('user_synonym', 'User Synonym',1),
-              ('all_table',    'System Table',1),
-              ('all_view',     'System View',1),
-              ('all_synonym',  'System Synonym',1) ]
- 
-   # Return a list of Schema objects
-   def getSchemaList(self, type=None):
- 
-     where_user = ""
-     if type == None: 
-       where_type = ['TABLE', 'VIEW', 'SYNONYM']
-     else: 
-       scope, type = string.split(type,'_')
-       where_type = [string.upper(type)]
-       if scope == 'user': 
-         where_user = " AND OWNER = USER"
-     
- 
-     statement = \
-       "select owner||'.'||table_name||'.'||table_type full_name, " + \
-         "decode(owner,user,null,owner||'.')||table_name table_name, " + \
-         "decode(owner,user,'user_','all_')||lower(table_type) table_type " + \
-         "from all_catalog where table_type in ('%s') %s " \
-               % (string.join(where_type,"','"), where_user) + \
-           "order by table_name "
- 
-     GDebug.printMesg(5,statement)
- 
-     cursor = self._dataConnection.cursor()
-     cursor.execute(statement)
- 
-     list = []
-     for rs in cursor.fetchall():
-       list.append(GDataObjects.Schema(attrs={'id':string.lower(rs[0]), 
'name':rs[1],
-                          'type':rs[2]},
-                          getChildSchema=self.__getFieldSchema))
- 
-     cursor.close()
-     return list
- 
- 
-   # Find a schema object with specified name
-   def getSchemaByName(self, name, type=None):
-      return None
- 
- 
-   # Get fields for a table
-   def __getFieldSchema(self, parent):
- 
-     owner, name, type = string.split(parent.id,'.')
- 
-     cursor = self._dataConnection.cursor()
- 
-     if type == 'SYNONYM': 
-       statement = "select table_owner, table_name, " + \
-                   "decode(db_link,null,null,'@'||db_link) name " + \
-                   "from all_synonyms " + \
-                   "where owner = '%s' and synonym_name='%s'" % (owner, name)
- 
-       GDebug.printMesg(5,statement)
- 
-       cursor.execute(statement)
-       rs = cursor.fetchone()
-       owner, name, link = rs
-     else: 
-       link = ""
- 
-     statement = \
-        "select owner||'.'||table_name||'.'||column_name||'.%s', " % (link) + \
-        "column_name, data_type, nullable, data_length, data_scale " + \
-        "from all_tab_columns%s " % (link) + \
-        "where owner = '%s' and table_name = '%s' " % (owner, name) + \
-        "order by column_id"
- 
-     GDebug.printMesg(5,statement)
- 
-     cursor.execute(statement)
-   
-     list = []
-     for rs in cursor.fetchall():
- 
-       attrs={'id': rs[0], 'name': rs[1],
-              'type':'field', 'nativetype': rs[2],
-              'required': rs[3] == 'Y'}
- 
-       if rs[2] in ('NUMBER','LONG','LONG RAW'):
-         attrs['precision'] = rs[5]
-         attrs['datatype'] = 'number'
-       elif rs[2] in ('DATE'):
-         attrs['datatype'] = 'date'
-       else:
-         attrs['datatype'] = 'text'
- 
-       if rs[5] != 0:
-         attrs['length'] = rs[4]
- 
-       list.append(GDataObjects.Schema(attrs=attrs))
- 
-     cursor.close()
-     return tuple(list)
- 
  
  class Oracle_DataObject_Object(Oracle_DataObject, \
        DBSIG_DataObject_Object):
--- 84,89 ----
***************
*** 206,266 ****
  
  
  class Oracle_DataObject_SQL(Oracle_DataObject, \
!       DBSIG_DataObject_SQL): 
!   def __init__(self): 
!     # Call DBSIG init first because Oracle_DataObject needs to overwrite 
      # some of its values
!     DBSIG_DataObject_SQL.__init__(self) 
      Oracle_DataObject.__init__(self)
  
    def _buildQuery(self, conditions={}):
      return DBSIG_DataObject_SQL._buildQuery(self, conditions)
- 
- 
- #
- #  Extensions to Trigger Namespaces
- #
- class TriggerExtensions:
- 
-   def __init__(self, connection):
-     self.__connection = connection
- 
-   # Return the current date, according to database
-   def getTimeStamp(self):
-     return self.__singleQuery("select sysdate from dual")
- 
-   # Return a sequence number from sequence 'name'
-   def getSequence(self, name):
-     return self.__singleQuery("select %s.nextval from dual" % name)
- 
-   # Run the SQL statement 'statement'
-   def sql(self, statement):
-     cursor = self.__connection.cursor()
-     try:
-       cursor.execute(statement)
-       cursor.close()
-     except:
-       cursor.close()
-       raise
- 
-   # Used internally
-   def __singleQuery(self, statement):
-     cursor = self.__connection.cursor()
-     try:
-       cursor.execute(statement)
-       rv = cursor.fetchone()
-       cursor.close()
-     except mesg:
-       GDebug.printMesg(1,"**** Unable to execute extension query")
-       GDebug.printMesg(1,"**** %s" % mesg)
-       cursor.close()
-       return None
- 
-     try:
-       return rv[0]
-     except:
-       return None
- 
  
  
  
--- 96,110 ----
  
  
  class Oracle_DataObject_SQL(Oracle_DataObject, \
!       DBSIG_DataObject_SQL):
!   def __init__(self):
!     # Call DBSIG init first because Oracle_DataObject needs to overwrite
      # some of its values
!     DBSIG_DataObject_SQL.__init__(self)
      Oracle_DataObject.__init__(self)
  
    def _buildQuery(self, conditions={}):
      return DBSIG_DataObject_SQL._buildQuery(self, conditions)
  
  
  



reply via email to

[Prev in Thread] Current Thread [Next in Thread]