[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/gnue-common/gnue/common GDataSource.py dbd...
From: |
Jason Cater |
Subject: |
gnue/gnue-common/gnue/common GDataSource.py dbd... |
Date: |
Tue, 05 Jun 2001 18:22:56 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/06/05 18:22:55
Modified files:
gnue-common/gnue/common: GDataSource.py
gnue-common/gnue/common/dbdrivers/_dbsig: DBdriver.py
Log message:
Added conditional support to gnue-comon dbdrivers
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GDataSource.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: gnue/gnue-common/gnue/common/GDataSource.py
diff -u gnue/gnue-common/gnue/common/GDataSource.py:1.5
gnue/gnue-common/gnue/common/GDataSource.py:1.6
--- gnue/gnue-common/gnue/common/GDataSource.py:1.5 Tue May 29 19:20:57 2001
+++ gnue/gnue-common/gnue/common/GDataSource.py Tue Jun 5 18:22:55 2001
@@ -112,54 +112,7 @@
'detaillink': (0, 0, char, None) }
xmlElements = {
- 'sql': (GSql, { }, 1) }
+# 'sql': (GSql, { }, 1)
+ }.update(GConnections.xmlElements)
-
-
-####
-# These may be used by an xml-query based DataSource later
-# 'query': (GRQquery, { 'id': (1, 1, char, None),
-# 'uniqueness': (0, 0, char, None)}, 1),
-# 'fields': (GRQfields, { }, 1),
-# 'subquery': (GRQsubquery, { }, 1),
-# 'fields': (GRQfields, { }, 1),
-# 'columns': (GRQcolumns, { }, 1),
-# 'field': (GRQfield, { 'id': (1, 1, char, None)}, 1),
-# 'subcolumn': (GRQsubcolumn,{ }, 1),
-# 'source': (GRQsource, { 'id': (1, 1, char, None)}, 1),
-# 'table': (GRQtable, { 'name': (1, 0, char, None)}, 1),
-# 'func': (GRQfunc, { 'name': (1, 0, char, None)}, 1),
-# 'column': (GRQcolumn, { 'name': (1, 0, char, None)}, 1),
-# 'sources': (GRQsources, { }, 1),
-# 'conditions': (GRQconditions,{ }, 1),
-# 'groupby': (GRQgroupby, { }, 1),
-# 'having': (GRQhaving, { }, 1),
-# 'union': (GRQunion, { 'type': (1, 0, char, None)}, 1),
-# 'const': (GRQconst, { 'type': (1, 0, char, None)}, 1),
-# 'add': (GRQadd, { }, 1),
-# 'sub': (GRQsub, { }, 1),
-# 'mul': (GRQmul, { }, 1),
-# 'div': (GRQdiv, { }, 1),
-# 'and': (GRQand, { }, 1),
-# 'or': (GRQor, { }, 1),
-# 'not': (GRQnot, { }, 1),
-# 'negate': (GRQnegate, { }, 1),
-# 'eq': (GRQeq, { }, 1),
-# 'ne': (GRQne, { }, 1),
-# 'gt': (GRQgt, { }, 1),
-# 'ge': (GRQge, { }, 1),
-# 'lt': (GRQlt, { }, 1),
-# 'le': (GRQle, { }, 1),
-# 'like': (GRQlike, { }, 1),
-# 'notlike': (GRQnotlike, { }, 1),
-# 'between': (GRQbetween, { }, 1),
-# 'notbetween': (GRQnotbetween,{ }, 1),
-# 'count': (GRQcount, { }, 1),
-# 'countdistinct':(GRQcountdistinct,{ }, 1),
-# 'countall': (GRQcountall, { }, 1),
-# 'sum': (GRQsum, { }, 1),
-# 'avg': (GRQavg, { }, 1),
-# 'max': (GRQmax, { }, 1),
-# 'min': (GRQmin, { }, 1)
-####
Index: gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py
diff -u gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.5
gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.6
--- gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.5 Tue Jun
5 08:57:45 2001
+++ gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py Tue Jun 5
18:22:55 2001
@@ -31,9 +31,10 @@
# HISTORY:
#
-from gnue.common import GDataObjects, GDebug
+from gnue.common import GDataObjects, GDebug, GConditions
import string
from gnue.common import GDebug
+import types
class DBSIG_RecordSet(GDataObjects.RecordSet):
def _postChanges(self):
@@ -78,6 +79,26 @@
class DBSIG_DataObject(GDataObjects.DataObject):
+
+ conditionElements = {
+ 'add': (1, 2, 999, '(%s)', '+' ),
+ 'sub': (1, 2, 999, '(%s)', '-' ),
+ 'mul': (1, 2, 999, '(%s)', '*' ),
+ 'div': (1, 2, 999, '(%s)', '/' ),
+ 'and': (1, 2, 999, '(%s)', ' AND ' ),
+ 'or': (1, 2, 999, '(%s)', ' OR ' ),
+ 'not': (1, 1, 1, '(NOT %s)', None ),
+ 'negate': (1, 1, 1, '-%s', None ),
+ 'eq': (1, 2, 2, '(%s = %s)', None ),
+ 'ne': (1, 2, 2, '(%s != %s)', None ),
+ 'gt': (1, 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 ) }
+
def __init__(self):
GDataObjects.DataObject.__init__(self)
@@ -124,22 +145,68 @@
return None
+ # Used to convert a condition tree to an sql where clause
+ def _conditionToSQL (condition):
+ if condition == {} or condition == None:
+ return ""
+ elif type(condition) == types.DictType:
+ cond = GConditions.buildConditionFromDict(cond)
+ 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
+
+ return " WHERE (%s)" % (this.__conditionToSQL (cond._children[0]))
+
+ # Used internally by _conditionToSQL
+ def __conditionToSQL (element):
+ if type(element) != types.InstanceType:
+ return "%s" % element
+ else:
+ otype = string.lower(element.getObjectType()[2:])
+ if otype == 'field':
+ return "%s" % element.name
+ elif otype == 'const':
+ return "'%s'" % element.value
+ elif otype == 'param':
+ return "'%s'" % element.getValue()
+ elif self.conditionElements.has_key(otype):
+ for i in range(0, len(element._children)):
+ element._children[i] = __conditionToSQL(element._children[i])
+ if len(element._children) < self.conditionElements[otype][0]:
+ raise GConditions.ConditionError, \
+ 'Condition element "%s" expects at least %s arguments; found %s' %
\
+ (otype, self.conditionElements[otype][0],
len(element._children))
+ if len(element._children[i]) < self.conditionElements[otype][1]:
+ raise GConditions.ConditionError, \
+ 'Condition element "%s" expects at most %s arguments; found %s' % \
+ (otype, self.conditionElements[otype][0],
len(element._children))
+ if self.conditionElements[otype][4] == None:
+ return self.conditionElements[otype][3] % tuple(element._children)
+ else:
+ return self.conditionElements[otype][3] % \
+ (string.join(element._children, self.conditionElements[otype][4]))
+ else:
+ raise GConditions.ConditionNotSupported, \
+ 'Condition clause "%s" is not supported by this db driver.' % otype
+
+
class DBSIG_DataObject_Object(DBSIG_DataObject):
def _buildQuery(self, conditions={}):
GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences)
if len(self._fieldReferences):
- q = "select %s from %s" % \
- (string.join(self._fieldReferences.keys(),","), self.table)
+ q = "SELECT %s FROM %s%s" % \
+ (string.join(self._fieldReferences.keys(),","), self.table,
+ self._conditionToSQL(conditions))
else:
- q = "select * from %s" % self.table
-
- GDebug.printMesg (5, 'Conditions For Query: %s' % conditions)
- if len(conditions):
- c = []
- for key in conditions.keys():
- c.append("%s='%s'" % (key, conditions[key]))
- q = q + " where (%s)" % string.join(c,') AND (')
+ q = "SELECT * FROM %s%s" % (self.table, self._conditionToSQL(conditions))
GDebug.printMesg(5,q)
@@ -158,28 +225,5 @@
'object': DBSIG_DataObject_Object,
'sql': DBSIG_DataObject_SQL
}
-
-
-conditionElements = {
- 'field': ( 1, 1, '%s', None ),
- 'param': ( 1, 1, '%s', None ),
- 'const': ( 1, 1, "'%s'", None ),
- 'add': ( 2, 999, '(%s)', '+' ),
- 'sub': ( 2, 999, '(%s)', '-' ),
- 'mul': ( 2, 999, '(%s)', '*' ),
- 'div': ( 2, 999, '(%s)', '/' ),
- 'and': ( 2, 999, '(%s)', ' AND ' ),
- 'or': ( 2, 999, '(%s)', ' OR ' ),
- 'not': ( 1, 1, '(NOT %s)', None ),
- 'negate': ( 1, 1, '-%s', 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 ) }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/gnue-common/gnue/common GDataSource.py dbd...,
Jason Cater <=