Changeset 3329
- Timestamp:
- 08/23/07 17:40:07 (1 year ago)
- Files:
-
- trunk/dabo/db/dbPostgreSQL.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/db/dbPostgreSQL.py
r3323 r3329 8 8 """Class providing PostgreSQL connectivity. Uses psycopg.""" 9 9 def __init__(self): 10 """ JFCS 08/23/07 Currently supporting only psycopg2""" 10 11 dBackend.__init__(self) 11 #- jfcs 11/01/04 I have to use alpha/beta of psycopg (currently 1.99.10)12 #- because the 1.1.x series does not support a cursor class (confirmed13 #- by the author of the module).14 #self.dbModuleName = "pgdb"15 #self.dbModuleName = "PgSQL"16 12 self.dbModuleName = "psycopg" 17 13 self.conn_user = '' … … 61 57 def getTables(self, cursor, includeSystemTables=False): 62 58 # jfcs 11/01/04 assumed public schema 63 #tempCursor.execute("select tablename from pg_tables where schemaname = 'public'")64 59 # jfcs 01/22/07 added below to support schema 65 60 # thanks to Phillip J. Allen who provided a Select state that filtered for the user name 66 61 if includeSystemTables: 67 62 sqltablestr = (("SELECT schemaname || '.' || tablename AS tablename FROM pg_tables WHERE has_table_privilege('%s', schemaname || '.' || tablename, 'SELECT')") % self.conn_user) 68 69 63 else: 70 64 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)) … … 84 78 85 79 def getFields(self, tableName, cursor): 80 """JFCS support for 7.4 and greater 81 Requires that each table have a primary key""" 86 82 tableNameBreak=tableName.split('.',1) 87 83 localSchemaName = tableNameBreak[0] 88 84 localTableName = tableNameBreak[1] 89 #jfcs 11/01/04 works great from psql (but does not work with the psycopg90 #module) and only with postgres 7.4.x and later. Too bad, the statement91 #does everything in one shot.92 #jfcs 11/02/04 below now works just fine93 #comment it if your working with 7.3.x94 # make sure you uncomment the other code out95 96 # jfcs 01/22/07 actually I'm not sure Dabo is still able to support 7.1 - 7.497 # should you attempt to Dabo with 7.4 or below please let us know.98 99 #tempCursor.execute("select c.column_name as fielname, c.data_type as fieldtyp, \100 #i.indisprimary AS is_pkey \101 #FROM information_schema.columns c \102 #LEFT JOIN information_schema.key_column_usage cu \103 #ON (c.table_name=cu.table_name AND c.column_name=cu.column_name) \104 #LEFT JOIN pg_class cl ON(cl.relname=cu.table_name) \105 #LEFT JOIN pg_index i ON(cl.oid= i.indrelid) WHERE c.table_name= '%s'" % tableName)106 #rs=tempCursor.fetchall()107 108 109 # Ok get the 'field name', 'field type'110 #tempCursor.execute("""select c.oid,a.attname, t.typname111 #from pg_class c inner join pg_attribute a112 #on a.attrelid = c.oid inner join pg_type t on a.atttypid = t.oid113 #where c.relname = '%s' and a.attnum > 0 """ % tableName)114 # JFCS 01/22/07 Added support for schema115 85 cursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c 116 86 inner join pg_attribute a on a.attrelid = c.oid … … 138 108 #thestr = rs2[0][3] 139 109 #thePKFieldName = thestr[thestr.find("(") + 1: thestr.find(")")].split(", ") 140 thePKFieldName = rs2[0][3] 110 #thePKFieldName = rs2[0][3] 111 thePKFieldName = rs2[0]['column_name'] 141 112 142 113 fields = [] 143 114 for r in rs: 144 name = r[1] 145 fldType =r[2] 115 name = r['attname'] 116 #fldType =r[2] 117 fldType =r['typname'] 146 118 pk = False 147 119 if thePKFieldName is not None: … … 244 216 localTableName = tableNameBreak[1] 245 217 246 tempCursor = self._cursor.AuxCursor 218 #tempCursor = self._cursor.AuxCursor 219 tempCursor =self._connection.cursor() 247 220 sqltablestr = """SELECT seq.relname::text 248 221 FROM pg_class src, pg_class seq, pg_namespace, pg_attribute, … … 261 234 tempCursor.execute(sqltablestr) 262 235 rs = tempCursor.fetchall() 236 #if rs is None: 237 #dabo.dbActivityLog.write("no data in getLastInsertID") 238 263 239 sqlWithseq_name="""select currval('%s') as curval""" % (rs[0][0],) 264 240 tempCursor.execute(sqlWithseq_name)
