[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5021 - in trunk/gnue-common/src/datasources/drivers: DBSIG2 postgresql/
From: |
jamest |
Subject: |
r5021 - in trunk/gnue-common/src/datasources/drivers: DBSIG2 postgresql/Base |
Date: |
Sun, 4 Jan 2004 12:41:12 -0600 (CST) |
Author: jamest
Date: 2004-01-04 12:41:10 -0600 (Sun, 04 Jan 2004)
New Revision: 5021
Modified:
trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py
trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
trunk/gnue-common/src/datasources/drivers/postgresql/Base/RecordSet.py
Log:
commented out some unneeded (i hope) code to reduce confusion
ported fixes from old db driver to new seperated driver
Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2004-01-02 15:02:22 UTC (rev 5020)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2004-01-04 18:41:10 UTC (rev 5021)
@@ -120,16 +120,16 @@
return "NULL"
elif type(value) == types.IntType:
- return str(value)
+ return "'%d'" % value
elif type(value) == types.LongType:
- return str(value)
+ return "'%d'" % value
elif type(value) == types.FloatType:
if value==int(value):
- return "%d" % value
+ return "'%d'" % value
else:
- return str(value)
+ return "'" + str (value) + "'"
elif type(value) == types.StringType:
Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py 2004-01-02
15:02:22 UTC (rev 5020)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Driver.py 2004-01-04
18:41:10 UTC (rev 5021)
@@ -30,595 +30,599 @@
#
# 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
+## from gnue.common.datasources import GDataObjects, GConditions
+## from gnue.common.apps import GDebug
+## import string
+## import types
-class DBSIG_RecordSet(GDataObjects.RecordSet):
+## 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()
+## 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)
+## GDebug.printMesg(5, "_postChanges: statement=%s" % statement)
- try:
- self._parent._update_cursor.execute(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)
+## # Set _initialData to be the just-now posted values
+## if not self._deleteFlag:
+## self._initialData = {}
+## self._initialData.update(self._fields)
- except self._parent._dataObject._DatabaseError, err:
- raise GDataObjects.ConnectionError, err
+## except self._parent._dataObject._DatabaseError, err:
+## raise GDataObjects.ConnectionError, err
- self._updateFlag = 0
- self._insertFlag = 0
- self._deleteFlag = 0
+## self._updateFlag = 0
+## self._insertFlag = 0
+## self._deleteFlag = 0
- return 1
+## 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)
+## # 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])))
+## 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
+## statement = "DELETE FROM %s WHERE %s" % \
+## (self._parent._dataObject.table, string.join(where,' AND ') )
+## return statement
- def _buildInsertStatement(self):
- vals = []
- fields = []
+## 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]))
+## 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,',') )
+## 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])))
+## 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])))
+## 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 ') )
+## 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 = []
+## 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)
+## 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
+## self._recordCount = cursor.rowcount or 0
- GDebug.printMesg(5, 'ResultSet created')
+## GDebug.printMesg(5, 'ResultSet created')
- def _loadNextRecord(self):
- if self._cursor:
- rs = None
+## def _loadNextRecord(self):
+## if self._cursor:
+## rs = None
- try:
- rsets = self._cursor.fetchmany()
- except self._dataObject._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)
+## try:
+## rsets = self._cursor.fetchmany()
+## except self._dataObject._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
+## 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):
+## 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 )}
+## 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)
+## def __init__(self, strictQueryCount=1):
+## GDataObjects.DataObject.__init__(self)
- GDebug.printMesg (1,"DB-SIG database driver backend initializing")
+## 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
+## # 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
+## 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
+## # 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
+## # 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'"
+## # 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:
+## def _toSqlString(self, value):
+## try:
+## return value.strftime(self._dateTimeFormat)
+## except AttributeError:
- if value == None:
- return "NULL"
+## if value == None:
+## return "NULL"
- elif type(value) == types.IntType:
- return "'%d'" % value
+## elif type(value) == types.IntType:
+## return "'%d'" % value
- elif type(value) == types.LongType:
- 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.FloatType:
+## if value==int(value):
+## return "'%d'" % value
+## else:
+## return "'" + str (value) + "'"
- elif type(value) == types.StringType:
+## elif type(value) == types.StringType:
- if self._unicodeMode:
- GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver
(%s)' % value)
+## if self._unicodeMode:
+## GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver
(%s)' % value)
- return "'%s'" % string.replace(value,
- "'",
- "%s'" % self._escapeSingleQuote)
+## return "'%s'" % string.replace(value,
+## "'",
+## "%s'" % self._escapeSingleQuote)
- elif type(value) == types.UnicodeType:
- return "'%s'" % string.replace(value.encode(self._databaseEncoding),
- "'",
- "%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'
+## # 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)
+## 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]]
+## # 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
+## # 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=""):
+## def _createResultSet(self, conditions={}, readOnly=0,
masterRecordSet=None,sql=""):
- # Used by drivers with a unique id (like rowid)
- if not self._primaryIdChecked: self._checkForPrimaryId()
+## # Used by drivers with a unique id (like rowid)
+## if not self._primaryIdChecked: self._checkForPrimaryId()
- try:
- cursor = self._dataConnection.cursor()
+## try:
+## cursor = self._dataConnection.cursor()
- cursor.arraysize = self.cache
- cursor.execute(self._buildQuery(conditions, additionalSQL=sql))
+## 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)
+## # 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
+## 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
+## rs = self._resultSetClass(self, cursor=cursor,
masterRecordSet=masterRecordSet)
+## if self._strictQueryCount:
+## rs._recordCount = recordCount
+## if readOnly:
+## rs._readonly = readOnly
- return rs
+## return rs
- def _getQueryCount(self,conditions={},sql=""):
- cursor = self._dataConnection.cursor()
+## def _getQueryCount(self,conditions={},sql=""):
+## cursor = self._dataConnection.cursor()
- cursor.execute(self._buildQueryCount(conditions,additionalSQL=sql))
- rs = cursor.fetchone()
- return int(rs[0])
+## 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()")
+## def commit(self):
+## GDebug.printMesg (5,"DB-SIG database driver: commit()")
- try:
- self._dataConnection.commit()
- except self._DatabaseError, value:
- raise GDataObjects.ConnectionError, value
+## try:
+## self._dataConnection.commit()
+## except self._DatabaseError, value:
+## raise GDataObjects.ConnectionError, value
- self._beginTransaction()
+## self._beginTransaction()
- def rollback(self):
- GDebug.printMesg (5,"DB-SIG database driver: rollback()")
+## 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
+## try:
+## self._dataConnection.rollback()
+## except:
+## pass # I'm SURE this isn't right (jcater)
+## # But not all db's support transactions
- self._beginTransaction()
+## 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
+## # 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
+## 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
+## 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
+## #
+## # 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
+## 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
+## # 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
+## 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,"size"):
+## sql=sql+"(%s)" % field.size
- # if hasattr(field,"precision"):
- # if hasattr(field,"scale"):
+## # if hasattr(field,"precision"):
+## # if hasattr(field,"scale"):
- if not field.nullable:
- sql=sql+" NOT NULL"
+## if not field.nullable:
+## sql=sql+" NOT NULL"
- if hasattr(field,"default"):
- sql=sql+" DEFAULT %s" % self._toSqlString(field.default)
+## if hasattr(field,"default"):
+## sql=sql+" DEFAULT %s" % self._toSqlString(field.default)
- return sql
+## return sql
- def _buildTableDefinition(self,tbl):
+## def _buildTableDefinition(self,tbl):
- sql="CREATE TABLE %s (" % tbl.name
+## sql="CREATE TABLE %s (" % tbl.name
- # add fields to table
+## # add fields to table
- fields=tbl.findChildOfType("GSFields")
+## fields=tbl.findChildOfType("GSFields")
- delim=""
+## delim=""
- for field in fields._children:
+## for field in fields._children:
- sql=sql+delim+"%s" % self._buildFieldDefinition(field)
- delim=","
+## sql=sql+delim+"%s" % self._buildFieldDefinition(field)
+## delim=","
- # define primary key
+## # define primary key
- pk=tbl.findChildOfType("GSPrimaryKey")
+## pk=tbl.findChildOfType("GSPrimaryKey")
- if (pk!=None) and len(pk._children):
+## if (pk!=None) and len(pk._children):
- sql=sql+", primary key %s (" % pk.name
+## sql=sql+", primary key %s (" % pk.name
- delim=""
+## delim=""
- for pkfield in pk._children:
+## for pkfield in pk._children:
- sql=sql+delim+pkfield.name
+## sql=sql+delim+pkfield.name
- delim=","
+## delim=","
- sql=sql+") "
+## sql=sql+") "
- # close definition
+## # close definition
- sql=sql+");"
+## sql=sql+");"
- GDebug.printMesg(1,"SQL Statement: %s" % sql)
+## GDebug.printMesg(1,"SQL Statement: %s" % sql)
- return sql
+## return sql
- def writeTable(self,tbl,overwrite):
+## def writeTable(self,tbl,overwrite):
- sql = self._buildTableDefinition(tbl)
+## 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()
+## 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)
+## # 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)
+## 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))
+## 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
+## 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")
+## 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 = ""
+## 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 = ""
+## 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)
+## 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 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)
+## if hasattr(self,'order_by') and not forDetail:
+## q = "%s ORDER BY %s " % (q, self.order_by)
- GDebug.printMesg(5,q)
+## GDebug.printMesg(5,q)
- return 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)
+## 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)
+## q = "SELECT count(*) FROM %s%s" % (self.table, whereClause)
- GDebug.printMesg(5,q)
+## GDebug.printMesg(5,q)
- return 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"
+## 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
-}
+## supportedDataObjects = {
+## 'object': DBSIG_DataObject_Object,
+## 'sql': DBSIG_DataObject_SQL
+## }
Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
2004-01-02 15:02:22 UTC (rev 5020)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/RecordSet.py
2004-01-04 18:41:10 UTC (rev 5021)
@@ -113,6 +113,7 @@
string.join(vals,',') )
def _buildUpdateStatement(self):
+ print "come on camel update"
updates = []
for field in self._modifiedFlags.keys():
updates.append ("%s=%s" % (field,
Modified: trunk/gnue-common/src/datasources/drivers/postgresql/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/postgresql/Base/RecordSet.py
2004-01-02 15:02:22 UTC (rev 5020)
+++ trunk/gnue-common/src/datasources/drivers/postgresql/Base/RecordSet.py
2004-01-04 18:41:10 UTC (rev 5021)
@@ -38,24 +38,29 @@
#
#
class RecordSet(DBSIG2.RecordSet):
- def _buildUpdateStatement(self):
- updates = []
- for field in self._modifiedFlags.keys():
- updates.append ("%s=%s" % (field,
- self._parent._dataObject._toSqlString(self._fields[field])))
+ pass
- 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 ') )
+##
+## Seems identical to the base records function
+##
+## 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 ') )
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5021 - in trunk/gnue-common/src/datasources/drivers: DBSIG2 postgresql/Base,
jamest <=