commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7079 - trunk/gnue-common/src/datasources/drivers/DBSIG2


From: reinhard
Subject: [gnue] r7079 - trunk/gnue-common/src/datasources/drivers/DBSIG2
Date: Wed, 2 Mar 2005 15:47:05 -0600 (CST)

Author: reinhard
Date: 2005-03-02 15:47:05 -0600 (Wed, 02 Mar 2005)
New Revision: 7079

Removed:
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py
Log:
Removed obsolete file.


Deleted: trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py  2005-03-02 
21:45:06 UTC (rev 7078)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py  2005-03-02 
21:47:05 UTC (rev 7079)
@@ -1,630 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2000-2005 Free Software Foundation
-#
-# FILE:
-# _dbsig/DBdriver.py
-#
-# DESCRIPTION:
-# Generic implementation of dbdriver using Python DB-SIG v2
-# specification.
-#
-# NOTES:
-# The classes below are meant to be extended
-#
-# HISTORY:
-#
-# I think this file is obsolete but it contained at least a
-# few bug fixes the new files didn't so I'm leaving it here
-# for a bit just in case - jamest
-#
-
-## from gnue.common.datasources import GDataObjects, GConditions
-## from gnue.common.apps import GDebug
-## import string
-## import types
-
-## class DBSIG_RecordSet(GDataObjects.RecordSet):
-
-##   def _postChanges(self):
-##     if not self.isPending(): return
-##     if self._deleteFlag:
-##       statement = self._buildDeleteStatement()
-##     elif self._insertFlag:
-##       statement = self._buildInsertStatement()
-##     elif self._updateFlag:
-##       statement = self._buildUpdateStatement()
-
-##     GDebug.printMesg(5, "_postChanges: statement=%s" % statement)
-
-##     try:
-##       self._parent._update_cursor.execute(statement)
-
-##       # Set _initialData to be the just-now posted values
-##       if not self._deleteFlag:
-##         self._initialData = {}
-##         self._initialData.update(self._fields)
-
-##     except self._parent._dataObject._connection._DatabaseError, err:
-##       raise GDataObjects.ConnectionError, err
-
-##     self._updateFlag = 0
-##     self._insertFlag = 0
-##     self._deleteFlag = 0
-
-##     return 1
-
-
-##   # If a vendor can do any of these more efficiently (i.e., use a known
-##   # PRIMARY KEY or ROWID, then override these methods. Otherwise, leave
-##   # as default.  Note that these functions are specific to DB-SIG based
-##   # drivers (i.e., these functions are not in the base RecordSet class)
-
-##   def _buildDeleteStatement(self):
-##     if self._initialData.has_key(self._parent._dataObject._primaryIdField):
-##       where = [self._parent._dataObject._primaryIdFormat % \
-##           self._initialData[self._parent._dataObject._primaryIdField]  ]
-##     else:
-##       where = []
-##       for field in self._initialData.keys():
-##         if self._parent.isFieldBound(field):
-##           if self._initialData[field] == None:
-##             where.append ("%s IS NULL" % field)
-##           else:
-##             where.append ("%s=%s" % (field,
-##               
self._parent._dataObject._toSqlString(self._initialData[field])))
-
-##     statement = "DELETE FROM %s WHERE %s" % \
-##        (self._parent._dataObject.table, string.join(where,' AND ') )
-##     return statement
-
-##   def _buildInsertStatement(self):
-##     vals = []
-##     fields = []
-
-##     for field in self._modifiedFlags.keys():
-##       if self._parent.isFieldBound(field):
-##         fields.append (field)
-##         if self._fields[field] == None or self._fields[field] == '':
-##           vals.append ("NULL") #  % (self._fields[field]))
-##         else:
-##           vals.append 
(self._parent._dataObject._toSqlString(self._fields[field]))
-
-##     return "INSERT INTO %s (%s) VALUES (%s)" % \
-##        (self._parent._dataObject.table, string.join(fields,','), \
-##         string.join(vals,',') )
-
-##   def _buildUpdateStatement(self):
-##     updates = []
-##     for field in self._modifiedFlags.keys():
-##       updates.append ("%s=%s" % (field,
-##          self._parent._dataObject._toSqlString(self._fields[field])))
-
-##     if self._parent._dataObject._primaryIdField:
-##       where = [self._parent._dataObject._primaryIdFormat % \
-##           self._initialData[self._parent._dataObject._primaryIdField]  ]
-##     else:
-##       where = []
-##       for field in self._initialData.keys():
-##         if self._initialData[field] == None:
-##           where.append ("%s IS NULL" % field)
-##         else:
-##           where.append ("%s=%s" % (field, 
self._parent._dataObject._toSqlString(self._initialData[field])))
-
-##     return "UPDATE %s SET %s WHERE %s" % \
-##        (self._parent._dataObject.table, string.join(updates,','), \
-##         string.join(where,' AND ') )
-
-
-## class DBSIG_ResultSet(GDataObjects.ResultSet):
-##   def __init__(self, dataObject, cursor=None, \
-##         defaultValues={}, masterRecordSet=None):
-##     GDataObjects.ResultSet.__init__(
-##            self,dataObject,cursor,defaultValues,masterRecordSet)
-##     self._recordSetClass = DBSIG_RecordSet
-##     self._fieldNames = []
-
-##     if self._cursor:
-##       for t in(self._cursor.description):
-##         self._fieldNames.append(t[0])
-##       GDebug.printMesg(5, "Field names set to %s" % self._fieldNames)
-
-##     self._recordCount = cursor.rowcount or 0
-
-##     GDebug.printMesg(5, 'ResultSet created')
-
-##   def _loadNextRecord(self):
-##     if self._cursor:
-##       rs = None
-
-##       try:
-##         rsets = self._cursor.fetchmany()
-##       except self._dataObject._connection._DatabaseError, err:
-##         raise GDataObjects.ConnectionError, err
-##       if rsets and len(rsets):
-##         for rs in(rsets):
-##           if rs:
-##             i = 0
-##             dict = {}
-##             for f in (rs):
-##               if self._dataObject._unicodeMode and 
type(f)==types.StringType:
-##                 f = unicode(f,self._dataObject._databaseEncoding)
-                
-##               dict[string.lower(self._fieldNames[i])] = f
-##               i += 1
-##             self._cachedRecords.append (self._recordSetClass(parent=self, \
-##                                                              
initialData=dict))
-##           else:
-##             return 0
-##         return 1
-##       else:
-##         # We no longer need the cursor if we are read only
-##         if self._readonly:
-##           self._cursor.close()
-##         return 0
-##     else:
-##       return 0
-
-
-## class DBSIG_DataObject(GDataObjects.DataObject):
-
-##   conditionElements = {
-##        'add':             (2, 999, '(%s)',                   '+'       ),
-##        'sub':             (2, 999, '(%s)',                   '-'       ),
-##        'mul':             (2, 999, '(%s)',                   '*'       ),
-##        'div':             (2, 999, '(%s)',                   '/'       ),
-##        'and':             (1, 999, '(%s)',                   ' AND '   ),
-##        'or':              (2, 999, '(%s)',                   ' OR '    ),
-##        'not':             (1,   1, '(NOT %s)',               None      ),
-##        'negate':          (1,   1, '-%s',                    None      ),
-##        'null':            (1,   1, '(%s IS NULL)',           None      ),
-##        'notnull':         (1,   1, '(%s IS NOT NULL)',       None      ),
-##        'eq':              (2,   2, '(%s = %s)',              None      ),
-##        'ne':              (2,   2, '(%s != %s)',             None      ),
-##        'gt':              (2,   2, '(%s > %s)',              None      ),
-##        'ge':              (2,   2, '(%s >= %s)',             None      ),
-##        'lt':              (2,   2, '(%s < %s)',              None      ),
-##        'le':              (2,   2, '(%s <= %s)',             None      ),
-##        'like':            (2,   2, '%s LIKE %s',             None      ),
-##        'notlike':         (2,   2, '%s NOT LIKE %s',         None      ),
-##        'between':         (3,   3, '%s BETWEEN %s AND %s',   None      ),
-##        'notbetween':      (3,   3, '(%s NOT BETWEEN %s AND %s)', None  ),
-##        # These two are hacks... these are not really valid tags
-##        # Used when the 2nd value of EQ or NE is NULL.
-##        '__iseq':          (2,   2, '(%s IS %s)',             None      ),
-##        '__isne':          (2,   2, '(%s IS NOT %s)',         None      )}
-
-##   def __init__(self, strictQueryCount=1):
-##     GDataObjects.DataObject.__init__(self)
-
-##     GDebug.printMesg (1,"DB-SIG database driver backend initializing")
-
-##     # This should be set to the Single Quote escape character
-##     # (typically either "'" or "\"
-##     self._escapeSingleQuote = "'"
-##     self._resultSetClass = DBSIG_ResultSet
-##     self._DatabaseError = None
-##     self._strictQueryCount = strictQueryCount
-
-##     self.distinct = 0
-
-##     # If a DB driver supports a unique identifier for rows,
-##     # list it here.  _primaryIdField is the field name (lower case)
-##     # that would appear in the recordset (note that this can be
-##     # a system generated format). If a primary id is supported,
-##     # _primaryIdFormat is the WHERE clause to be used. It will have
-##     # the string  % (fieldvalue) format applied to it.
-##     #
-##     # See Oracle drivers for example
-##     self._primaryIdField = None         # Internal recordset field name 
(lowercase!!!)
-##     self._primaryIdSelect = ""  # Select clause
-##     self._primaryIdFormat = "__gnue__ = '%s'"         # Where clause format
-
-##     # Internal flag to avoid consistently doing the same check
-##     # If this is set to 1 initially, then the
-##     self._primaryIdChecked = 1  # Internal flag
-
-
-##     # The date/time format used in insert/select statements
-##     # (based on format used for time.strftime())
-##     self._dateTimeFormat = "'%c'"
-
-
-##   def _toSqlString(self, value):
-##     try:
-##       return value.strftime(self._dateTimeFormat)
-##     except AttributeError:
-      
-##       if value == None:
-##         return "NULL"
-
-##       elif type(value) == types.IntType:
-##         return "'%d'" % value
-
-##       elif type(value) == types.LongType:
-##         return "'%d'" % value
-
-##       elif type(value) == types.FloatType:
-##         if value==int(value):
-##           return "'%d'" % value
-##         else:
-##           return "'" + str (value) + "'"
-
-##       elif type(value) == types.StringType:
-
-##         if self._unicodeMode:
-##           GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver 
(%s)' % value)
-          
-##         return "'%s'" % string.replace(value,
-##                                        "'",
-##                                        "%s'" % self._escapeSingleQuote)     
 
-
-##       elif type(value) == types.UnicodeType:
-##         return "'%s'" % string.replace(value.encode(self._databaseEncoding),
-##                                        "'",
-##                                        "%s'" % self._escapeSingleQuote)
-
-##       # TODO: make this test faster, possibly move type check to GTypecast
-##       elif hasattr(types,'BooleanType') and typestype(value) == 
types.BooleanType:
-##         if value:
-##           return 'TRUE'
-##         else:
-##           return 'FALSE'
-        
-##       else:
-##         err = _("Object of unknown type (%s) passed to DBSIG2 based 
dbdriver.") % type(value)
-##         # FIXME: raise an error instead of just printing a warning, after 
some transition time
-##         #raise GDataObjects.UnknownDataType, err
-##         GDebug.printMesg (0,err)
-##         return "'%s'" % string.replace(str(value),
-##                                        "'",
-##                                        "%s'" % self._escapeSingleQuote)
-        
-
-##   # This should be over-ridden only if driver needs more than user/pass
-##   def getLoginFields(self):
-##     return [['_username', _('User Name'),0],['_password', _('Password'),1]]
-
-
-##   # Used by drivers with a unique id (like rowid) (see Oracle for example)
-##   def _checkForPrimaryId(self):
-##     self._primaryIdChecked = 1
-
-
-##   def _createResultSet(self, conditions={}, readOnly=0, 
masterRecordSet=None,sql=""):
-
-##     # Used by drivers with a unique id (like rowid)
-##     if not self._primaryIdChecked: self._checkForPrimaryId()
-
-##     try:
-##       cursor = self._dataConnection.cursor()
-
-##       cursor.arraysize = self.cache
-##       cursor.execute(self._buildQuery(conditions, additionalSQL=sql))
-
-##       # pull a record count 
-##       if self._strictQueryCount:
-##         recordCount = cursor.rowcount
-##         #disable the count query and see if anyone screams
-##         #recordCount = self._getQueryCount(conditions,sql)
-        
-##     except self._DatabaseError, err:
-##       raise GDataObjects.ConnectionError, err
-
-##     rs = self._resultSetClass(self, cursor=cursor, 
masterRecordSet=masterRecordSet)
-##     if self._strictQueryCount:
-##       rs._recordCount = recordCount
-##     if readOnly:
-##       rs._readonly = readOnly
-
-##     return rs
-
-##   def _getQueryCount(self,conditions={},sql=""):
-##     cursor = self._dataConnection.cursor()
-
-##     cursor.execute(self._buildQueryCount(conditions,additionalSQL=sql))
-##     rs = cursor.fetchone()
-##     return int(rs[0])
-
-##   def commit(self):
-##     GDebug.printMesg (5,"DB-SIG database driver: commit()")
-
-##     try:
-##       self._dataConnection.commit()
-##     except self._DatabaseError, value:
-##       raise GDataObjects.ConnectionError, value
-
-##     self._beginTransaction()
-
-##   def rollback(self):
-##     GDebug.printMesg (5,"DB-SIG database driver: rollback()")
-
-##     try:
-##       self._dataConnection.rollback()
-##     except:
-##       pass  # I'm SURE this isn't right (jcater)
-##                 # But not all db's support transactions
-
-##     self._beginTransaction()
-
-
-##   # Used to convert a condition tree to an sql where clause
-##   def _conditionToSQL (self, condition):
-##     if condition == {} or condition == None:
-##       return ""
-##     elif type(condition) == types.DictType:
-##       cond = GConditions.buildConditionFromDict(condition)
-##     else:
-##       cond = condition
-
-##     if not len(cond._children): 
-##       return ""
-##     elif len(cond._children) > 1:
-##       chillun = cond._children[:]
-##       cond._children = []
-##       _and = GConditions.GCand(cond)
-##       _and._children = chillun
-
-##     where = " WHERE (%s)" % (self.__conditionToSQL (cond._children[0]))
-##     GDebug.printMesg(5, where)
-##     return where
-
-##   #
-##   # Used internally by _conditionToSQL
-##   #
-##   # This code recursively travels down a condition tree replacing the 
objects
-##   # with a strings representation
-##   def __conditionToSQL (self, element):
-##     if type(element) != types.InstanceType:
-##       return "%s" % element
-##     else:
-##       # Note that we strip the GC from the object types and lowercase the 
rest
-##       otype = string.lower(element._type[2:])
-##       #print "Otype: ",otype
-##       if otype == 'cfield':
-##         return "%s" % element.name
-##       elif otype == 'cconst':
-##         if element.value == None:
-##           return "NULL"
-##         elif element.type == 'number':
-##           return "%s" % element.value
-##         else:
-##           return self._toSqlString(element.value)
-##       elif otype == 'cparam':
-##         v = element.getValue()
-##         return (v == None and "NULL") or ("'%s'" % v)
-##       elif self.conditionElements.has_key(otype):
-##         result=[]
-##         for i in range(0, len(element._children)):
-##           result.append(self.__conditionToSQL(element._children[i]))
-##         if len(result) == 2 and \
-##            otype in ('eq','ne') and \
-##            result[1] == 'NULL':
-##            otype = "__is%s" % otype
-##         if len(result) < self.conditionElements[otype][0]:
-##           tmsg = _('Condition element "%s" expects at least %s arguments; 
found %s') % \
-##             (otype, self.conditionElements[otype][0], len(result))
-##           raise GConditions.ConditionError, tmsg
-##         if len(result) > self.conditionElements[otype][1]:
-##           tmsg = _('Condition element "%s" expects at most %s arguments; 
found %s') % \
-##                 (otype, self.conditionElements[otype][0], len(result))
-##           raise GConditions.ConditionError, tmsg
-
-##         if self.conditionElements[otype][3] == None:
-##           return self.conditionElements[otype][2] % tuple(result)
-##         else:
-##           return self.conditionElements[otype][2] % \
-##             (string.join(result, self.conditionElements[otype][3]))
-##       else:
-##         tmsg = _('Condition clause "%s" is not supported by this db 
driver.') % otype
-##         raise GConditions.ConditionNotSupported, tmsg
-
-##   # Code necessary to force the connection into transaction mode...
-##   # this is usually not necessary (MySQL is one of few DBs that must force)
-##   def _beginTransaction(self):
-##     pass
-
-
-##   def _buildFieldDefinition(self,field):
-##     try:
-##       sql="%s %s" % (field.name,
-##                      self.schema2nativeTypes[field.type])
-##     except:
-##       tmsg = _("Datatype '%s' is not supported by database")
-##       raise GDataObjects.DataTypeNotAvailable, tmsg
-    
-##     if hasattr(field,"size"):
-##       sql=sql+"(%s)" % field.size
-         
-##     #   if hasattr(field,"precision"):
-##     #   if hasattr(field,"scale"):
-
-##     if not field.nullable:
-##       sql=sql+" NOT NULL"
-      
-##     if hasattr(field,"default"):
-##       sql=sql+" DEFAULT %s" % self._toSqlString(field.default)
-
-##     return sql
-
-##   def _buildTableDefinition(self,tbl):
-      
-##     sql="CREATE TABLE %s (" % tbl.name
-
-
-##     # add fields to table
-
-##     fields=tbl.findChildOfType("GSFields")
-
-##     delim=""
-
-##     for field in fields._children:
-      
-##        sql=sql+delim+"%s" % self._buildFieldDefinition(field)
-##        delim=","
-
-##     # define primary key
-
-##     pk=tbl.findChildOfType("GSPrimaryKey")
-
-##     if (pk!=None) and len(pk._children):
-      
-##       sql=sql+", primary key %s (" % pk.name
-      
-##       delim=""
-    
-##       for pkfield in pk._children:
-        
-##         sql=sql+delim+pkfield.name
-        
-##         delim=","
-
-##       sql=sql+") "
-      
-
-##     # close definition
-
-##     sql=sql+");"
-
-##     GDebug.printMesg(1,"SQL Statement: %s" % sql)
-
-##     return sql
-  
-##   def writeTable(self,tbl,overwrite):
-    
-##     sql = self._buildTableDefinition(tbl)
-    
-##     try:
-##       cursor = self._dataConnection.cursor()
-##       cursor.execute(sql)
-##       cursor.close()
-##     except:
-##       # test it is an error because of an existing table
-##       # directly raise an error, if it is an access rights problem
-##       if not overwrite:
-##         return "Could not write table %s to database." % tbl.name
-##       else:
-##         cursor = self._dataConnection.cursor()
-##         # drop table
-##         cursor.execute("drop table %s" % tbl.name)
-##         # create table
-##         cursor.execute(sql)
-##         cursor.close()
-
-
-##   # write Schema to Database
-##   def writeSchema(self,obj,overwrite=0):
-##     if obj._type=="GSTable":
-##       return self.writeTable(obj,overwrite)
-
-##     elif obj._type=="GSView":
-##       return self.writeView(obj,overwrite)
-
-##     else:
-##       # do the same for all children
-##       result=[]
-##       for child in obj._children:
-##         result.append(self.writeSchema(child))
-
-##       if len(result)==0:
-##         return None
-##       elif len(result)==1:
-##         return result[0]
-##       else:
-##         return result
-
-
-
-## class DBSIG_DataObject_Object:
-##   def __init__(self):
-##    # TODO: A dummy placeholder to let old db driver work
-##    # TODO: each can have their *_DataObject_Object object from __init__ing
-##    # TODO: DBSIG_DataObject_Object
-##    GDebug.printMesg(0,
-##      "Database driver needs updated to not initialize 
DBSIG_DataObject_Object")
-
-##   def _buildQuery(self, conditions={}, forDetail=None, additionalSQL=""):
-##     GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences)
-##     if self.distinct:
-##       distinct = "distinct "
-##     else:
-##       distinct = ""
-
-##     if self._primaryIdSelect:
-##       pis = "%s," % self._primaryIdSelect
-##     else:
-##       pis = ""
-
-##     whereClause = self._conditionToSQL(conditions)
-##     if additionalSQL:
-##       if len(whereClause):
-##         whereClause += ' and %s' % (additionalSQL)
-##       else:
-##         whereClause = ' WHERE %s' % (additionalSQL)
-      
-##     if forDetail:
-##       q = "%s in (SELECT %s FROM %s%s)" % \
-##                      (string.join(self._masterfields,","),
-##                       string.join(self._detailfields,","),
-##                       self.table, whereClause)
-##     elif len(self._fieldReferences):
-##       q = "SELECT %s%s%s FROM %s%s" % \
-##            (distinct, pis, string.join(self._fieldReferences.keys(),","), 
self.table,
-##             whereClause)
-##     else:
-##       self._primaryIdSelect = None
-##       q = "SELECT %s* FROM %s%s" % (distinct, self.table,
-##                         whereClause)
-
-##     if hasattr(self,'order_by') and not forDetail:
-##      q = "%s ORDER BY %s " % (q, self.order_by)
-
-##     GDebug.printMesg(5,q)
-
-##     return q
-
-##   def _buildQueryCount(self, conditions={}, additionalSQL=""):
-##     whereClause = self._conditionToSQL(conditions)
-##     if additionalSQL:
-##       if len(whereClause):
-##         whereClause += ' and %s' % (additionalSQL)
-##       else:
-##         whereClause = ' WHERE %s' % (additionalSQL)
-
-
-##     q = "SELECT count(*) FROM %s%s" % (self.table, whereClause)
-
-##     GDebug.printMesg(5,q)
-
-##     return q
-
-## class DBSIG_DataObject_SQL:
-##   def _buildQuery(self, conditions={}):
-##     # Obviously, this is in a pre-alpha state :)
-##     return "select zipcode, city, state from zipcode order by zipcode desc"
-
-## supportedDataObjects = {
-##   'object': DBSIG_DataObject_Object,
-##   'sql':    DBSIG_DataObject_SQL
-## }
-
-
-
-
-





reply via email to

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