commit-gnue
[Top][All Lists]
Advanced

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

gnue/common/src/dbdrivers/gadfly DBdriver.py __...


From: Jan Ischebeck
Subject: gnue/common/src/dbdrivers/gadfly DBdriver.py __...
Date: Thu, 19 Sep 2002 08:48:06 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  02/09/19 08:48:06

Modified files:
        common/src/dbdrivers/gadfly: DBdriver.py 
Added files:
        common/src/dbdrivers/gadfly: __init__.py 

Log message:
        some code cleanups for the gadfly driver,
        gadfly works now in forms and designer.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/gadfly/__init__.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/dbdrivers/gadfly/DBdriver.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/common/src/dbdrivers/gadfly/DBdriver.py
diff -c gnue/common/src/dbdrivers/gadfly/DBdriver.py:1.1 
gnue/common/src/dbdrivers/gadfly/DBdriver.py:1.2
*** gnue/common/src/dbdrivers/gadfly/DBdriver.py:1.1    Mon Jul  8 20:03:28 2002
--- gnue/common/src/dbdrivers/gadfly/DBdriver.py        Thu Sep 19 08:48:06 2002
***************
*** 55,64 ****
  
  
  class Gadfly_ResultSet(DBSIG_ResultSet): 
!   def __init__(self, dataObject, cursor=None, defaultValues={}, 
masterRecordSet=None): 
      DBSIG_ResultSet.__init__(self, dataObject, \
              cursor, defaultValues, masterRecordSet)
      self._recordSetClass = Gadfly_RecordSet
    def _loadNextRecord(self):
      if self._cursor:
        rs = None
--- 55,66 ----
  
  
  class Gadfly_ResultSet(DBSIG_ResultSet): 
!   def __init__(self, dataObject, cursor=None, defaultValues={}, 
masterRecordSet=None):
!     cursor.rowcount=0
      DBSIG_ResultSet.__init__(self, dataObject, \
              cursor, defaultValues, masterRecordSet)
      self._recordSetClass = Gadfly_RecordSet
+     
    def _loadNextRecord(self):
      if self._cursor:
        rs = None
***************
*** 108,118 ****
  ##### END EVIL HACK
  
  class Gadfly_DataObject(DBSIG_DataObject):
    def __init__(self): 
      DBSIG_DataObject.__init__(self)
!     self._DatabaseError = DatabaseError
      self._resultSetClass = Gadfly_ResultSet
  
  
    def connect(self, connectData={}): 
      GDebug.printMesg(1,"Gadfly database driver initializing")
--- 110,132 ----
  ##### END EVIL HACK
  
  class Gadfly_DataObject(DBSIG_DataObject):
+ 
+ 
    def __init__(self): 
      DBSIG_DataObject.__init__(self)
!     self._DatabaseError = Error
      self._resultSetClass = Gadfly_ResultSet
  
+     # LIKE is not supported on database level at the moment
+     # there should be used other ways to emulate it
+     # until that works, do a = instead of a like
+     # EVIL HACK
+     self.conditionElements.update({\
+        'like':            (2,   2, '%s = %s',             None     ),\
+        'notlike':         (2,   2, 'NOT (%s = %s)',       None     )})
+     # END EVIL HACK
+ 
+ 
  
    def connect(self, connectData={}): 
      GDebug.printMesg(1,"Gadfly database driver initializing")
***************
*** 140,146 ****
  
    # This should be over-ridden only if driver needs more than user/pass
    def getLoginFields(self):
!     return [['_username', 'User Name',0],['_password', 'Password',1]]
  
    #
    # Schema (metadata) functions
--- 154,160 ----
  
    # This should be over-ridden only if driver needs more than user/pass
    def getLoginFields(self):
!     return []
  
    #
    # Schema (metadata) functions
***************
*** 153,170 ****
    # Return a list of Schema objects
    def getSchemaList(self, type=None):
  
-     # TODO: This excludes any system tables and views. Should it?
      statement = "select * from __table_names__"
  
      cursor = self._dataConnection.cursor()
      GDebug.printMesg(1,"** Executing: %s **" % statement)
!     cursor.execute(statement)
  
      list = []
      for rs in cursor.fetchall():
!       list.append(GDataObjects.Schema(attrs={'id':rs[1], 'name':rs[1],
!                          'type':'table'},
!                          getChildSchema=self.__getFieldSchema))
  
      cursor.close()
      return list
--- 167,185 ----
    # Return a list of Schema objects
    def getSchemaList(self, type=None):
  
      statement = "select * from __table_names__"
  
      cursor = self._dataConnection.cursor()
      GDebug.printMesg(1,"** Executing: %s **" % statement)
!     cursor.execute(statement)    
  
      list = []
      for rs in cursor.fetchall():
!       # exclude any system tables and views. f.e. __table_names__
!       if rs[1][:2]!="__":       
!         list.append(GDataObjects.Schema(attrs={'id':rs[1], 'name':rs[1], \
!                                 'type':rs[0] == 1 and 'view' or 'table',},
!                                        getChildSchema=self.__getFieldSchema))
  
      cursor.close()
      return list
***************
*** 193,200 ****
    # Get fields for a table
    def __getFieldSchema(self, parent):
  
      statement = "SELECT * FROM __COLUMNS__ WHERE TABLE_NAME='%s'" % parent.id
-     #statement = "SELECT * FROM %s" % parent.id
  
      cursor = self._dataConnection.cursor()
      GDebug.printMesg(1,"** Executing: %s **" % statement)
--- 208,217 ----
    # Get fields for a table
    def __getFieldSchema(self, parent):
  
+     # TODO: Read whole definitions from __DATADEFS__ and parse them
+     #       to distinguish between varchar, float and integer
+     
      statement = "SELECT * FROM __COLUMNS__ WHERE TABLE_NAME='%s'" % parent.id
  
      cursor = self._dataConnection.cursor()
      GDebug.printMesg(1,"** Executing: %s **" % statement)
***************
*** 208,215 ****
  
  
        attrs={'id': "%s.%s" % (parent.id, rs[0]), 'name': rs[0],
!              'type':'field'}#, 'nativetype': nativetype[0],
!              #'required': rs[2] != 'YES'}
  
        #if nativetype[0] in ('int','integer','bigint','mediumint',
        #                     'smallint','tinyint','float','real',
--- 225,232 ----
  
  
        attrs={'id': "%s.%s" % (parent.id, rs[0]), 'name': rs[0],
!              'type':'field', 'nativetype': 'varchar',
!              'required': 0}
  
        #if nativetype[0] in ('int','integer','bigint','mediumint',
        #                     'smallint','tinyint','float','real',
***************
*** 247,252 ****
--- 264,287 ----
    def _buildQuery(self, conditions={}):
      return DBSIG_DataObject_Object._buildQuery(self, conditions)
  
+   def _getQueryCount(self,conditions={}):
+     cursor = self._dataConnection.cursor()
+ 
+     cursor.execute(self._buildQueryCount(conditions))
+     # GADFLY throws an error if executing COUNT(*) on an empty set
+     try:
+       rs = cursor.fetchone()
+       return int(rs[0])
+     except:
+       return 0
+ 
+   def _buildQueryCount(self, conditions={}):
+     # GADFLY seems to hate big letter "SELECT"
+     q = "select count(*) from %s%s" % (self.table, 
self._conditionToSQL(conditions))
+ 
+     GDebug.printMesg(5,q)
+ 
+     return q
  
  class Gadfly_DataObject_SQL(Gadfly_DataObject, \
        DBSIG_DataObject_SQL):
***************
*** 258,263 ****
--- 293,299 ----
  
    def _buildQuery(self, conditions={}):
      return DBSIG_DataObject_SQL._buildQuery(self, conditions)
+ 
  
  
  #




reply via email to

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