[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src/dbdrivers/_pgsql DBdriver.py
From: |
Jason Cater |
Subject: |
gnue/common/src/dbdrivers/_pgsql DBdriver.py |
Date: |
Thu, 04 Jul 2002 14:44:16 -0400 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 02/07/04 14:44:16
Modified files:
common/src/dbdrivers/_pgsql: DBdriver.py
Log message:
Added DEFAULT VALUE and PRIMARY KEY support (preliminary/testing) to
postgresql's introspection
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/dbdrivers/_pgsql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.16&tr2=1.17&r1=text&r2=text
Patches:
Index: gnue/common/src/dbdrivers/_pgsql/DBdriver.py
diff -c gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.16
gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.17
*** gnue/common/src/dbdrivers/_pgsql/DBdriver.py:1.16 Fri Jun 28 17:54:06 2002
--- gnue/common/src/dbdrivers/_pgsql/DBdriver.py Thu Jul 4 14:44:16 2002
***************
*** 29,35 ****
#
! from string import lower, join
import sys
from gnue.common import GDebug, GDataObjects
from gnue.common.dbdrivers._dbsig.DBdriver \
--- 29,35 ----
#
! from string import lower, join, split
import sys
from gnue.common import GDebug, GDataObjects
from gnue.common.dbdrivers._dbsig.DBdriver \
***************
*** 133,139 ****
list = []
for rs in cursor.fetchall():
list.append(GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
! 'type':rs[1] == 'v' and 'view' or 'table'},
getChildSchema=self.__getFieldSchema))
cursor.close()
--- 133,140 ----
list = []
for rs in cursor.fetchall():
list.append(GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
! 'type':rs[1] == 'v' and 'view' or 'table',
! 'primarykey': self.__getPrimaryKey(cursor, rs[2])},
getChildSchema=self.__getFieldSchema))
cursor.close()
***************
*** 151,157 ****
rs = cursor.fetchone()
if rs:
schema = GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
! 'type':rs[1] == 'v' and 'view' or 'table'},
getChildSchema=self.__getFieldSchema)
else:
schema = None
--- 152,159 ----
rs = cursor.fetchone()
if rs:
schema = GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
! 'type':rs[1] == 'v' and 'view' or 'table',
! 'primarykey': self.__getPrimaryKey(cursor, rs[2])
},
getChildSchema=self.__getFieldSchema)
else:
schema = None
***************
*** 159,169 ****
cursor.close()
return schema
# Get fields for a table
def __getFieldSchema(self, parent):
statement = "select attname, pg_type.oid, typname, " + \
! " attnotnull, atthasdef, atttypmod " + \
"from pg_attribute, pg_type " + \
"where attrelid = %d and " % (parent.id) + \
"pg_type.oid = atttypid and attnum >= 0" + \
--- 161,183 ----
cursor.close()
return schema
+ def __getPrimaryKey(self, cursor, oid):
+ rs = cursor.execute("select indkey from pg_index where indrelid=%d" % oid)
+ statement = "select attname from pg_attribute " \
+ "where attrelid = %d and attnum = %%d" % oid
+ if rs:
+ pks = []
+ for indpos in rs[0]:
+ pks.append(cursor.execute(statement % indpos).fetchone()[0])
+ return tuple(pks)
+ else:
+ return None
+
# Get fields for a table
def __getFieldSchema(self, parent):
statement = "select attname, pg_type.oid, typname, " + \
! " attnotnull, atthasdef, atttypmod, attnum " + \
"from pg_attribute, pg_type " + \
"where attrelid = %d and " % (parent.id) + \
"pg_type.oid = atttypid and attnum >= 0" + \
***************
*** 190,195 ****
--- 204,227 ----
if rs[5] != -1:
attrs['length'] = rs[5]
+
+ # Find any default values
+ if rs[4]:
+ cursor.execute("select adsrc " + \
+ "from pg_attrdef " + \
+ "where adrelid = %d and adnum = %d" % (parent.id,
rs[6]))
+ defrs = cursor.fetchone()
+ if defrs:
+ dflt = defrs[0]
+ if dflt[:8] == 'nextval(':
+ attrs['defaulttype'] = 'sequence'
+ attrs['defaultval'] = split(dflt,"'")[1]
+ elif dflt == 'now()':
+ attrs['defaulttype'] = 'system'
+ attrs['defaultval'] = 'timestamp'
+ else:
+ attrs['defaulttype'] = 'constant'
+ attrs['defaultval'] = dflt
list.append(GDataObjects.Schema(attrs=attrs))
- gnue/common/src/dbdrivers/_pgsql DBdriver.py,
Jason Cater <=