55 |
|
|
56 |
|
|
57 |
class Gadfly_ResultSet(DBSIG_ResultSet): |
class Gadfly_ResultSet(DBSIG_ResultSet): |
58 |
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None): |
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None): |
59 |
|
cursor.rowcount=0 |
60 |
DBSIG_ResultSet.__init__(self, dataObject, \ |
DBSIG_ResultSet.__init__(self, dataObject, \ |
61 |
cursor, defaultValues, masterRecordSet) |
cursor, defaultValues, masterRecordSet) |
62 |
self._recordSetClass = Gadfly_RecordSet |
self._recordSetClass = Gadfly_RecordSet |
63 |
|
|
64 |
def _loadNextRecord(self): |
def _loadNextRecord(self): |
65 |
if self._cursor: |
if self._cursor: |
66 |
rs = None |
rs = None |
110 |
##### END EVIL HACK |
##### END EVIL HACK |
111 |
|
|
112 |
class Gadfly_DataObject(DBSIG_DataObject): |
class Gadfly_DataObject(DBSIG_DataObject): |
113 |
|
|
114 |
|
|
115 |
def __init__(self): |
def __init__(self): |
116 |
DBSIG_DataObject.__init__(self) |
DBSIG_DataObject.__init__(self) |
117 |
self._DatabaseError = DatabaseError |
self._DatabaseError = Error |
118 |
self._resultSetClass = Gadfly_ResultSet |
self._resultSetClass = Gadfly_ResultSet |
119 |
|
|
120 |
|
# LIKE is not supported on database level at the moment |
121 |
|
# there should be used other ways to emulate it |
122 |
|
# until that works, do a = instead of a like |
123 |
|
# EVIL HACK |
124 |
|
self.conditionElements.update({\ |
125 |
|
'like': (2, 2, '%s = %s', None ),\ |
126 |
|
'notlike': (2, 2, 'NOT (%s = %s)', None )}) |
127 |
|
# END EVIL HACK |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
def connect(self, connectData={}): |
def connect(self, connectData={}): |
132 |
GDebug.printMesg(1,"Gadfly database driver initializing") |
GDebug.printMesg(1,"Gadfly database driver initializing") |
154 |
|
|
155 |
# This should be over-ridden only if driver needs more than user/pass |
# This should be over-ridden only if driver needs more than user/pass |
156 |
def getLoginFields(self): |
def getLoginFields(self): |
157 |
return [['_username', 'User Name',0],['_password', 'Password',1]] |
return [] |
158 |
|
|
159 |
# |
# |
160 |
# Schema (metadata) functions |
# Schema (metadata) functions |
162 |
|
|
163 |
# Return a list of the types of Schema objects this driver provides |
# Return a list of the types of Schema objects this driver provides |
164 |
def getSchemaTypes(self): |
def getSchemaTypes(self): |
165 |
return [('table','Table',1)] |
return [('view','View',1), ('table','Table',1)] |
166 |
|
|
167 |
# Return a list of Schema objects |
# Return a list of Schema objects |
168 |
def getSchemaList(self, type=None): |
def getSchemaList(self, type=None): |
169 |
|
|
|
# TODO: This excludes any system tables and views. Should it? |
|
170 |
statement = "select * from __table_names__" |
statement = "select * from __table_names__" |
171 |
|
|
172 |
cursor = self._dataConnection.cursor() |
cursor = self._dataConnection.cursor() |
173 |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
174 |
cursor.execute(statement) |
cursor.execute(statement) |
175 |
|
|
176 |
list = [] |
list = [] |
177 |
for rs in cursor.fetchall(): |
for rs in cursor.fetchall(): |
178 |
list.append(GDataObjects.Schema(attrs={'id':rs[1], 'name':rs[1], |
# exclude any system tables and views. f.e. __table_names__ |
179 |
'type':'table'}, |
if rs[1][:2]!="__": |
180 |
getChildSchema=self.__getFieldSchema)) |
list.append(GDataObjects.Schema(attrs={'id':rs[1], 'name':rs[1], \ |
181 |
|
'type':rs[0] == 1 and 'view' or 'table',}, |
182 |
|
getChildSchema=self.__getFieldSchema)) |
183 |
|
|
184 |
cursor.close() |
cursor.close() |
185 |
return list |
return list |
187 |
|
|
188 |
# Find a schema object with specified name |
# Find a schema object with specified name |
189 |
def getSchemaByName(self, name, type=None): |
def getSchemaByName(self, name, type=None): |
190 |
statement = "SELECT '%s' from __table_names__" % (name) |
statement = "SELECT * from __table_names__ WHERE TABLE_NAME='%s'" % (name) |
191 |
|
|
192 |
cursor = self._dataConnection.cursor() |
cursor = self._dataConnection.cursor() |
193 |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
195 |
|
|
196 |
rs = cursor.fetchone() |
rs = cursor.fetchone() |
197 |
if rs: |
if rs: |
198 |
schema = GDataObjects.Schema(attrs={'id':name, 'name':name, |
schema = GDataObjects.Schema(attrs={'id':rs[1], 'name':rs[1], \ |
199 |
'type':'table'}, |
'type':rs[0] == 1 and 'view' or 'table',}, |
200 |
getChildSchema=self.__getFieldSchema) |
getChildSchema=self.__getFieldSchema) |
201 |
else: |
else: |
202 |
schema = None |
schema = None |
203 |
|
|
208 |
# Get fields for a table |
# Get fields for a table |
209 |
def __getFieldSchema(self, parent): |
def __getFieldSchema(self, parent): |
210 |
|
|
211 |
|
# TODO: Read whole definitions from __DATADEFS__ and parse them |
212 |
|
# to distinguish between varchar, float and integer |
213 |
|
|
214 |
statement = "SELECT * FROM __COLUMNS__ WHERE TABLE_NAME='%s'" % parent.id |
statement = "SELECT * FROM __COLUMNS__ WHERE TABLE_NAME='%s'" % parent.id |
|
#statement = "SELECT * FROM %s" % parent.id |
|
215 |
|
|
216 |
cursor = self._dataConnection.cursor() |
cursor = self._dataConnection.cursor() |
217 |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
GDebug.printMesg(1,"** Executing: %s **" % statement) |
225 |
|
|
226 |
|
|
227 |
attrs={'id': "%s.%s" % (parent.id, rs[0]), 'name': rs[0], |
attrs={'id': "%s.%s" % (parent.id, rs[0]), 'name': rs[0], |
228 |
'type':'field'}#, 'nativetype': nativetype[0], |
'type':'field', 'nativetype': 'varchar', |
229 |
#'required': rs[2] != 'YES'} |
'required': 0} |
230 |
|
|
231 |
#if nativetype[0] in ('int','integer','bigint','mediumint', |
#if nativetype[0] in ('int','integer','bigint','mediumint', |
232 |
# 'smallint','tinyint','float','real', |
# 'smallint','tinyint','float','real', |
264 |
def _buildQuery(self, conditions={}): |
def _buildQuery(self, conditions={}): |
265 |
return DBSIG_DataObject_Object._buildQuery(self, conditions) |
return DBSIG_DataObject_Object._buildQuery(self, conditions) |
266 |
|
|
267 |
|
def _getQueryCount(self,conditions={}): |
268 |
|
cursor = self._dataConnection.cursor() |
269 |
|
|
270 |
|
cursor.execute(self._buildQueryCount(conditions)) |
271 |
|
# GADFLY throws an error if executing COUNT(*) on an empty set |
272 |
|
try: |
273 |
|
rs = cursor.fetchone() |
274 |
|
return int(rs[0]) |
275 |
|
except: |
276 |
|
return 0 |
277 |
|
|
278 |
|
def _buildQueryCount(self, conditions={}): |
279 |
|
# GADFLY seems to hate big letter "SELECT" |
280 |
|
q = "select count(*) from %s%s" % (self.table, self._conditionToSQL(conditions)) |
281 |
|
|
282 |
|
GDebug.printMesg(5,q) |
283 |
|
|
284 |
|
return q |
285 |
|
|
286 |
class Gadfly_DataObject_SQL(Gadfly_DataObject, \ |
class Gadfly_DataObject_SQL(Gadfly_DataObject, \ |
287 |
DBSIG_DataObject_SQL): |
DBSIG_DataObject_SQL): |
295 |
return DBSIG_DataObject_SQL._buildQuery(self, conditions) |
return DBSIG_DataObject_SQL._buildQuery(self, conditions) |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
# |
# |
300 |
# Extensions to Trigger Namespaces |
# Extensions to Trigger Namespaces |
301 |
# |
# |