65 |
self._toplevelParent = self._type # Needs to be set by subclass |
self._toplevelParent = self._type # Needs to be set by subclass |
66 |
# so that _topObject gets set |
# so that _topObject gets set |
67 |
self._topObject = None |
self._topObject = None |
68 |
|
self._datasourceDictionary={} |
69 |
|
|
70 |
# |
# |
71 |
# trigger support |
# trigger support |
76 |
'simpleQuery':{'function':self.triggerSimpleQuery, |
'simpleQuery':{'function':self.triggerSimpleQuery, |
77 |
}, |
}, |
78 |
'getRecords':{'function':self.getRecords}, |
'getRecords':{'function':self.getRecords}, |
79 |
|
'delete':{'function':self.deleteCurrentRecordsetEntry, |
80 |
|
'global':1, |
81 |
|
}, |
82 |
|
'call':{'function':self.callFuncOfCurrentRecordsetEntry, |
83 |
|
'global':1, |
84 |
|
}, |
85 |
|
'getCondition':{'function':self.getCondition}, |
86 |
|
'setCondition':{'function':self.setCondition}, |
87 |
'getCurrentRecord':{'function':self.getCurrentRecord}, |
'getCurrentRecord':{'function':self.getCurrentRecord}, |
88 |
'getTimeStamp':{'function':self.getTimeStamp}, |
'getTimeStamp':{'function':self.getTimeStamp}, |
89 |
} |
} |
109 |
def getCurrentRecord(self): |
def getCurrentRecord(self): |
110 |
return self.getCurrentResultSet().getCurrentRecord() |
return self.getCurrentResultSet().getCurrentRecord() |
111 |
|
|
112 |
|
def _buildObject(self): |
113 |
|
try: |
114 |
|
for field in string.split(self.explicitfields,','): |
115 |
|
self._fieldReferences[field] = 1 |
116 |
|
except AttributeError: |
117 |
|
pass |
118 |
|
try: |
119 |
|
# TODO: This **really** needs to be deprecated and |
120 |
|
# TODO: should be using <sorting> tags |
121 |
|
for field in string.split(self.order_by,','): |
122 |
|
if field[-5:].lower() == ' desc': |
123 |
|
field = field[:-5] |
124 |
|
self._fieldReferences[field] = 1 |
125 |
|
except AttributeError: |
126 |
|
pass |
127 |
|
return GObjects.GObj._buildObject(self) |
128 |
|
|
129 |
|
|
130 |
def getTimeStamp(self): |
def getTimeStamp(self): |
131 |
return self._dataObject.triggerExtensions.getTimeStamp() |
return self._dataObject.triggerExtensions.getTimeStamp() |
132 |
|
|
152 |
returnList.append(resultDict) |
returnList.append(resultDict) |
153 |
return returnList |
return returnList |
154 |
|
|
155 |
|
def deleteCurrentRecordsetEntry(self): |
156 |
|
self._currentResultSet.getPostingRecordset().delete() |
157 |
|
|
158 |
|
def callFuncOfCurrentRecordsetEntry(self,name,params): |
159 |
|
n=self._currentResultSet.getRecordNumber() |
160 |
|
rset=self._currentResultSet.getRecord(n) |
161 |
|
if hasattr(rset,'callFunc'): |
162 |
|
rset.callFunc(name,params) |
163 |
|
else: |
164 |
|
raise StandardError, \ |
165 |
|
_("Backend doesn't support the trigger 'call' function") |
166 |
|
|
167 |
# |
# |
168 |
|
# get/set the static condition assosiated with a datasource |
169 |
|
# the static condition is build out of the <condition> child |
170 |
|
# elements below a datasource XML definition |
171 |
|
# |
172 |
|
def setCondition(mycondition): |
173 |
|
dataObject._staticCondition = mycondition |
174 |
|
# dataObject.invalidateCachedConditions() |
175 |
|
|
176 |
|
def getCondition(): |
177 |
|
return dataObject._staticCondition |
178 |
|
|
179 |
|
# |
180 |
# This method should be called after the object is created |
# This method should be called after the object is created |
181 |
# but before any other methods are called |
# but before any other methods are called |
182 |
# |
# |
185 |
|
|
186 |
def initialize(self): |
def initialize(self): |
187 |
if not self.database: |
if not self.database: |
188 |
# We are a connectionless datasource (virtual?) |
# We are a connectionless datasource (virtual?) |
189 |
# We have to bind to something, so bind to empty driver |
# We have to bind to something, so bind to empty or static driver |
190 |
from gnue.common.dbdrivers._empty import DBdriver |
if not self.type=="static": |
191 |
GDebug.printMesg (7, 'Using empty data driver') |
from gnue.common.dbdrivers._empty import DBdriver |
192 |
dataObject = DBdriver.supportedDataObjects['object']() |
GDebug.printMesg (7, 'Using empty data driver') |
193 |
|
dataObject = DBdriver.supportedDataObjects['object']() |
194 |
|
|
195 |
|
else: |
196 |
|
from gnue.common.dbdrivers._static import DBdriver |
197 |
|
GDebug.printMesg (7, 'Using static data driver') |
198 |
|
dataObject = DBdriver.supportedDataObjects['static']() |
199 |
|
|
200 |
|
for child in self._children: |
201 |
|
if isinstance(child, GStaticSet): |
202 |
|
dataObject._staticSet = child |
203 |
|
break |
204 |
|
|
205 |
|
|
206 |
elif self._connections: |
elif self._connections: |
207 |
self.database = string.lower(self.database) |
self.database = string.lower(self.database) |
219 |
dataObject._unboundFieldReferences = self._unboundFieldReferences |
dataObject._unboundFieldReferences = self._unboundFieldReferences |
220 |
dataObject._defaultValues = self._defaultValues |
dataObject._defaultValues = self._defaultValues |
221 |
dataObject._dataSource = self |
dataObject._dataSource = self |
222 |
|
|
223 |
|
# TODO: Short-term hack to allow primary key support |
224 |
|
try: |
225 |
|
dataObject._primaryIdField = self.primarykey |
226 |
|
dataObject._primaryIdFormat = "%s = '%%s'" % self.primarykey |
227 |
|
dataObject._primaryIdChecked = 1 |
228 |
|
except AttributeError: |
229 |
|
pass |
230 |
|
|
231 |
for child in self._children: |
for child in self._children: |
232 |
if isinstance(child, GConditions.GCondition): |
if isinstance(child, GConditions.GCondition): |
233 |
dataObject._staticCondition = child |
dataObject._staticCondition = child |
245 |
pass |
pass |
246 |
self._dataObject = dataObject |
self._dataObject = dataObject |
247 |
|
|
248 |
|
|
249 |
def connect(self): |
def connect(self): |
250 |
if self.database != None: |
if self.database != None: |
251 |
self._connections.\ |
self._connections.\ |
276 |
def hasMaster(self): |
def hasMaster(self): |
277 |
return self._dataObject != None and self._dataObject.hasMaster() |
return self._dataObject != None and self._dataObject.hasMaster() |
278 |
|
|
279 |
def createResultSet(self, conditions={}, readOnly=0): |
def createResultSet(self, conditions={}, readOnly=0, sql=""): |
280 |
resultSet= self._dataObject.createResultSet(conditions,readOnly) |
resultSet= self._dataObject.createResultSet(conditions,readOnly,sql=sql) |
281 |
self.__setResultSet( resultSet ) |
self.__setResultSet( resultSet ) |
282 |
return resultSet |
return resultSet |
283 |
|
|
289 |
self.__setResultSet( resultSet ) |
self.__setResultSet( resultSet ) |
290 |
return resultSet |
return resultSet |
291 |
|
|
292 |
|
def getQueryString(self,conditions={},forDetailSQL=None,additionalSQL=""): |
293 |
|
return self._dataObject.getQueryString(conditions, forDetailSQL,additionalSQL) |
294 |
|
|
295 |
# |
# |
296 |
# Master/detail stuff |
# Master/detail stuff |
297 |
# |
# |
367 |
return 1 |
return 1 |
368 |
|
|
369 |
|
|
370 |
|
|
371 |
###### |
###### |
372 |
# |
# |
373 |
# |
# |
375 |
###### |
###### |
376 |
class GSql(GObjects.GObj): |
class GSql(GObjects.GObj): |
377 |
def __init__(self, parent=None): |
def __init__(self, parent=None): |
378 |
GObjects.GObj(self, parent, type="GDSql") |
GObjects.GObj.__init__(self, parent, type="GDSql") |
379 |
|
|
380 |
|
###### |
381 |
|
# |
382 |
|
# |
383 |
|
# |
384 |
|
###### |
385 |
|
class GStaticSet(GObjects.GObj): |
386 |
|
def __init__(self, parent=None): |
387 |
|
GObjects.GObj.__init__(self, parent, type="GDStaticSet") |
388 |
|
|
389 |
|
class GStaticSetRow(GObjects.GObj): |
390 |
|
def __init__(self, parent=None): |
391 |
|
GObjects.GObj.__init__(self, parent, type="GDStaticSetRow") |
392 |
|
|
393 |
|
class GStaticSetField(GObjects.GObj): |
394 |
|
def __init__(self, parent=None): |
395 |
|
GObjects.GObj.__init__(self, parent, type="GDStaticSetField") |
396 |
|
|
397 |
###### |
###### |
398 |
# |
# |
412 |
xmlElements = { |
xmlElements = { |
413 |
'datasource': { |
'datasource': { |
414 |
'BaseClass': GDataSource, |
'BaseClass': GDataSource, |
415 |
|
'Importable': 1, |
416 |
'Attributes': { |
'Attributes': { |
417 |
'name': { |
'name': { |
418 |
'Required': 1, |
'Required': 1, |
433 |
'prequery': { |
'prequery': { |
434 |
'Typecast': GTypecast.boolean, |
'Typecast': GTypecast.boolean, |
435 |
'Default': 0 }, |
'Default': 0 }, |
436 |
|
'distinct': { |
437 |
|
'Typecast': GTypecast.boolean, |
438 |
|
'Default': 0 }, |
439 |
'order_by': { |
'order_by': { |
440 |
'Typecast': GTypecast.text }, |
'Typecast': GTypecast.text }, |
441 |
'master': { |
'master': { |
443 |
'masterlink': { |
'masterlink': { |
444 |
'Typecast': GTypecast.text }, |
'Typecast': GTypecast.text }, |
445 |
'detaillink': { |
'detaillink': { |
446 |
|
'Typecast': GTypecast.text }, |
447 |
|
# TODO: Short-term hack |
448 |
|
'explicitfields': { |
449 |
|
'Typecast': GTypecast.text }, |
450 |
|
'primarykey': { |
451 |
'Typecast': GTypecast.text } }, |
'Typecast': GTypecast.text } }, |
452 |
'ParentTags': None }, |
'ParentTags': None }, |
453 |
|
'staticset': { |
454 |
|
'BaseClass': GStaticSet, |
455 |
|
# TODO: This should be replaced by a SingleInstanceInParentObject |
456 |
|
# instead of SingleInstance (in the whole file) |
457 |
|
# 'SingleInstance': 1, |
458 |
|
'Attributes': { |
459 |
|
'fields': { |
460 |
|
'Typecast': GTypecast.text, |
461 |
|
'Required': 1 } }, |
462 |
|
'ParentTags': ('datasource',) }, |
463 |
|
'staticsetrow': { |
464 |
|
'BaseClass': GStaticSetRow, |
465 |
|
'ParentTags': ('staticset',) }, |
466 |
|
'staticsetfield': { |
467 |
|
'BaseClass': GStaticSetField, |
468 |
|
'Attributes': { |
469 |
|
'name': { |
470 |
|
'Typecast': GTypecast.text, |
471 |
|
'Required': 1 }, |
472 |
|
'value': { |
473 |
|
'Typecast': GTypecast.text, |
474 |
|
'Required': 1 } }, |
475 |
|
'ParentTags': ('staticsetrow',) }, |
476 |
} |
} |
477 |
|
|
478 |
# Add conditional elements |
# Add conditional elements |
479 |
xmlElements.update( |
xmlElements.update( |
480 |
GConditions.getXMLelements( |
GConditions.getXMLelements( |
481 |
{'conditions':{'ParentTags':('datasource',) } } )) |
{'condition':{'ParentTags':('datasource',) } } )) |
482 |
|
|
483 |
for alteration in updates.keys(): |
for alteration in updates.keys(): |
484 |
xmlElements[alteration].update(updates[alteration]) |
xmlElements[alteration].update(updates[alteration]) |