42 |
def _haveHistory(self, table=None): |
def _haveHistory(self, table=None): |
43 |
if not table: |
if not table: |
44 |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
|
#string.split(string.replace(self._parent._dataObject.table,' ',''),',') |
|
45 |
else: |
else: |
46 |
auxTable = map(lambda x: x.strip(), table.split(',')) |
auxTable = map(lambda x: x.strip(), table.split(',')) |
|
#string.split(string.replace(table,' ',''),',') |
|
47 |
for table in auxTable: |
for table in auxTable: |
48 |
if table.endswith('_data'): |
if table.endswith('_data'): |
49 |
return 1 |
return 1 |
52 |
def _postChanges(self,autoCommit=1): |
def _postChanges(self,autoCommit=1): |
53 |
if not self.isPending(): return |
if not self.isPending(): return |
54 |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
|
#string.split(string.replace(self._parent._dataObject.table,' ',''),',') |
|
55 |
|
|
56 |
if self._haveHistory(): |
if self._haveHistory(): |
57 |
return self._postChangesWHist(autoCommit) |
return self._postChangesWHist(autoCommit) |
109 |
|
|
110 |
def _postChangesWHist(self,autoCommit): |
def _postChangesWHist(self,autoCommit): |
111 |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
auxTable = map(lambda x: x.strip(), self._parent._dataObject.table.split(',')) |
|
#string.split(string.replace(self._parent._dataObject.table,' ',''),',') |
|
112 |
auxHTable = None |
auxHTable = None |
113 |
if hasattr(self._parent._dataObject,"historytable"): |
if hasattr(self._parent._dataObject,"historytable"): |
114 |
auxHTable =map(lambda x: x.strip(), self._parent._dataObject.historytable.split(',')) |
auxHTable =map(lambda x: x.strip(), self._parent._dataObject.historytable.split(',')) |
|
#string.split(string.replace(self._parent._dataObject.historytable,' ',''),',') |
|
115 |
statements = [] |
statements = [] |
116 |
try: |
try: |
117 |
if self._deleteFlag: |
if self._deleteFlag: |
535 |
|
|
536 |
|
|
537 |
def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None): |
def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None): |
538 |
|
|
539 |
# Used by drivers with a unique id (like rowid) |
# Used by drivers with a unique id (like rowid) |
540 |
if not self._primaryIdChecked: self._checkForPrimaryId() |
if not self._primaryIdChecked: self._checkForPrimaryId() |
541 |
|
|
549 |
cursor.arraysize = self.cache |
cursor.arraysize = self.cache |
550 |
tableCount = string.count(self.table,',')+1 |
tableCount = string.count(self.table,',')+1 |
551 |
tables = map(lambda x: x.strip(), self.table.split(',')) |
tables = map(lambda x: x.strip(), self.table.split(',')) |
552 |
#string.split(string.replace(self.table,' ',''),',') |
|
553 |
prefixedFields = None |
if not self._prefixedFields: |
554 |
if self._primaryKeys and self._fieldReferences: |
import gnue.common.GConditions as GConditions |
555 |
for table in self._primaryKeys.keys(): |
tmpCond = GConditions.GCondition() |
556 |
for field in self._primaryKeys[table]: |
ceq = GConditions.GCeq(tmpCond) |
557 |
if not self._fieldReferences.has_key(table+"."+field) and not self._fieldReferences.has_key(field): |
GConditions.GCConst(ceq,1,"number") |
558 |
self._fieldReferences[table+"."+field] = "" |
GConditions.GCConst(ceq,0,"number") |
559 |
|
if self._primaryKeys and self._fieldReferences: |
560 |
prefixedFields = self._fieldReferences.keys() |
for table in self._primaryKeys.keys(): |
561 |
|
for field in self._primaryKeys[table]: |
562 |
if tableCount > 1 and not prefixedFields: |
if not self._fieldReferences.has_key(table+"."+field) and not self._fieldReferences.has_key(field): |
563 |
prefixedFields = [] |
self._fieldReferences[table+"."+field] = "" |
564 |
for iterTable in tables: |
|
565 |
cursor.execute(self._buildQuery(conditions,iterTable)) |
self._prefixedFields = self._fieldReferences.keys() |
566 |
for iterDesc in (cursor.description): |
|
567 |
prefixedFields.append(iterTable+'.'+iterDesc[0]) |
if tableCount > 1: |
568 |
|
if not self._prefixedFields: |
569 |
|
self._prefixedFields = [] |
570 |
|
for iterTable in tables: |
571 |
|
cursor.execute(self._buildQuery(tmpCond,iterTable)) |
572 |
|
if iterTable.count(' as '): |
573 |
|
iterTable = map(lambda x: x.strip(), iterTable.split(' as '))[1] #Esto es por si tiene ej: "from entity as client" |
574 |
|
for iterDesc in (cursor.description): |
575 |
|
self._prefixedFields.append(iterTable+'.'+iterDesc[0]) |
576 |
|
|
577 |
#if masterRecordSet: |
#if masterRecordSet: |
578 |
# print self._conditionToSQL(conditions) |
# print self._conditionToSQL(conditions) |
579 |
cursor.execute(self._buildQuery(conditions)) |
cursor.execute(self._buildQuery(conditions)) |
580 |
|
|
581 |
|
|
582 |
except self._DatabaseError, err: |
except self._DatabaseError, err: |
583 |
raise GDataObjects.ConnectionError(str(err)) |
raise GDataObjects.ConnectionError(str(err)) |
584 |
|
|
585 |
if not prefixedFields: |
if not self._prefixedFields: |
586 |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet) |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet) |
587 |
else: |
else: |
588 |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet, fieldNames=prefixedFields) |
rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=masterRecordSet, fieldNames=self._prefixedFields) |
589 |
|
|
590 |
if self._strictQueryCount: |
if self._strictQueryCount: |
591 |
rs._recordCount = recordCount |
rs._recordCount = recordCount |
732 |
q = "SELECT %s FROM %s%s" % \ |
q = "SELECT %s FROM %s%s" % \ |
733 |
(string.join(self._fieldReferences.keys(),","), qTable, |
(string.join(self._fieldReferences.keys(),","), qTable, |
734 |
self._conditionToSQL(conditions)) |
self._conditionToSQL(conditions)) |
735 |
|
#if qTable.count(',') != 0: |
736 |
|
# print "q in buildQuery with fieldRef",q |
737 |
else: |
else: |
738 |
self._primaryIdSelect = None |
self._primaryIdSelect = None |
739 |
q = "SELECT * FROM %s%s" % (qTable, |
q = "SELECT * FROM %s%s" % (qTable, self._conditionToSQL(conditions)) |
740 |
self._conditionToSQL(conditions)) |
#if qTable.count(',') != 0: |
741 |
|
# print "q in buildQuery without fieldRef",q |
742 |
|
|
743 |
if hasattr(self,'order_by'): |
if hasattr(self,'order_by'): |
744 |
q = "%s ORDER BY %s " % (q, self.order_by) |
q = "%s ORDER BY %s " % (q, self.order_by) |