commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnue-common/src GDataObjects.py dbdrivers/...


From: Jason Cater
Subject: gnue/gnue-common/src GDataObjects.py dbdrivers/...
Date: Mon, 17 Sep 2001 22:11:18 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/09/17 22:11:17

Modified files:
        gnue-common/src: GDataObjects.py 
        gnue-common/src/dbdrivers/postgresql: DBdriver.py 

Log message:
        misc fixes

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GDataObjects.py.diff?cvsroot=OldCVS&tr1=1.20&tr2=1.21&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.16&tr2=1.17&r1=text&r2=text

Patches:
Index: gnue/gnue-common/src/GDataObjects.py
diff -u gnue/gnue-common/src/GDataObjects.py:1.20 
gnue/gnue-common/src/GDataObjects.py:1.21
--- gnue/gnue-common/src/GDataObjects.py:1.20   Thu Sep 13 18:39:21 2001
+++ gnue/gnue-common/src/GDataObjects.py        Mon Sep 17 22:11:17 2001
@@ -1,19 +1,19 @@
 #
 # This file is part of GNU Enterprise.
 #
-# GNU Enterprise is free software; you can redistribute it 
-# and/or modify it under the terms of the GNU General Public 
-# License as published by the Free Software Foundation; either 
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
 # version 2, or (at your option) any later version.
 #
-# GNU Enterprise is distributed in the hope that it will be 
-# useful, but WITHOUT ANY WARRANTY; without even the implied 
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 # PURPOSE. See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public 
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
 # Copyright 2000, 2001 Free Software Foundation
@@ -22,7 +22,7 @@
 # GDataObjects.py
 #
 # DESCRIPTION:
-# Class 
+# Class
 #
 # NOTES:
 #
@@ -583,14 +583,14 @@
 
 
 # Used to store schema data
-class Schema: 
-  def __init__(self, id=None, name=None, type=None, readOnly = 0):
-    self.id = id
-    self.name = name
-    self.type = type
-    self.readOnly = readOnly
+class Schema:
+  def __init__(self, attrs={}, getChildSchema=None):
+    self.__dict__.update(attrs)
+    if getChildSchema != None:
+      self.getChildSchema = getChildSchema
 
-
+  def getChildSchema(self, parent):
+    return ()
 
 
 
Index: gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.16 
gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.17
--- gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py:1.16  Fri Sep 14 
19:10:15 2001
+++ gnue/gnue-common/src/dbdrivers/postgresql/DBdriver.py       Mon Sep 17 
22:11:17 2001
@@ -42,7 +42,7 @@
 class PG_RecordSet(DBSIG_RecordSet): 
   pass    
 
-class PG_ResultSet(DBSIG_ResultSet): 
+class PG_ResultSet(DBSIG_ResultSet):
   def __init__(self, dataObject, cursor=None, defaultValues={}, 
masterRecordSet=None): 
     DBSIG_ResultSet.__init__(self, dataObject, \
             cursor, defaultValues, masterRecordSet)
@@ -88,14 +88,14 @@
 
 
 class PG_DataObject(DBSIG_DataObject): 
-  def __init__(self): 
+  def __init__(self):
     DBSIG_DataObject.__init__(self)
     self._DatabaseError = pgdb.DatabaseError
     #### When the PyGreSQL's .fetchone() bug is fixed, delete following line
     self._resultSetClass = PG_ResultSet
 
 
-  def connect(self, connectData={}): 
+  def connect(self, connectData={}):
     GDebug.printMesg(1,"Postgresql database driver initializing")
     try: 
       self._dataConnection = pgdb.connect(user=connectData['_username'], 
@@ -109,7 +109,7 @@
     self._postConnect()
 
 
-  def _postConnect(self): 
+  def _postConnect(self):
     self.triggerExtensions = TriggerExtensions(self._dataConnection)
 
 
@@ -118,54 +118,103 @@
   #
 
   # 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 = %s 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
 
 
 
 class PG_DataObject_Object(PG_DataObject, \
-      DBSIG_DataObject_Object): 
+      DBSIG_DataObject_Object):
 
-  def __init__(self): 
-    # Call DBSIG init first because PG_DataObject needs to overwrite 
+  def __init__(self):
+    # Call DBSIG init first because PG_DataObject needs to overwrite
     # some of its values
-    DBSIG_DataObject_Object.__init__(self) 
+    DBSIG_DataObject_Object.__init__(self)
     PG_DataObject.__init__(self)
 
-  def _buildQuery(self, conditions={}): 
+  def _buildQuery(self, conditions={}):
     return DBSIG_DataObject_Object._buildQuery(self, conditions)
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]