dabo Commit
Revision 2614
Date: 2007-01-06 17:44:47 -0800 (Sat, 06 Jan 2007)
Author: Paul
Changed:
U branches/paul_sandbox/dabo/db/dBackend.py
U branches/paul_sandbox/dabo/db/dCursorMixin.py
U branches/paul_sandbox/dabo/db/dbSQLite.py
Log:
Fixed the problem with inconsistent values returned by the DataStructure
property with MySQL versus SQLite: turns out that getting rid of
getStructureDescription() and using getFields() works beautifully.
Diff:
Modified: branches/paul_sandbox/dabo/db/dBackend.py
===================================================================
--- branches/paul_sandbox/dabo/db/dBackend.py 2007-01-07 01:18:59 UTC (rev
2613)
+++ branches/paul_sandbox/dabo/db/dBackend.py 2007-01-07 01:44:47 UTC (rev
2614)
@@ -394,39 +394,6 @@
or (b[5] != s[5]) or (b[6] != s[6]) ]
- def getStructureDescription(self, cursor):
- """This will work for most backends. However, SQLite doesn't
- properly return the structure when no records are returned.
- """
- #Try using the no-records version of the SQL statement.
- try:
- tmpsql = cursor.getStructureOnlySql()
- except AttributeError:
- # We need to parse the sql property to get what we need.
- import re
- pat =
re.compile("(\s*select\s*.*\s*from\s*.*\s*)((?:where\s(.*))+)\s*", re.I | re.M
| re.S)
- if pat.search(cursor.sql):
- # There is a WHERE clause. Add the NODATA clause
- tmpsql = pat.sub("\\1 where 1=0 ", cursor.sql)
- else:
- # no WHERE clause. See if it has GROUP BY or
ORDER BY clauses
- pat =
re.compile("(\s*select\s*.*\s*from\s*.*\s*)((?:group\s*by\s(.*))+)\s*", re.I |
re.M | re.S)
- if pat.search(cursor.sql):
- tmpsql = pat.sub("\\1 where 1=0 ",
cursor.sql)
- else:
- pat =
re.compile("(\s*select\s*.*\s*from\s*.*\s*)((?:order\s*by\s(.*))+)\s*", re.I |
re.M | re.S)
- if pat.search(cursor.sql):
- tmpsql = pat.sub("\\1 where 1=0
", cursor.sql)
- else:
- # Nothing. So just tack it on
the end.
- tmpsql = cursor.sql + " where
1=0 "
- #print tmpsql
- auxCrs = cursor._getAuxCursor()
- auxCrs.execute(tmpsql)
- auxCrs.storeFieldTypes()
- return auxCrs.FieldDescription
-
-
########## Created by Echo ##############
def isExistingTable(self, table):
"""Returns whether or not the table exists."""
Modified: branches/paul_sandbox/dabo/db/dCursorMixin.py
===================================================================
--- branches/paul_sandbox/dabo/db/dCursorMixin.py 2007-01-07 01:18:59 UTC
(rev 2613)
+++ branches/paul_sandbox/dabo/db/dCursorMixin.py 2007-01-07 01:44:47 UTC
(rev 2614)
@@ -1880,7 +1880,7 @@
# Nothing we can do. We are probably an
AuxCursor
pass
else:
- ds =
self.BackendObject.getStructureDescription(self)
+ ds = self.getFields()
for field in ds:
field_name, field_type, pk =
field[0], field[1], field[2]
try:
Modified: branches/paul_sandbox/dabo/db/dbSQLite.py
===================================================================
--- branches/paul_sandbox/dabo/db/dbSQLite.py 2007-01-07 01:18:59 UTC (rev
2613)
+++ branches/paul_sandbox/dabo/db/dbSQLite.py 2007-01-07 01:44:47 UTC (rev
2614)
@@ -91,31 +91,8 @@
def getFields(self, tableName):
tempCursor = self._connection.cursor()
-# Get the name of the PK, if any
-# pkName = ""
-# try:
-# If any of these statements fail, there is no valid
-# PK defined for this table.
-# tempCursor.execute("""select * from sqlite_master
-# where tbl_name = '%s'""" %
tableName)
-# The SQL CREATE code is in position 4 of the tuple
-# tblSQL = tempCursor.fetchall()[0][4].lower()
-# Remove the CREATE...
-# parenPos = tblSQL.find("(")
-# tblSQL = tblSQL[parenPos+1:]
-# pkPos = tblSQL.find("primary key")
-# tblSQL = tblSQL[:pkPos]
-# The PK field name is the first word of the last
-# field def in that string
-# commaPos = tblSQL.find(",")
-# while commaPos > -1:
-# tblSQL = tblSQL[commaPos:]
-# commaPos = tblSQL.find(",")
-# pkName = tblSQL.strip().split(" ")[0]
-# except:
-# pass
- # Now get the field info
+ # Get the field info
tempCursor.execute("pragma table_info('%s')" % tableName)
rs = tempCursor.fetchall()
fields = []
@@ -174,46 +151,6 @@
pass
- def getStructureDescription(self, cursor):
- """ Return an empty cursor description. """
- ret = ()
- # First, get the SQL
- try:
- sql = cursor.sql
- except:
- sql = ""
- if sql:
- mtch = re.search("select\s(.+)\sfrom\s*.*", sql, re.I |
re.M | re.S)
- if mtch:
- fldDescrip = []
- fldText = mtch.groups()[0].replace("\n", " ")
- flds = fldText.split(",")
- for fld in flds:
- fldDescrip.append( (fld.split(" ")[-1],
"", False))
- ret = tuple(fldDescrip)
- if not ret:
- # Get the standard fields in the table
- auxCrs = cursor._getAuxCursor()
- auxCrs.execute("pragma table_info('%s')" % cursor.Table)
- rs = auxCrs._records
- fields = []
- for rec in rs:
- typ = rec["type"].lower()
- if typ == "integer":
- fldType = "I"
- elif typ == "real":
- fldType = "N"
- elif typ == "blob":
- fldType = "L"
- else:
- # SQLite treats everything else as text
- fldType = "C"
- pk = bool(rec["pk"])
- fields.append( (rec["name"], fldType, pk))
- ret = tuple(fields)
- return ret
-
-
def createTableAndIndexes(self, tabledef, cursor, createTable=True,
createIndexes=True):
if not tabledef.Name:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev