Changeset 3323
- Timestamp:
- 08/22/07 18:07:43 (1 year ago)
- Files:
-
- trunk/dabo/db/dBackend.py (modified) (4 diffs)
- trunk/dabo/db/dCursorMixin.py (modified) (3 diffs)
- trunk/dabo/db/dbFirebird.py (modified) (5 diffs)
- trunk/dabo/db/dbMsSQL.py (modified) (7 diffs)
- trunk/dabo/db/dbMySQL.py (modified) (2 diffs)
- trunk/dabo/db/dbOracle.py (modified) (2 diffs)
- trunk/dabo/db/dbPostgreSQL.py (modified) (6 diffs)
- trunk/dabo/db/dbSQLite.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/db/dBackend.py
r3314 r3323 39 39 # writing, only dbSQLite is set up for this. 40 40 self._alreadyCorrectedFieldTypes = False 41 # Reference to the cursor that is using this object 42 self._cursor = None 41 43 42 44 … … 156 158 157 159 158 def getTables(self, includeSystemTables=False):160 def getTables(self, cursor, includeSystemTables=False): 159 161 """ Return a tuple of the tables in the current database. 160 162 … … 164 166 165 167 166 def getTableRecordCount(self, tableName ):168 def getTableRecordCount(self, tableName, cursor): 167 169 """ Return the number of records in the backend table.""" 168 170 return -1 169 171 170 172 171 def getFields(self, tableName ):173 def getFields(self, tableName, cursor): 172 174 """ Return field information from the backend table. 173 175 … … 480 482 def isExistingTable(self, table): 481 483 """Returns whether or not the table exists.""" 484 crs = self._cursor.AuxCursor 482 485 if isinstance(table, dTable): 483 return self._isExistingTable(table.name )486 return self._isExistingTable(table.name, crs) 484 487 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): 489 492 # OVERRIDE IN SUBCLASSES! 490 493 return False trunk/dabo/db/dCursorMixin.py
r3322 r3323 1655 1655 def getTables(self, includeSystemTables=False): 1656 1656 """ Return a tuple of tables in the current database.""" 1657 return self.BackendObject.getTables( includeSystemTables)1657 return self.BackendObject.getTables(self.AuxCursor, includeSystemTables) 1658 1658 1659 1659 1660 1660 def getTableRecordCount(self, tableName): 1661 1661 """ Get the number of records in the backend table.""" 1662 return self.BackendObject.getTableRecordCount(tableName )1662 return self.BackendObject.getTableRecordCount(tableName, self.AuxCursor) 1663 1663 1664 1664 … … 1674 1674 # Use the default 1675 1675 tableName = self.Table 1676 return self.BackendObject.getFields(tableName )1676 return self.BackendObject.getFields(tableName, self.AuxCursor) 1677 1677 1678 1678 … … 2057 2057 def _setBackendObject(self, obj): 2058 2058 self.__backend = obj 2059 if obj: 2060 obj._cursor = self 2059 2061 if self.__auxCursor: 2060 2062 self.__auxCursor.__backend = obj trunk/dabo/db/dbFirebird.py
r3314 r3323 95 95 96 96 97 def getTables(self, includeSystemTables=False):97 def getTables(self, cursor, includeSystemTables=False): 98 98 if includeSystemTables: 99 99 whereClause = '' … … 101 101 whereClause = "where rdb$relation_name not starting with 'RDB$' " 102 102 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 " 105 104 "%s order by rdb$relation_name" % whereClause) 106 rs = tempCursor. fetchall()105 rs = tempCursor.getDataSet() 107 106 tables = [] 108 107 for record in rs: … … 111 110 112 111 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): 121 118 # Get the PK 122 119 sql = """ select inseg.rdb$field_name … … 125 122 where idxs.rdb$relation_name = '%s' 126 123 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) 129 126 try: 130 127 pkField = rs[0].strip() … … 147 144 ORDER BY b.RDB$FIELD_ID """ % tableName.upper() 148 145 149 tempCursor.execute(sql)150 rs = tempCursor.fetchall()146 cursor.execute(sql) 147 rs = cursor.getDataSet() 151 148 fields = [] 152 149 for r in rs: trunk/dabo/db/dbMsSQL.py
r3303 r3323 64 64 65 65 66 def getTables(self, includeSystemTables=False): 67 tempCursor = self._connection.cursor() 66 def getTables(self, cursor, includeSystemTables=False): 68 67 # jfcs 11/01/06 assumed public schema 69 68 # cfk: this worries me: how does it know what db is being used? … … 71 70 72 71 dbName = self.database 73 tempCursor.execute("select table_name"72 cursor.execute("select table_name" 74 73 " from INFORMATION_SCHEMA.TABLES" 75 74 " where table_catalog = %(db)s" … … 77 76 " order by table_name", 78 77 {'db':dbName} ) 79 rs = tempCursor.fetchall()78 rs = cursor.getDataSet() 80 79 tables = [x[0] for x in rs] 81 80 tables = tuple(tables) … … 83 82 84 83 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] 89 87 90 88 … … 151 149 152 150 153 def getFields(self, tableName ):151 def getFields(self, tableName, cursor): 154 152 """ 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 """ 158 155 # fairly standard way of getting column settings 159 156 # this may be standard enough to put in the super class 160 161 157 dbName = self.database 162 158 163 tempCursor.execute(159 cursor.execute( 164 160 "select COLUMN_NAME, DATA_TYPE" 165 161 " from INFORMATION_SCHEMA.COLUMNS" … … 168 164 " order by ORDINAL_POSITION", 169 165 {'table':tableName, 'db':dbName} ) 170 fieldDefs = tempCursor.fetchall()171 172 tempCursor.execute(166 fieldDefs = cursor.getDataSet() 167 168 cursor.execute( 173 169 "select COLUMN_NAME " 174 170 " from information_schema.Constraint_Column_Usage CCU" … … 180 176 " and TC.Table_Name = %(table)s", 181 177 {'table':tableName, 'db':dbName} ) 182 pkFields = tempCursor.fetchall()178 pkFields = cursor.getDataSet() 183 179 184 180 fields = [] trunk/dabo/db/dbMySQL.py
r3314 r3323 95 95 96 96 97 def _isExistingTable(self, tablename): 98 tempCursor = self._connection.cursor() 97 def _isExistingTable(self, tablename, cursor): 99 98 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() 102 101 return bool(rs) 103 102 104 103 105 def getTables(self, includeSystemTables=False):104 def getTables(self, cursor, includeSystemTables=False): 106 105 # MySQL doesn't have system tables, in the traditional sense, as 107 106 # 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() 111 109 tables = [] 112 110 for record in rs: … … 115 113 116 114 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): 124 121 if not tableName: 125 122 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 130 126 # The field name is the first element of the tuple. Find the 131 127 # first entry with the field name 'Key'; that will be the trunk/dabo/db/dbOracle.py
r3303 r3323 75 75 76 76 77 def getTables(self, includeSystemTables=False):77 def getTables(self, cursor, includeSystemTables=False): 78 78 #### TODO: Verify that this works with NEWDATABASE, including 79 79 #### 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() 83 82 tables = [] 84 83 for record in rs: … … 87 86 88 87 89 def getTableRecordCount(self, tableName ):88 def getTableRecordCount(self, tableName, cursor): 90 89 #### 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] 94 92 95 93 96 def getFields(self, tableName): 97 tempCursor = self._connection.cursor() 94 def getFields(self, tableName, cursor): 98 95 #### TODO: Modify for NEWDATABASE syntax 99 tempCursor.execute("describe %s" % tableName)100 rs = tempCursor.fetchall()101 fldDesc = tempCursor.description96 cursor.execute("describe %s" % tableName) 97 rs = cursor.getDataSet() 98 fldDesc = cursor.description 102 99 # The field name is the first element of the tuple. Find the 103 100 # first entry with the field name 'Key'; that will be the trunk/dabo/db/dbPostgreSQL.py
r3316 r3323 59 59 60 60 61 def getTables(self, includeSystemTables=False): 62 tempCursor = self._connection.cursor() 61 def getTables(self, cursor, includeSystemTables=False): 63 62 # jfcs 11/01/04 assumed public schema 64 63 #tempCursor.execute("select tablename from pg_tables where schemaname = 'public'") … … 71 70 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)) 72 71 73 tempCursor.execute(sqltablestr) 74 rs = tempCursor.fetchall() 75 76 72 cursor.execute(sqltablestr) 73 rs = cursor.getDataSet() 77 74 tables = [] 78 75 for record in rs: … … 81 78 82 79 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): 91 86 tableNameBreak=tableName.split('.',1) 92 87 localSchemaName = tableNameBreak[0] … … 118 113 #where c.relname = '%s' and a.attnum > 0 """ % tableName) 119 114 # JFCS 01/22/07 Added support for schema 120 tempCursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c115 cursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c 121 116 inner join pg_attribute a on a.attrelid = c.oid 122 117 inner join pg_type t on a.atttypid = t.oid 123 118 inner join pg_tables b on b.tablename=c.relname 124 119 where (b.schemaname || '.'|| c.relname) = '%s' and a.attnum > 0 """ % tableName) 125 rs = tempCursor.fetchall()120 rs = cursor.getDataSet() 126 121 127 122 ## get the PK the code should work well with 7.4 - 8.2 versions 128 129 123 sqlstr = """SELECT n.nspname AS schema_name, c.relname AS table_name, 130 124 c.oid AS table_oid, a.attname AS column_name, idx.n + 1 AS ordinal_position … … 137 131 AND c.relnamespace = n.oid and c.relname = '%s' and n.nspname = '%s' """ % ('%',localTableName,localSchemaName) 138 132 139 tempCursor.execute(sqlstr)140 rs2 =tempCursor.fetchall()141 if rs2 ==[]:133 cursor.execute(sqlstr) 134 rs2 = cursor.getDataSet() 135 if rs2 == []: 142 136 thePKFieldName = None 143 137 else: … … 250 244 localTableName = tableNameBreak[1] 251 245 252 tempCursor = self._c onnection.cursor()246 tempCursor = self._cursor.AuxCursor 253 247 sqltablestr = """SELECT seq.relname::text 254 248 FROM pg_class src, pg_class seq, pg_namespace, pg_attribute, trunk/dabo/db/dbSQLite.py
r3322 r3323 113 113 114 114 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() 119 118 return len(rs) > 0 120 119 121 120 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() 126 124 if includeSystemTables: 127 125 tables = [rec["name"] for rec in rs … … 134 132 135 133 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() 146 142 fields = [] 147 143 for rec in rs:
