dabo Commit
Revision 3323
Date: 2007-08-22 18:07:43 -0700 (Wed, 22 Aug 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3323

Changed:
U   trunk/dabo/db/dBackend.py
U   trunk/dabo/db/dCursorMixin.py
U   trunk/dabo/db/dbFirebird.py
U   trunk/dabo/db/dbMsSQL.py
U   trunk/dabo/db/dbMySQL.py
U   trunk/dabo/db/dbOracle.py
U   trunk/dabo/db/dbPostgreSQL.py
U   trunk/dabo/db/dbSQLite.py

Log:
Revamped some of the routines that called for the backend object to create its 
own cursor. These now are called from dCursorMixin passing along the AuxCursor, 
so that there should be no discrepancy between the 'selected' database, as was 
reported by a few people. 

As I haven't run into this in my apps, the fact that all my apps are working OK 
with these changes doesn't reassure me very much, so please test these changes 
and let me know if a) the problem is fixed; b) if the problem remains; or c) if 
new problems are appearing.


Diff:
Modified: trunk/dabo/db/dBackend.py
===================================================================
--- trunk/dabo/db/dBackend.py   2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dBackend.py   2007-08-23 01:07:43 UTC (rev 3323)
@@ -38,6 +38,8 @@
                # True in the given db module to tell dCursorMixin not to 
bother. As of this
                # writing, only dbSQLite is set up for this.
                self._alreadyCorrectedFieldTypes = False
+               # Reference to the cursor that is using this object
+               self._cursor = None
 
 
        def isValidModule(self):
@@ -155,7 +157,7 @@
                        return None
 
 
-       def getTables(self, includeSystemTables=False):
+       def getTables(self, cursor, includeSystemTables=False):
                """ Return a tuple of the tables in the current database.
 
                Different backends will do this differently, so override in 
subclasses.
@@ -163,12 +165,12 @@
                return tuple()
 
 
-       def getTableRecordCount(self, tableName):
+       def getTableRecordCount(self, tableName, cursor):
                """ Return the number of records in the backend table."""
                return -1
 
 
-       def getFields(self, tableName):
+       def getFields(self, tableName, cursor):
                """ Return field information from the backend table.
 
                See dCursorMixin.getFields() for a description of the return 
value.
@@ -479,13 +481,14 @@
        ##########              Created by Echo         ##############
        def isExistingTable(self, table):
                """Returns whether or not the table exists."""
+               crs = self._cursor.AuxCursor
                if isinstance(table, dTable):
-                       return self._isExistingTable(table.name)
+                       return self._isExistingTable(table.name, crs)
                else:
-                       return self._isExistingTable(table)
+                       return self._isExistingTable(table, crs)
 
 
-       def _isExistingTable(self, tablename):
+       def _isExistingTable(self, tablename, cursor):
                # OVERRIDE IN SUBCLASSES!
                return False
 

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dCursorMixin.py       2007-08-23 01:07:43 UTC (rev 3323)
@@ -1654,12 +1654,12 @@
 
        def getTables(self, includeSystemTables=False):
                """ Return a tuple of tables in the current database."""
-               return self.BackendObject.getTables(includeSystemTables)
+               return self.BackendObject.getTables(self.AuxCursor, 
includeSystemTables)
 
 
        def getTableRecordCount(self, tableName):
                """ Get the number of records in the backend table."""
-               return self.BackendObject.getTableRecordCount(tableName)
+               return self.BackendObject.getTableRecordCount(tableName, 
self.AuxCursor)
 
 
        def getFields(self, tableName=None):
@@ -1673,7 +1673,7 @@
                if tableName is None:
                        # Use the default
                        tableName = self.Table
-               return self.BackendObject.getFields(tableName)
+               return self.BackendObject.getFields(tableName, self.AuxCursor)
 
 
        def getFieldInfoFromDescription(self):
@@ -2056,6 +2056,8 @@
 
        def _setBackendObject(self, obj):
                self.__backend = obj
+               if obj:
+                       obj._cursor = self
                if self.__auxCursor:
                        self.__auxCursor.__backend = obj
 

Modified: trunk/dabo/db/dbFirebird.py
===================================================================
--- trunk/dabo/db/dbFirebird.py 2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbFirebird.py 2007-08-23 01:07:43 UTC (rev 3323)
@@ -94,38 +94,35 @@
                return "%s%s%s" % (sqt, str(val), sqt)
 
 
-       def getTables(self, includeSystemTables=False):
+       def getTables(self, cursor, includeSystemTables=False):
                if includeSystemTables:
                        whereClause = ''
                else:
                        whereClause = "where rdb$relation_name not starting 
with 'RDB$' "
                        
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select rdb$relation_name from rdb$relations 
"
+               cursor.execute("select rdb$relation_name from rdb$relations "
                        "%s order by rdb$relation_name" % whereClause)
-               rs = tempCursor.fetchall()
+               rs = tempCursor.getDataSet()
                tables = []
                for record in rs:
                        tables.append(record[0].strip())
                return tuple(tables)
                
                
-       def getTableRecordCount(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from %s where 
1=1" % tableName)
-               return tempCursor.fetchall()[0][0]
+       def getTableRecordCount(self, tableName, cursor):
+               cursor.execute("select count(*) as ncount from %s where 1=1" % 
tableName)
+               return tempCursor.getDataSet()[0][0]
 
 
-       def getFields(self, tableName):
-               tempCursor = self._connection.cursor()
+       def getFields(self, tableName, cursor):
                # Get the PK
                sql = """ select inseg.rdb$field_name
                from rdb$indices idxs join rdb$index_segments inseg
                        on idxs.rdb$index_name = inseg.rdb$index_name
                        where idxs.rdb$relation_name = '%s'
        and idxs.rdb$unique_flag = 1 """ % tableName.upper()
-               tempCursor.execute(sql)
-               rs = tempCursor.fetchone()
+               cursor.execute(sql)
+               rs = cursor.getDataSet(rows=1)
                try:
                        pkField = rs[0].strip()
                except:
@@ -146,8 +143,8 @@
  AND a.RDB$RELATION_NAME = '%s'
  ORDER BY b.RDB$FIELD_ID """ % tableName.upper()
  
-               tempCursor.execute(sql)
-               rs = tempCursor.fetchall()
+               cursor.execute(sql)
+               rs = cursor.getDataSet()
                fields = []
                for r in rs:
                        name = r[0].strip()

Modified: trunk/dabo/db/dbMsSQL.py
===================================================================
--- trunk/dabo/db/dbMsSQL.py    2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbMsSQL.py    2007-08-23 01:07:43 UTC (rev 3323)
@@ -63,29 +63,27 @@
                return "%s%s%s" % (sqt, str(val), sqt)
        
        
-       def getTables(self, includeSystemTables=False):
-               tempCursor = self._connection.cursor()
+       def getTables(self, cursor, includeSystemTables=False):
                # jfcs 11/01/06 assumed public schema
                # cfk: this worries me: how does it know what db is being used?
                # tempCursor.execute("select name from sysobjects where xtype = 
'U' order by name")
                
                dbName = self.database
-               tempCursor.execute("select table_name"
+               cursor.execute("select table_name"
                        " from INFORMATION_SCHEMA.TABLES"
                        " where table_catalog = %(db)s"
                        " and table_type = 'BASE TABLE'"
                        " order by table_name",
                         {'db':dbName} )
-               rs = tempCursor.fetchall()
+               rs = cursor.getDataSet()
                tables = [x[0] for x in rs]
                tables = tuple(tables)
                return tables
 
        
-       def getTableRecordCount(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from 
'%(tablename)'" % tableName)
-               return tempCursor.fetchall()[0][0]
+       def getTableRecordCount(self, tableName, cursor):
+               cursor.execute("select count(*) as ncount from '%(tablename)'" 
% tableName)
+               return tempCursor.getDataSet()[0][0]
                
 
        def _fieldTypeNativeToDabo(self, nativeType):
@@ -150,26 +148,24 @@
                return ret
                
 
-       def getFields(self, tableName):
+       def getFields(self, tableName, cursor):
                """ Returns the list of fields of the passed table
-                       field: ( fieldname, dabo data type, key )
-                       """
-               tempCursor = self._connection.cursor()
+               field: ( fieldname, dabo data type, key )
+               """
                # fairly standard way of getting column settings
                # this may be standard enough to put in the super class
-
                dbName = self.database
                
-               tempCursor.execute(
+               cursor.execute(
                        "select COLUMN_NAME, DATA_TYPE" 
                        " from INFORMATION_SCHEMA.COLUMNS"
                        " where table_catalog = %(db)s"
                        " and table_name = %(table)s"
                        " order by ORDINAL_POSITION",
                         {'table':tableName, 'db':dbName} )
-               fieldDefs = tempCursor.fetchall()
+               fieldDefs = cursor.getDataSet()
 
-               tempCursor.execute(
+               cursor.execute(
                        "select COLUMN_NAME "
                        " from information_schema.Constraint_Column_Usage CCU"
                        " join information_schema.TABLE_CONSTRAINTS TC"
@@ -179,7 +175,7 @@
                        " and TC.CONSTRAINT_CATALOG = %(db)s" 
                        " and TC.Table_Name = %(table)s",
                         {'table':tableName, 'db':dbName} )
-               pkFields = tempCursor.fetchall()
+               pkFields = cursor.getDataSet()
 
                fields = []
                for r in fieldDefs:

Modified: trunk/dabo/db/dbMySQL.py
===================================================================
--- trunk/dabo/db/dbMySQL.py    2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbMySQL.py    2007-08-23 01:07:43 UTC (rev 3323)
@@ -94,39 +94,35 @@
                return "%s%s%s" % (sqt, str(val), sqt)
        
        
-       def _isExistingTable(self, tablename):
-               tempCursor = self._connection.cursor()
+       def _isExistingTable(self, tablename, cursor):
                tbl = self.encloseNames(self.escQuote(tablename))
-               tempCursor.execute("SHOW TABLES LIKE %s" % tbl)
-               rs = tempCursor.fetchall()
+               cursor.execute("SHOW TABLES LIKE %s" % tbl)
+               rs = tempCursor.getDataSet()
                return bool(rs)
                        
        
-       def getTables(self, includeSystemTables=False):
+       def getTables(self, cursor, includeSystemTables=False):
                # MySQL doesn't have system tables, in the traditional sense, 
as 
                # they exist in the mysql database.
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("show tables")
-               rs = tempCursor.fetchall()
+               cursor.execute("show tables")
+               rs = tempCursor.getDataSet()
                tables = []
                for record in rs:
                        tables.append(record[0])
                return tuple(tables)
                
                
-       def getTableRecordCount(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from %s" % 
self.encloseNames(tableName))
-               return tempCursor.fetchall()[0][0]
+       def getTableRecordCount(self, tableName, cursor):
+               cursor.execute("select count(*) as ncount from %s" % 
self.encloseNames(tableName))
+               return tempCursor.getDataSet()[0][0]
 
 
-       def getFields(self, tableName):
+       def getFields(self, tableName, cursor):
                if not tableName:
                        return tuple()
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("describe %s" % self.encloseNames(tableName))
-               rs = tempCursor.fetchall()
-               fldDesc = tempCursor.description
+               cursor.execute("describe %s" % self.encloseNames(tableName))
+               rs = cursor.getDataSet()
+               fldDesc = cursor.description
                # The field name is the first element of the tuple. Find the
                # first entry with the field name 'Key'; that will be the 
                # position for the PK flag

Modified: trunk/dabo/db/dbOracle.py
===================================================================
--- trunk/dabo/db/dbOracle.py   2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbOracle.py   2007-08-23 01:07:43 UTC (rev 3323)
@@ -74,31 +74,28 @@
                return "%s%s%s" % (sqt, str(val), sqt)
 
                
-       def getTables(self, includeSystemTables=False):
+       def getTables(self, cursor, includeSystemTables=False):
                #### TODO: Verify that this works with NEWDATABASE, including
                ####    the option for including/excluding system tables.
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("show tables")
-               rs = tempCursor.fetchall()
+               cursor.execute("show tables")
+               rs = cursor.getDataSet()
                tables = []
                for record in rs:
                        tables.append(record[0])
                return tuple(tables)
 
                
-       def getTableRecordCount(self, tableName):
+       def getTableRecordCount(self, tableName, cursor):
                #### TODO: Verify that this is the correct syntax for 
NEWDATABASE
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from %s" % 
tableName)
-               return tempCursor.fetchall()[0][0]
+               cursor.execute("select count(*) as ncount from %s" % tableName)
+               return cursor.getDataSet()[0][0]
 
 
-       def getFields(self, tableName):
-               tempCursor = self._connection.cursor()
+       def getFields(self, tableName, cursor):
                #### TODO: Modify for NEWDATABASE syntax
-               tempCursor.execute("describe %s" % tableName)
-               rs = tempCursor.fetchall()
-               fldDesc = tempCursor.description
+               cursor.execute("describe %s" % tableName)
+               rs = cursor.getDataSet()
+               fldDesc = cursor.description
                # The field name is the first element of the tuple. Find the
                # first entry with the field name 'Key'; that will be the 
                # position for the PK flag

Modified: trunk/dabo/db/dbPostgreSQL.py
===================================================================
--- trunk/dabo/db/dbPostgreSQL.py       2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbPostgreSQL.py       2007-08-23 01:07:43 UTC (rev 3323)
@@ -58,8 +58,7 @@
                return "%s%s%s" % (sqt, str(val), sqt)
        
        
-       def getTables(self, includeSystemTables=False):
-               tempCursor = self._connection.cursor()
+       def getTables(self, cursor, includeSystemTables=False):
                # jfcs 11/01/04 assumed public schema
                #tempCursor.execute("select tablename from pg_tables where 
schemaname = 'public'")
                # jfcs 01/22/07 added below to support schema 
@@ -70,24 +69,20 @@
                else:
                        sqltablestr = (("SELECT schemaname || '.' || tablename 
AS tablename FROM pg_tables WHERE (schemaname not like 'pg_%s' and schemaname 
not like 'information%s') and has_table_privilege('%s', schemaname || '.' || 
tablename, 'SELECT')") % ('%','%',self.conn_user))
                                                
-               tempCursor.execute(sqltablestr)
-               rs = tempCursor.fetchall()
-               
-               
+               cursor.execute(sqltablestr)
+               rs = cursor.getDataSet()
                tables = []
                for record in rs:
                        tables.append(record[0])
                return tuple(tables)
 
        
-       def getTableRecordCount(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from %s" % 
tableName)
-               return tempCursor.fetchall()[0][0]
+       def getTableRecordCount(self, tableName, cursor):
+               cursor.execute("select count(*) as ncount from %s" % tableName)
+               return cursor.getDataSet()[0][0]
 
 
-       def getFields(self, tableName):
-               tempCursor = self._connection.cursor()
+       def getFields(self, tableName, cursor):
                tableNameBreak=tableName.split('.',1)
                localSchemaName = tableNameBreak[0]
                localTableName = tableNameBreak[1]
@@ -117,15 +112,14 @@
                                #on a.attrelid = c.oid inner join pg_type t on 
a.atttypid = t.oid 
                                #where c.relname = '%s' and a.attnum > 0 """ % 
tableName)
                # JFCS 01/22/07 Added support for schema 
-               tempCursor.execute("""select c.oid,a.attname, t.typname, 
b.schemaname from pg_class c 
+               cursor.execute("""select c.oid,a.attname, t.typname, 
b.schemaname from pg_class c 
 inner join pg_attribute a on a.attrelid = c.oid 
 inner join pg_type t on a.atttypid = t.oid 
 inner join pg_tables b on b.tablename=c.relname
 where (b.schemaname || '.'|| c.relname)  = '%s' and a.attnum > 0 """ % 
tableName)
-               rs = tempCursor.fetchall()
+               rs = cursor.getDataSet()
 
                ## get the PK the code should work well with 7.4 - 8.2 versions
-               
                sqlstr = """SELECT n.nspname AS schema_name, c.relname AS 
table_name,
            c.oid AS table_oid, a.attname AS column_name, idx.n + 1 AS 
ordinal_position
       FROM pg_class c, pg_attribute a, pg_index i, pg_namespace n, 
generate_series(0, 31) idx(n)
@@ -136,9 +130,9 @@
        AND has_table_privilege(c.oid, 'SELECT'::text)
        AND c.relnamespace = n.oid and c.relname = '%s' and n.nspname = '%s' 
""" % ('%',localTableName,localSchemaName)
                
-               tempCursor.execute(sqlstr)
-               rs2=tempCursor.fetchall()
-               if rs2==[]:
+               cursor.execute(sqlstr)
+               rs2 = cursor.getDataSet()
+               if rs2 == []:
                        thePKFieldName = None
                else:
                        #thestr = rs2[0][3]
@@ -249,7 +243,7 @@
                localSchemaName = tableNameBreak[0]
                localTableName = tableNameBreak[1]
                
-               tempCursor = self._connection.cursor()
+               tempCursor = self._cursor.AuxCursor
                sqltablestr = """SELECT seq.relname::text
                FROM pg_class src, pg_class seq, pg_namespace, pg_attribute,
                pg_depend

Modified: trunk/dabo/db/dbSQLite.py
===================================================================
--- trunk/dabo/db/dbSQLite.py   2007-08-22 18:43:28 UTC (rev 3322)
+++ trunk/dabo/db/dbSQLite.py   2007-08-23 01:07:43 UTC (rev 3323)
@@ -112,17 +112,15 @@
                return "%s%s%s" % (sqt, val, sqt)
                
        
-       def _isExistingTable(self, tablename):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("SELECT name FROM sqlite_master WHERE 
type='table' AND name=%s" % self.escQuote(tablename))
-               rs = tempCursor.fetchall()
+       def _isExistingTable(self, tablename, cursor):
+               cursor.execute("SELECT name FROM sqlite_master WHERE 
type='table' AND name=%s" % self.escQuote(tablename))
+               rs = cursor.getDataSet()
                return len(rs) > 0
        
        
-       def getTables(self, includeSystemTables=False):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select * from sqlite_master")
-               rs = tempCursor.fetchall()
+       def getTables(self, cursor, includeSystemTables=False):
+               cursor.execute("select * from sqlite_master")
+               rs = cursor.getDataSet()
                if includeSystemTables:
                        tables = [rec["name"] for rec in rs 
                                        if rec["type"] == "table"]
@@ -133,16 +131,14 @@
                return tuple(tables)
                
                
-       def getTableRecordCount(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("select count(*) as ncount from %s" % 
tableName)
-               return tempCursor.fetchall()[0]["ncount"]
+       def getTableRecordCount(self, tableName, cursor):
+               cursor.execute("select count(*) as ncount from %s" % tableName)
+               return cursor.getDataSet(rows=1)["ncount"]
 
 
-       def getFields(self, tableName):
-               tempCursor = self._connection.cursor()
-               tempCursor.execute("pragma table_info('%s')" % tableName)
-               rs = tempCursor.fetchall()
+       def getFields(self, tableName, cursor):
+               cursor.execute("pragma table_info('%s')" % tableName)
+               rs = cursor.getDataSet()
                fields = []
                for rec in rs:
                        typ = rec["type"].lower()




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to