[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/gnue-common/src/dbdrivers popy/DBdriver.py...
From: |
Jason Cater |
Subject: |
gnue/gnue-common/src/dbdrivers popy/DBdriver.py... |
Date: |
Tue, 06 Nov 2001 14:41:10 -0500 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/11/06 14:41:10
Modified files:
gnue-common/src/dbdrivers/popy: DBdriver.py
gnue-common/src/dbdrivers/psycopg: DBdriver.py
gnue-common/src/dbdrivers/pypgsql: DBdriver.py
Log message:
Fixed introspection methods in alternate postgresql drivers
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/popy/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: gnue/gnue-common/src/dbdrivers/popy/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/popy/DBdriver.py:1.3
gnue/gnue-common/src/dbdrivers/popy/DBdriver.py:1.4
--- gnue/gnue-common/src/dbdrivers/popy/DBdriver.py:1.3 Sun Nov 4 17:22:35 2001
+++ gnue/gnue-common/src/dbdrivers/popy/DBdriver.py Tue Nov 6 14:41:10 2001
@@ -74,41 +74,90 @@
#
# Return a list of the types of Schema objects this driver provides
- def getSchemaTypes(self):
+ def getSchemaTypes(self):
return [('view','View',1), ('table','Table',1)]
# Return a list of Schema objects
- def getSchemaList(self, type=None):
+ def getSchemaList(self, type=None):
includeTables = (type in ('table','sources', None))
includeViews = (type in ('view','sources', None))
inClause = []
- if includeTables:
+ if includeTables:
inClause.append ("'r'")
- if includeViews:
+ if includeViews:
inClause.append ("'v'")
# TODO: This excludes any system tables and views. Should it?
statement = "select relname, relkind from pg_class " + \
"where relkind in (%s) " % (join(inClause,',')) + \
"and relname not like 'pg_%' " + \
- "order by relname"
+ "order by relname"
cursor = self._dataConnection.cursor()
cursor.execute(statement)
-
+
list = []
- for rs in cursor.fetchall():
- list.append(GDataObjects.Schema(id=lower(rs[0]), name=rs[0],
- type=rs[1] == 'v' and 'view' or 'table'))
+ for rs in cursor.fetchall():
+ list.append(GDataObjects.Schema(attrs={'id':lower(rs[0]), 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema))
cursor.close()
return list
-
+
# Find a schema object with specified name
def getSchemaByName(self, name, type=None):
- return None
+ statement = "select relname, relkind, oid from pg_class " + \
+ "where relname = '%s'" % (name)
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ rs = cursor.fetchone()
+ schema = GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema)
+
+ cursor.close()
+ return schema
+
+ # Get fields for a table
+ def __getFieldSchema(self, parent):
+
+ statement = "select attname, pg_attribute.oid, typname, " + \
+ " attnotnull, atthasdef, atttypmod " + \
+ "from pg_attribute, pg_type " + \
+ "where attrelid = %d and " % (parent.id) + \
+ "pg_type.oid = atttypid and attnum >= 0" + \
+ "order by attnum"
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ list = []
+ for rs in cursor.fetchall():
+
+ attrs={'id': rs[1], 'name': rs[0],
+ 'type':'field', 'nativetype': rs[2],
+ 'required': rs[3] and not rs[4]}
+
+ if rs[2] in ('int8','int2','int4','numeric',
+ 'float4','float8','money','bool'):
+ attrs['datatype']='number'
+ elif rs[2] in ('date','time','timestamp','abstime','reltime'):
+ attrs['datatype']='date'
+ else:
+ attrs['datatype']='text'
+
+ if rs[5] != -1:
+ attrs['length'] = rs[5]
+
+ list.append(GDataObjects.Schema(attrs=attrs))
+
+ cursor.close()
+ return list
Index: gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py:1.3
gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py:1.4
--- gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py:1.3 Sun Nov 4
17:22:35 2001
+++ gnue/gnue-common/src/dbdrivers/psycopg/DBdriver.py Tue Nov 6 14:41:10 2001
@@ -74,41 +74,90 @@
#
# Return a list of the types of Schema objects this driver provides
- def getSchemaTypes(self):
+ def getSchemaTypes(self):
return [('view','View',1), ('table','Table',1)]
# Return a list of Schema objects
- def getSchemaList(self, type=None):
+ def getSchemaList(self, type=None):
includeTables = (type in ('table','sources', None))
includeViews = (type in ('view','sources', None))
inClause = []
- if includeTables:
+ if includeTables:
inClause.append ("'r'")
- if includeViews:
+ if includeViews:
inClause.append ("'v'")
# TODO: This excludes any system tables and views. Should it?
statement = "select relname, relkind from pg_class " + \
"where relkind in (%s) " % (join(inClause,',')) + \
"and relname not like 'pg_%' " + \
- "order by relname"
+ "order by relname"
cursor = self._dataConnection.cursor()
cursor.execute(statement)
-
+
list = []
- for rs in cursor.fetchall():
- list.append(GDataObjects.Schema(id=lower(rs[0]), name=rs[0],
- type=rs[1] == 'v' and 'view' or 'table'))
+ for rs in cursor.fetchall():
+ list.append(GDataObjects.Schema(attrs={'id':lower(rs[0]), 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema))
cursor.close()
return list
-
+
# Find a schema object with specified name
def getSchemaByName(self, name, type=None):
- return None
+ statement = "select relname, relkind, oid from pg_class " + \
+ "where relname = '%s'" % (name)
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ rs = cursor.fetchone()
+ schema = GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema)
+
+ cursor.close()
+ return schema
+
+ # Get fields for a table
+ def __getFieldSchema(self, parent):
+
+ statement = "select attname, pg_attribute.oid, typname, " + \
+ " attnotnull, atthasdef, atttypmod " + \
+ "from pg_attribute, pg_type " + \
+ "where attrelid = %d and " % (parent.id) + \
+ "pg_type.oid = atttypid and attnum >= 0" + \
+ "order by attnum"
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ list = []
+ for rs in cursor.fetchall():
+
+ attrs={'id': rs[1], 'name': rs[0],
+ 'type':'field', 'nativetype': rs[2],
+ 'required': rs[3] and not rs[4]}
+
+ if rs[2] in ('int8','int2','int4','numeric',
+ 'float4','float8','money','bool'):
+ attrs['datatype']='number'
+ elif rs[2] in ('date','time','timestamp','abstime','reltime'):
+ attrs['datatype']='date'
+ else:
+ attrs['datatype']='text'
+
+ if rs[5] != -1:
+ attrs['length'] = rs[5]
+
+ list.append(GDataObjects.Schema(attrs=attrs))
+
+ cursor.close()
+ return list
Index: gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py:1.5
gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py:1.6
--- gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py:1.5 Mon Nov 5
22:55:24 2001
+++ gnue/gnue-common/src/dbdrivers/pypgsql/DBdriver.py Tue Nov 6 14:41:10 2001
@@ -82,41 +82,90 @@
#
# Return a list of the types of Schema objects this driver provides
- def getSchemaTypes(self):
+ def getSchemaTypes(self):
return [('view','View',1), ('table','Table',1)]
# Return a list of Schema objects
- def getSchemaList(self, type=None):
+ def getSchemaList(self, type=None):
includeTables = (type in ('table','sources', None))
includeViews = (type in ('view','sources', None))
inClause = []
- if includeTables:
+ if includeTables:
inClause.append ("'r'")
- if includeViews:
+ if includeViews:
inClause.append ("'v'")
# TODO: This excludes any system tables and views. Should it?
statement = "select relname, relkind from pg_class " + \
"where relkind in (%s) " % (join(inClause,',')) + \
"and relname not like 'pg_%' " + \
- "order by relname"
+ "order by relname"
cursor = self._dataConnection.cursor()
cursor.execute(statement)
-
+
list = []
- for rs in cursor.fetchall():
- list.append(GDataObjects.Schema(id=lower(rs[0]), name=rs[0],
- type=rs[1] == 'v' and 'view' or 'table'))
+ for rs in cursor.fetchall():
+ list.append(GDataObjects.Schema(attrs={'id':lower(rs[0]), 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema))
cursor.close()
return list
-
+
# Find a schema object with specified name
def getSchemaByName(self, name, type=None):
- return None
+ statement = "select relname, relkind, oid from pg_class " + \
+ "where relname = '%s'" % (name)
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ rs = cursor.fetchone()
+ schema = GDataObjects.Schema(attrs={'id':rs[2], 'name':rs[0],
+ 'type':rs[1] == 'v' and 'view' or 'table'},
+ getChildSchema=self.__getFieldSchema)
+
+ cursor.close()
+ return schema
+
+ # Get fields for a table
+ def __getFieldSchema(self, parent):
+
+ statement = "select attname, pg_attribute.oid, typname, " + \
+ " attnotnull, atthasdef, atttypmod " + \
+ "from pg_attribute, pg_type " + \
+ "where attrelid = %d and " % (parent.id) + \
+ "pg_type.oid = atttypid and attnum >= 0" + \
+ "order by attnum"
+
+ cursor = self._dataConnection.cursor()
+ cursor.execute(statement)
+
+ list = []
+ for rs in cursor.fetchall():
+
+ attrs={'id': rs[1], 'name': rs[0],
+ 'type':'field', 'nativetype': rs[2],
+ 'required': rs[3] and not rs[4]}
+
+ if rs[2] in ('int8','int2','int4','numeric',
+ 'float4','float8','money','bool'):
+ attrs['datatype']='number'
+ elif rs[2] in ('date','time','timestamp','abstime','reltime'):
+ attrs['datatype']='date'
+ else:
+ attrs['datatype']='text'
+
+ if rs[5] != -1:
+ attrs['length'] = rs[5]
+
+ list.append(GDataObjects.Schema(attrs=attrs))
+
+ cursor.close()
+ return list
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/gnue-common/src/dbdrivers popy/DBdriver.py...,
Jason Cater <=