Changeset 3329

Show
Ignore:
Timestamp:
08/23/07 17:40:07 (1 year ago)
Author:
johnf
Message:

Made changes to support Ed recent changes.
Changed thePKFieldName to use a dict rather than a tuple.
reverted back to the way I was creating a temp cursor.

Files:

Legend:

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

    r3323 r3329  
    88    """Class providing PostgreSQL connectivity. Uses psycopg.""" 
    99    def __init__(self): 
     10        """ JFCS 08/23/07 Currently supporting only psycopg2""" 
    1011        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 (confirmed 
    13         #- by the author of the module). 
    14         #self.dbModuleName = "pgdb" 
    15         #self.dbModuleName = "PgSQL" 
    1612        self.dbModuleName = "psycopg" 
    1713        self.conn_user = '' 
     
    6157    def getTables(self, cursor, includeSystemTables=False): 
    6258        # jfcs 11/01/04 assumed public schema 
    63         #tempCursor.execute("select tablename from pg_tables where schemaname = 'public'") 
    6459        # jfcs 01/22/07 added below to support schema  
    6560        # thanks to Phillip J. Allen who provided a Select state that filtered for the user name 
    6661        if includeSystemTables: 
    6762            sqltablestr = (("SELECT schemaname || '.' || tablename AS tablename FROM pg_tables WHERE has_table_privilege('%s', schemaname || '.' || tablename, 'SELECT')") % self.conn_user) 
    68      
    6963        else: 
    7064            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)) 
     
    8478 
    8579    def getFields(self, tableName, cursor): 
     80        """JFCS support for 7.4 and greater 
     81           Requires that each table have a primary key""" 
    8682        tableNameBreak=tableName.split('.',1) 
    8783        localSchemaName = tableNameBreak[0] 
    8884        localTableName = tableNameBreak[1] 
    89         #jfcs 11/01/04 works great from psql (but does not work with the psycopg 
    90         #module) and only with postgres 7.4.x and later.  Too bad, the statement 
    91         #does everything in one shot. 
    92         #jfcs 11/02/04 below now works just fine 
    93         #comment it if your working with 7.3.x 
    94         # make sure you uncomment the other code out 
    95          
    96         # jfcs 01/22/07 actually I'm not sure Dabo is still able to support 7.1 - 7.4 
    97         # 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.typname  
    111                 #from pg_class c inner join pg_attribute a  
    112                 #on a.attrelid = c.oid inner join pg_type t on a.atttypid = t.oid  
    113                 #where c.relname = '%s' and a.attnum > 0 """ % tableName) 
    114         # JFCS 01/22/07 Added support for schema  
    11585        cursor.execute("""select c.oid,a.attname, t.typname, b.schemaname from pg_class c  
    11686inner join pg_attribute a on a.attrelid = c.oid  
     
    138108            #thestr = rs2[0][3] 
    139109            #thePKFieldName = thestr[thestr.find("(") + 1: thestr.find(")")].split(", ") 
    140             thePKFieldName = rs2[0][3] 
     110            #thePKFieldName = rs2[0][3] 
     111            thePKFieldName = rs2[0]['column_name'] 
    141112         
    142113        fields = [] 
    143114        for r in rs: 
    144             name = r[1] 
    145             fldType =r[2] 
     115            name = r['attname'] 
     116            #fldType =r[2] 
     117            fldType =r['typname'] 
    146118            pk = False 
    147119            if thePKFieldName is not None: 
     
    244216        localTableName = tableNameBreak[1] 
    245217         
    246         tempCursor = self._cursor.AuxCursor 
     218        #tempCursor = self._cursor.AuxCursor 
     219        tempCursor =self._connection.cursor() 
    247220        sqltablestr = """SELECT seq.relname::text 
    248221        FROM pg_class src, pg_class seq, pg_namespace, pg_attribute, 
     
    261234        tempCursor.execute(sqltablestr) 
    262235        rs = tempCursor.fetchall() 
     236        #if rs is None: 
     237            #dabo.dbActivityLog.write("no data in getLastInsertID") 
     238 
    263239        sqlWithseq_name="""select currval('%s') as curval""" % (rs[0][0],) 
    264240        tempCursor.execute(sqlWithseq_name)