Changeset 3323

Show
Ignore:
Timestamp:
08/22/07 18:07:43 (1 year ago)
Author:
ed
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/db/dBackend.py

    r3314 r3323  
    3939        # writing, only dbSQLite is set up for this. 
    4040        self._alreadyCorrectedFieldTypes = False 
     41        # Reference to the cursor that is using this object 
     42        self._cursor = None 
    4143 
    4244 
     
    156158 
    157159 
    158     def getTables(self, includeSystemTables=False): 
     160    def getTables(self, cursor, includeSystemTables=False): 
    159161        """ Return a tuple of the tables in the current database. 
    160162 
     
    164166 
    165167 
    166     def getTableRecordCount(self, tableName): 
     168    def getTableRecordCount(self, tableName, cursor): 
    167169        """ Return the number of records in the backend table.""" 
    168170        return -1 
    169171 
    170172 
    171     def getFields(self, tableName): 
     173    def getFields(self, tableName, cursor): 
    172174        """ Return field information from the backend table. 
    173175 
     
    480482    def isExistingTable(self, table): 
    481483        """Returns whether or not the table exists.""" 
     484        crs = self._cursor.AuxCursor 
    482485        if isinstance(table, dTable): 
    483             return self._isExistingTable(table.name
     486            return self._isExistingTable(table.name, crs
    484487        else: 
    485             return self._isExistingTable(table
    486  
    487  
    488     def _isExistingTable(self, tablename): 
     488            return self._isExistingTable(table, crs
     489 
     490 
     491    def _isExistingTable(self, tablename, cursor): 
    489492        # OVERRIDE IN SUBCLASSES! 
    490493        return False 
  • trunk/dabo/db/dCursorMixin.py

    r3322 r3323  
    16551655    def getTables(self, includeSystemTables=False): 
    16561656        """ Return a tuple of tables in the current database.""" 
    1657         return self.BackendObject.getTables(includeSystemTables) 
     1657        return self.BackendObject.getTables(self.AuxCursor, includeSystemTables) 
    16581658 
    16591659 
    16601660    def getTableRecordCount(self, tableName): 
    16611661        """ Get the number of records in the backend table.""" 
    1662         return self.BackendObject.getTableRecordCount(tableName
     1662        return self.BackendObject.getTableRecordCount(tableName, self.AuxCursor
    16631663 
    16641664 
     
    16741674            # Use the default 
    16751675            tableName = self.Table 
    1676         return self.BackendObject.getFields(tableName
     1676        return self.BackendObject.getFields(tableName, self.AuxCursor
    16771677 
    16781678 
     
    20572057    def _setBackendObject(self, obj): 
    20582058        self.__backend = obj 
     2059        if obj: 
     2060            obj._cursor = self 
    20592061        if self.__auxCursor: 
    20602062            self.__auxCursor.__backend = obj 
  • trunk/dabo/db/dbFirebird.py

    r3314 r3323  
    9595 
    9696 
    97     def getTables(self, includeSystemTables=False): 
     97    def getTables(self, cursor, includeSystemTables=False): 
    9898        if includeSystemTables: 
    9999            whereClause = '' 
     
    101101            whereClause = "where rdb$relation_name not starting with 'RDB$' " 
    102102             
    103         tempCursor = self._connection.cursor() 
    104         tempCursor.execute("select rdb$relation_name from rdb$relations " 
     103        cursor.execute("select rdb$relation_name from rdb$relations " 
    105104            "%s order by rdb$relation_name" % whereClause) 
    106         rs = tempCursor.fetchall() 
     105        rs = tempCursor.getDataSet() 
    107106        tables = [] 
    108107        for record in rs: 
     
    111110         
    112111         
    113     def getTableRecordCount(self, tableName): 
    114         tempCursor = self._connection.cursor() 
    115         tempCursor.execute("select count(*) as ncount from %s where 1=1" % tableName) 
    116         return tempCursor.fetchall()[0][0] 
    117  
    118  
    119     def getFields(self, tableName): 
    120         tempCursor = self._connection.cursor() 
     112    def getTableRecordCount(self, tableName, cursor): 
     113        cursor.execute("select count(*) as ncount from %s where 1=1" % tableName) 
     114        return tempCursor.getDataSet()[0][0] 
     115 
     116 
     117    def getFields(self, tableName, cursor): 
    121118        # Get the PK 
    122119        sql = """ select inseg.rdb$field_name 
     
    125122            where idxs.rdb$relation_name = '%s' 
    126123    and idxs.rdb$unique_flag = 1 """ % tableName.upper() 
    127         tempCursor.execute(sql) 
    128         rs = tempCursor.fetchone(
     124        cursor.execute(sql) 
     125        rs = cursor.getDataSet(rows=1
    129126        try: 
    130127            pkField = rs[0].strip() 
     
    147144 ORDER BY b.RDB$FIELD_ID """ % tableName.upper() 
    148145  
    149         tempCursor.execute(sql) 
    150         rs = tempCursor.fetchall() 
     146        cursor.execute(sql) 
     147        rs = cursor.getDataSet() 
    151148        fields = [] 
    152149        for r in rs: 
  • trunk/dabo/db/dbMsSQL.py

    r3303 r3323  
    6464     
    6565     
    66     def getTables(self, includeSystemTables=False): 
    67         tempCursor = self._connection.cursor() 
     66    def getTables(self, cursor, includeSystemTables=False): 
    6867        # jfcs 11/01/06 assumed public schema 
    6968        # cfk: this worries me: how does it know what db is being used? 
     
    7170         
    7271        dbName = self.database 
    73         tempCursor.execute("select table_name" 
     72        cursor.execute("select table_name" 
    7473            " from INFORMATION_SCHEMA.TABLES" 
    7574            " where table_catalog = %(db)s" 
     
    7776            " order by table_name", 
    7877             {'db':dbName} ) 
    79         rs = tempCursor.fetchall() 
     78        rs = cursor.getDataSet() 
    8079        tables = [x[0] for x in rs] 
    8180        tables = tuple(tables) 
     
    8382 
    8483     
    85     def getTableRecordCount(self, tableName): 
    86         tempCursor = self._connection.cursor() 
    87         tempCursor.execute("select count(*) as ncount from '%(tablename)'" % tableName) 
    88         return tempCursor.fetchall()[0][0] 
     84    def getTableRecordCount(self, tableName, cursor): 
     85        cursor.execute("select count(*) as ncount from '%(tablename)'" % tableName) 
     86        return tempCursor.getDataSet()[0][0] 
    8987         
    9088 
     
    151149         
    152150 
    153     def getFields(self, tableName): 
     151    def getFields(self, tableName, cursor): 
    154152        """ Returns the list of fields of the passed table 
    155             field: ( fieldname, dabo data type, key ) 
    156             """ 
    157         tempCursor = self._connection.cursor() 
     153        field: ( fieldname, dabo data type, key ) 
     154        """ 
    158155        # fairly standard way of getting column settings 
    159156        # this may be standard enough to put in the super class 
    160  
    161157        dbName = self.database 
    162158         
    163         tempCursor.execute( 
     159        cursor.execute( 
    164160            "select COLUMN_NAME, DATA_TYPE"  
    165161            " from INFORMATION_SCHEMA.COLUMNS" 
     
    168164            " order by ORDINAL_POSITION", 
    169165             {'table':tableName, 'db':dbName} ) 
    170         fieldDefs = tempCursor.fetchall() 
    171  
    172         tempCursor.execute( 
     166        fieldDefs = cursor.getDataSet() 
     167 
     168        cursor.execute( 
    173169            "select COLUMN_NAME " 
    174170            " from information_schema.Constraint_Column_Usage CCU" 
     
    180176            " and TC.Table_Name = %(table)s", 
    181177             {'table':tableName, 'db':dbName} ) 
    182         pkFields = tempCursor.fetchall() 
     178        pkFields = cursor.getDataSet() 
    183179 
    184180        fields = [] 
  • trunk/dabo/db/dbMySQL.py

    r3314 r3323  
    9595     
    9696     
    97     def _isExistingTable(self, tablename): 
    98         tempCursor = self._connection.cursor() 
     97    def _isExistingTable(self, tablename, cursor): 
    9998        tbl = self.encloseNames(self.escQuote(tablename)) 
    100         tempCursor.execute("SHOW TABLES LIKE %s" % tbl) 
    101         rs = tempCursor.fetchall() 
     99        cursor.execute("SHOW TABLES LIKE %s" % tbl) 
     100        rs = tempCursor.getDataSet() 
    102101        return bool(rs) 
    103102             
    104103     
    105     def getTables(self, includeSystemTables=False): 
     104    def getTables(self, cursor, includeSystemTables=False): 
    106105        # MySQL doesn't have system tables, in the traditional sense, as  
    107106        # they exist in the mysql database. 
    108         tempCursor = self._connection.cursor() 
    109         tempCursor.execute("show tables") 
    110         rs = tempCursor.fetchall() 
     107        cursor.execute("show tables") 
     108        rs = tempCursor.getDataSet() 
    111109        tables = [] 
    112110        for record in rs: 
     
    115113         
    116114         
    117     def getTableRecordCount(self, tableName): 
    118         tempCursor = self._connection.cursor() 
    119         tempCursor.execute("select count(*) as ncount from %s" % self.encloseNames(tableName)) 
    120         return tempCursor.fetchall()[0][0] 
    121  
    122  
    123     def getFields(self, tableName): 
     115    def getTableRecordCount(self, tableName, cursor): 
     116        cursor.execute("select count(*) as ncount from %s" % self.encloseNames(tableName)) 
     117        return tempCursor.getDataSet()[0][0] 
     118 
     119 
     120    def getFields(self, tableName, cursor): 
    124121        if not tableName: 
    125122            return tuple() 
    126         tempCursor = self._connection.cursor() 
    127         tempCursor.execute("describe %s" % self.encloseNames(tableName)) 
    128         rs = tempCursor.fetchall() 
    129         fldDesc = tempCursor.description 
     123        cursor.execute("describe %s" % self.encloseNames(tableName)) 
     124        rs = cursor.getDataSet() 
     125        fldDesc = cursor.description 
    130126        # The field name is the first element of the tuple. Find the 
    131127        # first entry with the field name 'Key'; that will be the  
  • trunk/dabo/db/dbOracle.py

    r3303 r3323  
    7575 
    7676         
    77     def getTables(self, includeSystemTables=False): 
     77    def getTables(self, cursor, includeSystemTables=False): 
    7878        #### TODO: Verify that this works with NEWDATABASE, including 
    7979        ####    the option for including/excluding system tables. 
    80         tempCursor = self._connection.cursor() 
    81         tempCursor.execute("show tables") 
    82         rs = tempCursor.fetchall() 
     80        cursor.execute("show tables") 
     81        rs = cursor.getDataSet() 
    8382        tables = [] 
    8483        for record in rs: 
     
    8786 
    8887         
    89     def getTableRecordCount(self, tableName): 
     88    def getTableRecordCount(self, tableName, cursor): 
    9089        #### TODO: Verify that this is the correct syntax for NEWDATABASE 
    91         tempCursor = self._connection.cursor() 
    92         tempCursor.execute("select count(*) as ncount from %s" % tableName) 
    93         return tempCursor.fetchall()[0][0] 
     90        cursor.execute("select count(*) as ncount from %s" % tableName) 
     91        return cursor.getDataSet()[0][0] 
    9492 
    9593 
    96     def getFields(self, tableName): 
    97         tempCursor = self._connection.cursor() 
     94    def getFields(self, tableName, cursor): 
    9895        #### TODO: Modify for NEWDATABASE syntax 
    99         tempCursor.execute("describe %s" % tableName) 
    100         rs = tempCursor.fetchall() 
    101         fldDesc = tempCursor.description 
     96        cursor.execute("describe %s" % tableName) 
     97        rs = cursor.getDataSet() 
     98        fldDesc = cursor.description 
    10299        # The field name is the first element of the tuple. Find the 
    103100        # first entry with the field name 'Key'; that will be the  
  • trunk/dabo/db/dbPostgreSQL.py

    r3316 r3323  
    5959     
    6060     
    61     def getTables(self, includeSystemTables=False): 
    62         tempCursor = self._connection.cursor() 
     61    def getTables(self, cursor, includeSystemTables=False): 
    6362        # jfcs 11/01/04 assumed public schema 
    6463        #tempCursor.execute("select tablename from pg_tables where schemaname = 'public'") 
     
    7170            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)) 
    7271                         
    73         tempCursor.execute(sqltablestr) 
    74         rs = tempCursor.fetchall() 
    75          
    76          
     72        cursor.execute(sqltablestr) 
     73        rs = cursor.getDataSet() 
    7774        tables = [] 
    7875        for record in rs: 
     
    8178 
    8279     
    83     def getTableRecordCount(self, tableName): 
    84         tempCursor = self._connection.cursor() 
    85         tempCursor.execute("select count(*) as ncount from %s" % tableName) 
    86         return tempCursor.fetchall()[0][0] 
    87  
    88  
    89     def getFields(self, tableName): 
    90         tempCursor = self._connection.cursor() 
     80    def getTableRecordCount(self, tableName, cursor): 
     81        cursor.execute("select count(*) as ncount from %s" % tableName) 
     82        return cursor.getDataSet()[0][0] 
     83 
     84 
     85    def getFields(self, tableName, cursor): 
    9186        tableNameBreak=tableName.split('.',1) 
    9287        localSchemaName = tableNameBreak[0] 
     
    118113                #where c.relname = '%s' and a.attnum > 0 """ % tableName) 
    119114        # JFCS 01/22/07 Added support for schema  
    120         tempCursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c  
     115        cursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c  
    121116inner join pg_attribute a on a.attrelid = c.oid  
    122117inner join pg_type t on a.atttypid = t.oid  
    123118inner join pg_tables b on b.tablename=c.relname 
    124119where (b.schemaname || '.'|| c.relname)  = '%s' and a.attnum > 0 """ % tableName) 
    125         rs = tempCursor.fetchall() 
     120        rs = cursor.getDataSet() 
    126121 
    127122        ## get the PK the code should work well with 7.4 - 8.2 versions 
    128          
    129123        sqlstr = """SELECT n.nspname AS schema_name, c.relname AS table_name, 
    130124           c.oid AS table_oid, a.attname AS column_name, idx.n + 1 AS ordinal_position 
     
    137131       AND c.relnamespace = n.oid and c.relname = '%s' and n.nspname = '%s' """ % ('%',localTableName,localSchemaName) 
    138132         
    139         tempCursor.execute(sqlstr) 
    140         rs2=tempCursor.fetchall() 
    141         if rs2==[]: 
     133        cursor.execute(sqlstr) 
     134        rs2 = cursor.getDataSet() 
     135        if rs2 == []: 
    142136            thePKFieldName = None 
    143137        else: 
     
    250244        localTableName = tableNameBreak[1] 
    251245         
    252         tempCursor = self._connection.cursor() 
     246        tempCursor = self._cursor.AuxCursor 
    253247        sqltablestr = """SELECT seq.relname::text 
    254248        FROM pg_class src, pg_class seq, pg_namespace, pg_attribute, 
  • trunk/dabo/db/dbSQLite.py

    r3322 r3323  
    113113         
    114114     
    115     def _isExistingTable(self, tablename): 
    116         tempCursor = self._connection.cursor() 
    117         tempCursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=%s" % self.escQuote(tablename)) 
    118         rs = tempCursor.fetchall() 
     115    def _isExistingTable(self, tablename, cursor): 
     116        cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=%s" % self.escQuote(tablename)) 
     117        rs = cursor.getDataSet() 
    119118        return len(rs) > 0 
    120119     
    121120     
    122     def getTables(self, includeSystemTables=False): 
    123         tempCursor = self._connection.cursor() 
    124         tempCursor.execute("select * from sqlite_master") 
    125         rs = tempCursor.fetchall() 
     121    def getTables(self, cursor, includeSystemTables=False): 
     122        cursor.execute("select * from sqlite_master") 
     123        rs = cursor.getDataSet() 
    126124        if includeSystemTables: 
    127125            tables = [rec["name"] for rec in rs  
     
    134132         
    135133         
    136     def getTableRecordCount(self, tableName): 
    137         tempCursor = self._connection.cursor() 
    138         tempCursor.execute("select count(*) as ncount from %s" % tableName) 
    139         return tempCursor.fetchall()[0]["ncount"] 
    140  
    141  
    142     def getFields(self, tableName): 
    143         tempCursor = self._connection.cursor() 
    144         tempCursor.execute("pragma table_info('%s')" % tableName) 
    145         rs = tempCursor.fetchall() 
     134    def getTableRecordCount(self, tableName, cursor): 
     135        cursor.execute("select count(*) as ncount from %s" % tableName) 
     136        return cursor.getDataSet(rows=1)["ncount"] 
     137 
     138 
     139    def getFields(self, tableName, cursor): 
     140        cursor.execute("pragma table_info('%s')" % tableName) 
     141        rs = cursor.getDataSet() 
    146142        fields = [] 
    147143        for rec in rs: