[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7338 - in trunk/gnue-common/src/datasources: . drivers/Base driv
From: |
reinhard |
Subject: |
[gnue] r7338 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/DBSIG2 |
Date: |
Mon, 11 Apr 2005 19:03:17 -0500 (CDT) |
Author: reinhard
Date: 2005-04-11 19:03:16 -0500 (Mon, 11 Apr 2005)
New Revision: 7338
Modified:
trunk/gnue-common/src/datasources/GDataSource.py
trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
Log:
Removed a lot of code that's not used any more now.
Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py 2005-04-11 23:49:06 UTC
(rev 7337)
+++ trunk/gnue-common/src/datasources/GDataSource.py 2005-04-12 00:03:16 UTC
(rev 7338)
@@ -379,9 +379,6 @@
self.__setResultSet( resultSet )
return resultSet
- def getQueryString(self,conditions={},forDetailSQL=None,additionalSQL=""):
- return self._dataObject.getQueryString(conditions,
forDetailSQL,additionalSQL)
-
#
# Master/detail stuff
#
Modified: trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
2005-04-11 23:49:06 UTC (rev 7337)
+++ trunk/gnue-common/src/datasources/drivers/Base/DataObject.py
2005-04-12 00:03:16 UTC (rev 7338)
@@ -102,9 +102,6 @@
return resultset
- # Do not over-ride by vendor code
- def getQueryString(self,conditions={},forDetailSQL=None,additionalSQL=""):
- return self._buildQuery(conditions,forDetailSQL,additionalSQL)
def createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-04-11
23:49:06 UTC (rev 7337)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-04-12
00:03:16 UTC (rev 7338)
@@ -392,11 +392,7 @@
if do.primarykey and do.primarykeyseq and ',' not in do.primarykey and
\
hasattr(do._connection,'getsequence') and \
self.getField(do.primarykey) is None:
- try:
-
self.setField(do.primarykey,do._connection.getsequence(do.primarykeyseq))
- except do._connection._DatabaseError:
- raise exceptions.InvalidDatasourceDefintion, \
- errors.getException () [2]
+
self.setField(do.primarykey,do._connection.getsequence(do.primarykeyseq))
# If we have a connection (i.e. we aren't static or unbound), do the post
if self._parent._dataObject._connection:
Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2005-04-11 23:49:06 UTC (rev 7337)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/DataObject.py
2005-04-12 00:03:16 UTC (rev 7338)
@@ -35,14 +35,7 @@
__all__ = ['DataObject','DataObject_SQL','DataObject_Object']
-from gnue.common.datasources import GConditions, Exceptions
from gnue.common.datasources.drivers.Base import DataObject as BaseDataObject
-from gnue.common.apps import errors
-import string
-import types
-import mx.DateTime
-from string import join, replace
-
from ResultSet import ResultSet
######################################################################
@@ -53,267 +46,23 @@
_escapeSingleQuote = "'"
_resultSetClass = ResultSet
- _DatabaseError = None
# The date/time format used in insert/select statements
# (based on format used for time.strftime())
_dateTimeFormat = "'%c'"
_timeFormat = "'%X'"
- 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 ),
- 'upper': (1, 1, 'UPPER(%s)', None ),
- 'lower': (1, 1, 'LOWER(%s)', None )}
-
- def __init__(self, *args, **params):
- BaseDataObject.__init__(self, *args, **params)
-
- gDebug (8, "DB-SIG database driver backend initializing")
-
- self.distinct = False
-
- # If possible, this will contain the field names used in the last select
- # in the same order used in the SELECT statement.
- self._fieldOrder = []
-
-
- def _toSqlString(self, value):
- if isinstance (value, mx.DateTime.DateTimeType):
- if (value.year, value.month, value.day) == (1, 1, 1):
- return value.strftime (self._timeFormat)
- else:
- return value.strftime (self._dateTimeFormat)
- else:
- 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 (1, 'WARNING: non-unicode passed to the dbdriver (%s)' %
value)
-
- return "'%s'" % replace(value,
- "'",
- "%s'" % self._escapeSingleQuote)
-
- elif type(value) == types.UnicodeType:
- return "'%s'" % replace(value,
- "'",
- "%s'" % self._escapeSingleQuote)
-
- # TODO: make this test faster, possibly move type check to GTypecast
- elif hasattr(types,'BooleanType') and type(value) == types.BooleanType:
- if value:
- return 'TRUE'
- else:
- return 'FALSE'
-
- else:
- err = u_("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 Exceptions.UnknownDataType, err
- gDebug (1, err)
- return "'%s'" % replace(str(value),
- "'",
- "%s'" % self._escapeSingleQuote)
-
-
- # 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 (8, 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 = u_('Condition element "%(element)s" expects at least '
- '%(expected)s arguments; found %(found)s') \
- % {'element' : otype,
- 'expected': self.conditionElements[otype][0],
- 'found' : len (result)}
- raise GConditions.ConditionError, tmsg
-
- if len(result) > self.conditionElements [otype][1]:
- tmsg = u_('Condition element "%(element)s" expects at most '
- '%(expected)s arguments; found %(found)s') \
- % {'element' : otype,
- 'expected': self.conditionElements[otype][1],
- 'found' : 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] % \
- (join(result, self.conditionElements[otype][3]))
- else:
- tmsg = u_('Condition clause "%s" is not supported by this db driver.')
% otype
- raise GConditions.ConditionNotSupported, tmsg
-
-
-
######################################################################
#
#
#
-class DataObject_Object(DataObject):
+class DataObject_Object (DataObject):
+ pass
- def _buildQuery(self, conditions={}, forDetail=None, additionalSQL=""):
- gDebug (8, 'DBSIG2-DO::Implicit Fields: %s' % self._fieldReferences)
- if self.distinct:
- distinct = "distinct "
- else:
- distinct = ""
-
- 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)" % \
- (join(self._masterfields,","),
- join(self._detailfields,","),
- self.table, whereClause)
-
- elif hasattr (self, '_dataSource') and
self._dataSource._hasFieldReferences:
- # Explicitly referenced fields give, no need to select *
- self._fieldOrder = fields = self._fieldReferences.keys()
- q = "SELECT %s%s FROM %s%s" % \
- (distinct, join(fields,","), self.table,
- whereClause)
-
- elif self._fieldReferences:
- # All referenced fields were added in the background (like primarykey or
- # rowid), so we add * to the query
- self._fieldOrder = fields = self._fieldReferences.keys()
- q = "SELECT %s%s, * FROM %s%s" % \
- (distinct, join(fields,","), self.table,
- whereClause)
-
- else:
- # No fields at all referenced (neither explicitly nor automatically), so
- # only select * in the query
- self._fieldOrder = []
- q = "SELECT %s* FROM %s%s" % (distinct, self.table,
- whereClause)
-
- if hasattr (self, 'sorting') and not forDetail and self.sorting:
- order = []
- for item in self.sorting:
- field = item ['name']
- descending = item.get ('descending') or False
- ignorecase = item.get ('ignorecase') or False
-
- fmt = ignorecase and "LOWER(%s)%s" or "%s%s"
- order.append (fmt % (field, descending and ' desc' or ''))
-
- q = "%s ORDER BY %s " % (q, string.join (order, ", "))
-
- gDebug (8, q)
-
- return q
-
######################################################################
#
#
#
-class DataObject_SQL(DataObject):
-
- # Set by GDataSource
- # (GDataSource.GSql instance)
- _rawSQL = None
-
- def _buildQuery(self, conditions={}, forDetail=None, additionalSQL=""):
- try:
- sql= self.__sql
- except AttributeError:
- sql = self.__sql = self._rawSQL.getChildrenAsContent()
- return sql
-
-
+class DataObject_SQL (DataObject):
+ pass
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7338 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/DBSIG2,
reinhard <=