16 |
# write to the Free Software Foundation, Inc., 59 Temple Place |
# write to the Free Software Foundation, Inc., 59 Temple Place |
17 |
# - Suite 330, Boston, MA 02111-1307, USA. |
# - Suite 330, Boston, MA 02111-1307, USA. |
18 |
# |
# |
19 |
# Copyright 2000-2002 Free Software Foundation |
# Copyright 2000-2003 Free Software Foundation |
20 |
# |
# |
21 |
# FILE: |
# FILE: |
22 |
# _dbsig/DBdriver.py |
# _dbsig/DBdriver.py |
55 |
except self._parent._dataObject._DatabaseError, err: |
except self._parent._dataObject._DatabaseError, err: |
56 |
pass |
pass |
57 |
return 0 |
return 0 |
58 |
|
|
59 |
|
|
60 |
def _postChanges(self): |
def _postChanges(self): |
61 |
if not self.isPending(): return |
if not self.isPending(): return |
62 |
auxTable = string.split(string.replace(self._parent._dataObject.table,' ',''),',') |
auxTable = string.split(string.replace(self._parent._dataObject.table,' ',''),',') |
68 |
if self._deleteFlag: |
if self._deleteFlag: |
69 |
auxTable.reverse() |
auxTable.reverse() |
70 |
for table in auxTable: |
for table in auxTable: |
71 |
statements.append(self._buildDeleteStatement(table)) |
statements.append(self._buildDeleteStatement(table)) |
72 |
elif self._insertFlag: |
elif self._insertFlag: |
73 |
for table in auxTable: |
for table in auxTable: |
74 |
statements.append(self._buildInsertStatement(table)) |
statements.append(self._buildInsertStatement(table)) |
87 |
statements.append(self._buildUpdateStatement(iterTable)) |
statements.append(self._buildUpdateStatement(iterTable)) |
88 |
else: |
else: |
89 |
statements.append(self._buildUpdateStatement(auxTable[0])) |
statements.append(self._buildUpdateStatement(auxTable[0])) |
90 |
|
|
91 |
for statement in statements: |
for statement in statements: |
92 |
GDebug.printMesg(5, "_postChanges: statement=%s" % statement) |
GDebug.printMesg(5, "_postChanges: statement=%s" % statement) |
93 |
|
|
94 |
try: |
try: |
95 |
print "statement: %s" % statement |
#print "statement: %s" % statement |
96 |
self._parent._update_cursor.execute(statement) |
self._parent._update_cursor.execute(statement) |
97 |
|
|
98 |
# Set _initialData to be the just-now posted values |
# Set _initialData to be the just-now posted values |
99 |
if not self._deleteFlag: |
if not self._deleteFlag: |
100 |
self._initialData = {} |
self._initialData = {} |
101 |
self._initialData.update(self._fields) |
self._initialData.update(self._fields) |
102 |
|
|
103 |
except self._parent._dataObject._DatabaseError, err: |
except self._parent._dataObject._DatabaseError, err: |
104 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError, err |
105 |
|
|
106 |
self._updateFlag = 0 |
self._updateFlag = 0 |
107 |
self._insertFlag = 0 |
self._insertFlag = 0 |
108 |
self._deleteFlag = 0 |
self._deleteFlag = 0 |
132 |
if not result: break |
if not result: break |
133 |
result = self._doInsertStatementWHist(iterTable) |
result = self._doInsertStatementWHist(iterTable) |
134 |
if not result: break |
if not result: break |
135 |
print iterTable |
#print iterTable |
136 |
else: |
else: |
137 |
result = self._doDeleteStatementWHist(auxTable[0]) |
result = self._doDeleteStatementWHist(auxTable[0]) |
138 |
if result: result = self._doInsertStatementWHist(auxTable[0]) |
if result: result = self._doInsertStatementWHist(auxTable[0]) |
139 |
|
|
|
|
|
140 |
# Set _initialData to be the just-now posted values |
# Set _initialData to be the just-now posted values |
141 |
if not self._deleteFlag: |
if not self._deleteFlag: |
142 |
self._initialData = {} |
self._initialData = {} |
143 |
self._initialData.update(self._fields) |
self._initialData.update(self._fields) |
144 |
|
|
145 |
|
|
146 |
self._updateFlag = 0 |
self._updateFlag = 0 |
147 |
self._insertFlag = 0 |
self._insertFlag = 0 |
148 |
self._deleteFlag = 0 |
self._deleteFlag = 0 |
165 |
if self._initialData.has_key(table+"."+iterField): |
if self._initialData.has_key(table+"."+iterField): |
166 |
where.append(auxWhere % (iterField,self._initialData[table+"."+iterField])) |
where.append(auxWhere % (iterField,self._initialData[table+"."+iterField])) |
167 |
else: |
else: |
168 |
where.append(auxWhere % (iterField,self._initialData[iterField])) |
where.append(auxWhere % (iterField,self._initialData[iterField])) |
169 |
else: |
else: |
170 |
for field in self._initialData.keys(): |
for field in self._initialData.keys(): |
171 |
if self._parent.isFieldBound(field): |
if self._parent.isFieldBound(field): |
203 |
def _buildInsertStatement(self, table): |
def _buildInsertStatement(self, table): |
204 |
vals = [] |
vals = [] |
205 |
fields = [] |
fields = [] |
206 |
|
|
207 |
pkFields = [] |
pkFields = [] |
208 |
if self._parent._dataObject._primaryKeys: |
if self._parent._dataObject._primaryKeys: |
209 |
pkFields.extend(self._parent._dataObject._primaryKeys[table]) |
pkFields.extend(self._parent._dataObject._primaryKeys[table]) |
227 |
continue |
continue |
228 |
except ValueError: |
except ValueError: |
229 |
pass |
pass |
230 |
|
|
231 |
fields.append(auxField) |
fields.append(auxField) |
232 |
if self._fields[field] == None or self._fields[field] == '': |
if self._fields[field] == None or self._fields[field] == '': |
233 |
vals.append ("NULL") # % (self._fields[field])) |
vals.append ("NULL") # % (self._fields[field])) |
234 |
else: |
else: |
235 |
vals.append (self._parent._dataObject._toSqlString(self._fields[field])) |
vals.append (self._parent._dataObject._toSqlString(self._fields[field])) |
|
|
|
236 |
for iterField in pkFields: |
for iterField in pkFields: |
237 |
fields.append(iterField) |
fields.append(iterField) |
238 |
tmpTable = table[0:24] |
tmpTable = table[0:24] |
250 |
return "INSERT INTO %s (%s) VALUES (%s)" % \ |
return "INSERT INTO %s (%s) VALUES (%s)" % \ |
251 |
(table, string.join(fields,','), \ |
(table, string.join(fields,','), \ |
252 |
string.join(vals,',') ) |
string.join(vals,',') ) |
253 |
|
|
254 |
def _doInsertStatementWHist(self, table): |
def _doInsertStatementWHist(self, table): |
255 |
vals = [] |
vals = [] |
256 |
fields = [] |
fields = [] |
257 |
|
|
258 |
pkFields = [] |
pkFields = [] |
259 |
if self._parent._dataObject._primaryKeys: |
if self._parent._dataObject._primaryKeys: |
260 |
pkFields.extend(self._parent._dataObject._primaryKeys[table]) |
pkFields.extend(self._parent._dataObject._primaryKeys[table]) |
294 |
vals.append(seqValue) |
vals.append(seqValue) |
295 |
self._fields[table+'.'+iterField] = seqValue |
self._fields[table+'.'+iterField] = seqValue |
296 |
|
|
297 |
|
#print self._parent._dataObject._joinConditions |
298 |
for iterField in self._parent._dataObject._joinConditions.keys(): |
for iterField in self._parent._dataObject._joinConditions.keys(): |
299 |
[auxTable, auxField] = iterField.split('.') |
[auxTable, auxField] = iterField.split('.') |
300 |
if auxTable == table: |
if auxTable == table: |
308 |
|
|
309 |
statement = "INSERT INTO %s (%s) VALUES (%s)" % \ |
statement = "INSERT INTO %s (%s) VALUES (%s)" % \ |
310 |
(table, string.join(fields,','), \ |
(table, string.join(fields,','), \ |
311 |
string.join(vals,',') ) |
string.join(vals,',') ) |
312 |
print statement |
#print statement |
313 |
try: |
try: |
314 |
self._parent._update_cursor.execute("BEGIN") |
self._parent._update_cursor.execute("BEGIN") |
315 |
self._parent._update_cursor.execute(statement) |
self._parent._update_cursor.execute(statement) |
316 |
self._parent._update_cursor.execute("COMMIT") |
self._parent._update_cursor.execute("COMMIT") |
317 |
|
|
318 |
except self._parent._dataObject._DatabaseError, err: |
except self._parent._dataObject._DatabaseError, err: |
319 |
GDebug.printMesg(5, "_doInsertStatementWHist: ERROR = %s" % err) |
#print "_doInsertStatementWHist: ERROR = %s" % err |
320 |
|
GDebug.printMesg(5, "_doInsertStatementWHist: ERROR = %s" % err) |
321 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError, err |
322 |
|
|
323 |
return 1 |
return 1 |
324 |
|
|
325 |
def _buildUpdateStatement(self, table): |
def _buildUpdateStatement(self, table): |
326 |
updates = [] |
updates = [] |
327 |
for field in self._modifiedFlags.keys(): |
for field in self._modifiedFlags.keys(): |
365 |
else: |
else: |
366 |
where.append ("%s=%s" % (auxField, self._parent._dataObject._toSqlString(self._initialData[field]))) |
where.append ("%s=%s" % (auxField, self._parent._dataObject._toSqlString(self._initialData[field]))) |
367 |
|
|
368 |
return "UPDATE %s SET %s WHERE %s" % \ |
statement = "UPDATE %s SET %s WHERE %s" % \ |
369 |
(table, string.join(updates,','), \ |
(table, string.join(updates,','), \ |
370 |
string.join(where,' AND ') ) |
string.join(where,' AND ') ) |
371 |
|
#print statement |
372 |
|
return statement |
373 |
|
|
374 |
|
|
375 |
class DBSIG_ResultSet(GDataObjects.ResultSet): |
class DBSIG_ResultSet(GDataObjects.ResultSet): |
425 |
class DBSIG_DataObject(GDataObjects.DataObject): |
class DBSIG_DataObject(GDataObjects.DataObject): |
426 |
|
|
427 |
conditionElements = { |
conditionElements = { |
428 |
'add': (2, 999, '(%s)', '+' ), |
'add': (2, 999, '(%s)', '+' ), |
429 |
'sub': (2, 999, '(%s)', '-' ), |
'sub': (2, 999, '(%s)', '-' ), |
430 |
'mul': (2, 999, '(%s)', '*' ), |
'mul': (2, 999, '(%s)', '*' ), |
431 |
'div': (2, 999, '(%s)', '/' ), |
'div': (2, 999, '(%s)', '/' ), |
432 |
'and': (1, 999, '(%s)', ' AND ' ), |
'and': (1, 999, '(%s)', ' AND ' ), |
433 |
'or': (2, 999, '(%s)', ' OR ' ), |
'or': (2, 999, '(%s)', ' OR ' ), |
434 |
'not': (1, 1, '(NOT %s)', None ), |
'not': (1, 1, '(NOT %s)', None ), |
435 |
'negate': (1, 1, '-%s', None ), |
'negate': (1, 1, '-%s', None ), |
436 |
'null': (1, 1, '(%s IS NULL)', None ), |
'null': (1, 1, '(%s IS NULL)', None ), |
437 |
'notnull': (1, 1, '(%s IS NOT NULL)', None ), |
'notnull': (1, 1, '(%s IS NOT NULL)', None ), |
438 |
'eq': (2, 2, '(%s = %s)', None ), |
'eq': (2, 2, '(%s = %s)', None ), |
439 |
'ne': (2, 2, '(%s != %s)', None ), |
'ne': (2, 2, '(%s != %s)', None ), |
440 |
'gt': (2, 2, '(%s > %s)', None ), |
'gt': (2, 2, '(%s > %s)', None ), |
441 |
'ge': (2, 2, '(%s >= %s)', None ), |
'ge': (2, 2, '(%s >= %s)', None ), |
442 |
'lt': (2, 2, '(%s < %s)', None ), |
'lt': (2, 2, '(%s < %s)', None ), |
443 |
'le': (2, 2, '(%s <= %s)', None ), |
'le': (2, 2, '(%s <= %s)', None ), |
444 |
'like': (2, 2, '(%s LIKE %s)', None ), |
'like': (2, 2, '%s LIKE %s', None ), |
445 |
'notlike': (2, 2, '(%s NOT LIKE %s)', None ), |
'notlike': (2, 2, '%s NOT LIKE %s', None ), |
446 |
'between': (3, 3, '(%s BETWEEN %s AND %s)', None ), |
'between': (3, 3, '%s BETWEEN %s AND %s', None ), |
447 |
'notbetween': (3, 3, '(%s NOT BETWEEN %s AND %s)', None ), |
'notbetween': (3, 3, '(%s NOT BETWEEN %s AND %s)', None ), |
448 |
# These two are hacks... these are not really valid tags |
# These two are hacks... these are not really valid tags |
449 |
# Used when the 2nd value of EQ or NE is NULL. |
# Used when the 2nd value of EQ or NE is NULL. |
450 |
# These are probably not necessary now that null and not null exist |
'__iseq': (2, 2, '(%s IS %s)', None ), |
451 |
'__iseq': (2, 2, '(%s IS %s)', None ), |
'__isne': (2, 2, '(%s IS NOT %s)', None )} |
452 |
'__isne': (2, 2, '(%s IS NOT %s)', None )} |
|
453 |
schema2nativeTypes={} |
schema2nativeTypes={} |
454 |
|
|
455 |
def __init__(self, strictQueryCount=1): |
def __init__(self, strictQueryCount=1): |
463 |
self._resultSetClass = DBSIG_ResultSet |
self._resultSetClass = DBSIG_ResultSet |
464 |
self._DatabaseError = None |
self._DatabaseError = None |
465 |
self._strictQueryCount = strictQueryCount |
self._strictQueryCount = strictQueryCount |
466 |
|
self._joinConditions = {} |
467 |
|
self._joinConditionsLoaded = None |
468 |
|
|
469 |
self.distinct = 0 |
self.distinct = 0 |
470 |
|
|
518 |
|
|
519 |
|
|
520 |
def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None,sql=""): |
def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None,sql=""): |
|
|
|
521 |
# Used by drivers with a unique id (like rowid) |
# Used by drivers with a unique id (like rowid) |
522 |
if not self._primaryIdChecked: self._checkForPrimaryId() |
if not self._primaryIdChecked: self._checkForPrimaryId() |
523 |
|
|
532 |
tableCount = string.count(self.table,',')+1 |
tableCount = string.count(self.table,',')+1 |
533 |
tables = string.split(string.replace(self.table,' ',''),',') |
tables = string.split(string.replace(self.table,' ',''),',') |
534 |
prefixedFields = None |
prefixedFields = None |
535 |
|
#print self._primaryKeys |
536 |
|
#print self._fieldReferences |
537 |
if self._primaryKeys and self._fieldReferences: |
if self._primaryKeys and self._fieldReferences: |
538 |
for table in self._primaryKeys.keys(): |
for table in self._primaryKeys.keys(): |
539 |
for field in self._primaryKeys[table]: |
for field in self._primaryKeys[table]: |
540 |
if not self._fieldReferences.has_key(table+"."+field) and not self._fieldReferences.has_key(field): |
if not self._fieldReferences.has_key(table+"."+field) and not self._fieldReferences.has_key(field): |
541 |
self._fieldReferences[table+"."+field] = "" |
self._fieldReferences[table+"."+field] = "" |
542 |
|
|
543 |
prefixedFields = self._fieldReferences.keys() |
prefixedFields = self._fieldReferences.keys() |
544 |
|
|
545 |
|
#print tableCount |
546 |
|
#print prefixedFields |
547 |
if tableCount > 1 and not prefixedFields: |
if tableCount > 1 and not prefixedFields: |
548 |
prefixedFields = [] |
prefixedFields = [] |
549 |
for iterTable in tables: |
for iterTable in tables: |
550 |
cursor.execute(self._buildQuery(conditions,iterTable)) |
cursor.execute(self._buildQuery(conditions,qTable=iterTable)) |
551 |
for iterDesc in (cursor.description): |
for iterDesc in (cursor.description): |
552 |
prefixedFields.append(iterTable+'.'+iterDesc[0]) |
mas = iterTable+'.'+iterDesc[0] |
553 |
|
prefixedFields.append(mas) |
554 |
|
|
555 |
cursor.execute(self._buildQuery(conditions,sql=sql)) |
cursor.execute(self._buildQuery(conditions,sql=sql)) |
556 |
|
|
557 |
except self._DatabaseError, err: |
except self._DatabaseError, err: |
558 |
raise GDataObjects.ConnectionError, err |
raise GDataObjects.ConnectionError, err |
559 |
|
|
560 |
|
#print "tableCount", tableCount |
561 |
|
#print "prefixedFields", prefixedFields |
562 |
if not prefixedFields: |
if not prefixedFields: |
563 |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet) |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet) |
564 |
else: |
else: |
617 |
_and = GConditions.GCand(cond) |
_and = GConditions.GCand(cond) |
618 |
_and._children = chillun |
_and._children = chillun |
619 |
|
|
|
self._joinConditionsLoaded = 1 |
|
620 |
where = " WHERE (%s)" % (self.__conditionToSQL (cond._children[0])) |
where = " WHERE (%s)" % (self.__conditionToSQL (cond._children[0])) |
621 |
|
self._joinConditionsLoaded = 1 |
622 |
GDebug.printMesg(5, where) |
GDebug.printMesg(5, where) |
623 |
return where |
return where |
624 |
|
|
672 |
result[1] == 'NULL': |
result[1] == 'NULL': |
673 |
otype = "__is%s" % otype |
otype = "__is%s" % otype |
674 |
if len(result) < self.conditionElements[otype][0]: |
if len(result) < self.conditionElements[otype][0]: |
675 |
raise GConditions.ConditionError, \ |
tmsg = _('Condition element "%s" expects at least %s arguments; found %s') % \ |
676 |
_('Condition element "%s" expects at least %s arguments; found %s') % \ |
(otype, self.conditionElements[otype][0], len(result)) |
677 |
(otype, self.conditionElements[otype][0], len(result)) |
raise GConditions.ConditionError, tmsg |
678 |
if len(result) > self.conditionElements[otype][1]: |
if len(result) > self.conditionElements[otype][1]: |
679 |
raise GConditions.ConditionError, \ |
tmsg = _('Condition element "%s" expects at most %s arguments; found %s') % \ |
|
_('Condition element "%s" expects at most %s arguments; found %s') % \ |
|
680 |
(otype, self.conditionElements[otype][0], len(result)) |
(otype, self.conditionElements[otype][0], len(result)) |
681 |
|
raise GConditions.ConditionError, tmsg |
682 |
|
|
683 |
if self.conditionElements[otype][3] == None: |
if self.conditionElements[otype][3] == None: |
684 |
return self.conditionElements[otype][2] % tuple(result) |
return self.conditionElements[otype][2] % tuple(result) |
686 |
return self.conditionElements[otype][2] % \ |
return self.conditionElements[otype][2] % \ |
687 |
(string.join(result, self.conditionElements[otype][3])) |
(string.join(result, self.conditionElements[otype][3])) |
688 |
else: |
else: |
689 |
raise GConditions.ConditionNotSupported, \ |
tmsg = _('Condition clause "%s" is not supported by this db driver.') % otype |
690 |
_('Condition clause "%s" is not supported by this db driver.') % otype |
raise GConditions.ConditionNotSupported, tmsg |
691 |
|
|
692 |
# Code necessary to force the connection into transaction mode... |
# Code necessary to force the connection into transaction mode... |
693 |
# this is usually not necessary (MySQL is one of few DBs that must force) |
# this is usually not necessary (MySQL is one of few DBs that must force) |
700 |
sql="%s %s" % (field.name, |
sql="%s %s" % (field.name, |
701 |
self.schema2nativeTypes[field.type]) |
self.schema2nativeTypes[field.type]) |
702 |
except: |
except: |
703 |
raise GDataObjects.DataTypeNotAvailable, \ |
tmsg = _("Datatype '%s' is not supported by database") |
704 |
"Datatype '%s' is not supported by database" |
raise GDataObjects.DataTypeNotAvailable, tmsg |
705 |
|
|
706 |
if hasattr(field,"size"): |
if hasattr(field,"size"): |
707 |
sql=sql+"(%s)" % field.size |
sql=sql+"(%s)" % field.size |
708 |
|
|
709 |
# if hasattr(field,"precision"): |
# if hasattr(field,"precision"): |
710 |
# if hasattr(field,"scale"): |
# if hasattr(field,"scale"): |
711 |
|
|
712 |
if not field.nullable: |
if not field.nullable: |
713 |
sql=sql+" NOT NULL" |
sql=sql+" NOT NULL" |
714 |
|
|
715 |
if hasattr(field,"default"): |
if hasattr(field,"default"): |
716 |
sql=sql+" DEFAULT %s" % self._toSqlString(field.default) |
sql=sql+" DEFAULT %s" % self._toSqlString(field.default) |
717 |
|
|
718 |
return sql |
return sql |
719 |
|
|
720 |
def _buildTableDefinition(self,tbl): |
def _buildTableDefinition(self,tbl): |
721 |
|
|
722 |
sql="CREATE TABLE %s (" % tbl.name |
sql="CREATE TABLE %s (" % tbl.name |
723 |
|
|
724 |
|
|
729 |
delim="" |
delim="" |
730 |
|
|
731 |
for field in fields._children: |
for field in fields._children: |
732 |
|
|
733 |
sql=sql+delim+"%s" % self._buildFieldDefinition(field) |
sql=sql+delim+"%s" % self._buildFieldDefinition(field) |
734 |
delim="," |
delim="," |
735 |
|
|
738 |
pk=tbl.findChildOfType("GSPrimaryKey") |
pk=tbl.findChildOfType("GSPrimaryKey") |
739 |
|
|
740 |
if (pk!=None) and len(pk._children): |
if (pk!=None) and len(pk._children): |
741 |
|
|
742 |
sql=sql+", primary key %s (" % pk.name |
sql=sql+", primary key %s (" % pk.name |
743 |
|
|
744 |
delim="" |
delim="" |
745 |
|
|
746 |
for pkfield in pk._children: |
for pkfield in pk._children: |
747 |
|
|
748 |
sql=sql+delim+pkfield.name |
sql=sql+delim+pkfield.name |
749 |
|
|
750 |
delim="," |
delim="," |
751 |
|
|
752 |
sql=sql+") " |
sql=sql+") " |
753 |
|
|
754 |
|
|
755 |
# close definition |
# close definition |
756 |
|
|
759 |
GDebug.printMesg(1,"SQL Statement: %s" % sql) |
GDebug.printMesg(1,"SQL Statement: %s" % sql) |
760 |
|
|
761 |
return sql |
return sql |
762 |
|
|
763 |
def writeTable(self,tbl,overwrite): |
def writeTable(self,tbl,overwrite): |
764 |
|
|
765 |
sql = self._buildTableDefinition(tbl) |
sql = self._buildTableDefinition(tbl) |
766 |
|
|
767 |
try: |
try: |
768 |
cursor = self._dataConnection.cursor() |
cursor = self._dataConnection.cursor() |
769 |
cursor.execute(sql) |
cursor.execute(sql) |
816 |
def _buildQuery(self, conditions={}, forDetail=None, additionalSQL="", qTable=None): |
def _buildQuery(self, conditions={}, forDetail=None, additionalSQL="", qTable=None): |
817 |
if not qTable: |
if not qTable: |
818 |
qTable = self.table |
qTable = self.table |
819 |
|
|
820 |
GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences) |
GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences) |
821 |
if self.distinct: |
if self.distinct: |
822 |
distinct = "distinct " |
distinct = "distinct " |
834 |
whereClause += ' and %s' % (additionalSQL) |
whereClause += ' and %s' % (additionalSQL) |
835 |
else: |
else: |
836 |
whereClause = ' WHERE %s' % (additionalSQL) |
whereClause = ' WHERE %s' % (additionalSQL) |
837 |
|
|
838 |
if forDetail: |
if forDetail: |
839 |
q = "%s in (SELECT %s FROM %s%s)" % \ |
q = "%s in (SELECT %s FROM %s%s)" % \ |
840 |
(string.join(self._masterfields,","), |
(string.join(self._masterfields,","), |
841 |
string.join(self._detailfields,","), |
string.join(self._detailfields,","), |
842 |
self.table, whereClause) |
qTable, whereClause) |
843 |
elif len(self._fieldReferences): |
elif len(self._fieldReferences): |
844 |
q = "SELECT %s%s%s FROM %s%s" % \ |
q = "SELECT %s%s%s FROM %s%s" % \ |
845 |
(distinct, pis, string.join(self._fieldReferences.keys(),","), self.table, |
(distinct, pis, string.join(self._fieldReferences.keys(),","), qTable, |
846 |
whereClause) |
whereClause) |
847 |
else: |
else: |
848 |
self._primaryIdSelect = None |
self._primaryIdSelect = None |
849 |
q = "SELECT %s* FROM %s%s" % (distinct, self.table, |
q = "SELECT %s* FROM %s%s" % (distinct, qTable, |
850 |
whereClause) |
whereClause) |
851 |
|
|
852 |
if hasattr(self,'order_by') and not forDetail: |
if hasattr(self,'order_by') and not forDetail: |
853 |
q = "%s ORDER BY %s " % (q, self.order_by) |
q = "%s ORDER BY %s " % (q, self.order_by) |
854 |
|
|
855 |
|
#print q |
856 |
GDebug.printMesg(5,q) |
GDebug.printMesg(5,q) |
|
|
|
857 |
return q |
return q |
858 |
|
|
859 |
def _buildQueryCount(self, conditions={}, additionalSQL=""): |
def _buildQueryCount(self, conditions={}, additionalSQL=""): |
885 |
'object': DBSIG_DataObject_Object, |
'object': DBSIG_DataObject_Object, |
886 |
'sql': DBSIG_DataObject_SQL |
'sql': DBSIG_DataObject_SQL |
887 |
} |
} |
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
|