[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/gnue-common/gnue/common/dbdrivers _dbsig/D...
From: |
Jason Cater |
Subject: |
gnue/gnue-common/gnue/common/dbdrivers _dbsig/D... |
Date: |
Tue, 15 May 2001 08:15:39 -0700 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 01/05/15 08:15:39
Modified files:
gnue-common/gnue/common/dbdrivers/_dbsig: DBdriver.py
gnue-common/gnue/common/dbdrivers/postgresql: DBdriver.py
Removed files:
gnue-common/gnue/common/dbdrivers/pg: DBdriver.py __init__.py
test.py
Log message:
placed experimental dbdriver into main postgresql file since two
formats do not conflict with each other
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py
diff -u gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.2
gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.3
--- gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.2 Fri May
11 14:59:04 2001
+++ gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py Tue May 15
08:15:39 2001
@@ -32,7 +32,7 @@
#
from gnue.common import GDataObjects, GDebug
-
+from string import lower
class DBSIG_RecordSet(GDataObjects.RecordSet):
def _postChanges(self):
@@ -73,15 +73,21 @@
return 0
-class DBSIG_DataSource(GDataObjects.DataSource):
+class DBSIG_DataObject(GDataObjects.DataObject):
def __init__(self):
- GDataObjects.DataSource.__init__(self)
+ GDataObjects.DataObject.__init__(self)
GDebug.printMesg (1,"DB-SIG database driver backend initializing")
self._resultSetClass = DBSIG_ResultSet
self._DatabaseError = None
+
+ # This should be over-ridden only if driver needs more than user/pass
+ def getLoginFields(self):
+ return [['_username', 'User Name',0],['_password', 'Password',1]]
+
+
def createResultSet(self, conditions={}, readOnly=0):
try:
cursor = self._dataConnection.cursor()
@@ -115,20 +121,21 @@
-class DBSIG_DataSourceObject(DBSIG_DataSource):
+class DBSIG_DataObject_Object(DBSIG_DataObject):
def _buildQuery(self, conditions={}):
return None
-class DBSIG_DataSourceSQL(DBSIG_DataSource):
+class DBSIG_DataObject_SQL(DBSIG_DataObject):
def _buildQuery(self, conditions={}):
+ # Obviously, this is in a pre-alpha state :)
return "select zipcode, city, state from zipcode order by zipcode desc"
-supportedDataSources = {
- 'object': DBSIG_DataSourceObject,
- 'sql': DBSIG_DataSourceSQL
+supportedDataObjects = {
+ 'object': DBSIG_DataObject_Object,
+ 'sql': DBSIG_DataObject_SQL
}
Index: gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py
diff -u gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py:1.1
gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py:1.2
--- gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py:1.1 Sun Apr
15 18:33:51 2001
+++ gnue/gnue-common/gnue/common/dbdrivers/postgresql/DBdriver.py Tue May
15 08:15:39 2001
@@ -4,7 +4,7 @@
# 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.
+# 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
@@ -19,33 +19,156 @@
# Copyright 2000 Free Software Foundation
#
# FILE:
-# DSgedi.py
+# postgresql/DBdriver.py
#
# DESCRIPTION:
-# Driver to provide access to data vi the gedi object server
-# Accessed via the GFBlock object
-# Requires oribt-python 0.1.3 to function properly at this time
+# Postgresql implementation of dbdriver using Python DB-SIG v2
+# specification.
#
# NOTES:
#
+import pgdb
+from string import lower
+import sys
+from gnue.common import GDebug
+from gnue.common.dbdrivers._dbsig.DBdriver \
+ import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, \
+ DBSIG_DataObject_SQL, DBSIG_DataObject_Object
+
+
+class PG_RecordSet(DBSIG_RecordSet):
+ def _postChanges(self):
+ values = []
+ fields = []
+ fieldString = ""
+ for field in (self._modifiedFields.keys()):
+ fields.append(field + " = %s")
+ values.append(self._fields[field])
+
+ statement = 'UPDATE %s SET %s WHERE %s = %s'
+
+
+class PG_ResultSet(DBSIG_ResultSet):
+ def __init__(self, cursor=None, defaultValues={}, masterRecordSet=None):
+ DBSIG_ResultSet.__init__(self, \
+ cursor,defaultValues,masterRecordSet)
+ self._recordSetClass = PG_RecordSet
+
+
+ #### NOTE: Once PyGreSQL's .fetchone() bug is fixed, this method
+ #### should be deleted! Also note the line in PG_DataObject.__init__.
+ #### Right now, we are having to preload *ALL* rows from a datasource.
+ def _loadNextRecord(self):
+ if self._cursor:
+ try:
+ rsall = self._cursor.fetchall()
+ except self._DatabaseError, err:
+ raise DBError, err
+
+ if len(rsall):
+ for rs in(rsall):
+ GDebug.printMesg(5, "New row retrieved: %s" % rs)
+ if not self._fieldNames:
+ self._fieldNames = []
+ for t in(self._cursor.description):
+ self._fieldNames.append(t[0])
+ self._boundFields[lower(t[0])] = ""
+ GDebug.printMesg(5, "Field names set to %s" % self._fieldNames)
+ if rs:
+ i = 0
+ dict = {}
+ for f in(rs):
+ dict[self._fieldNames[i]] = f
+ i = i + 1
+
self._cachedRecords.append(self._recordSetClass(parent=self,initialData=dict))
+ else:
+ return 0
+ return 1
+ else:
+ return 0
+ else:
+ return 0
+####
+
+
+class PG_DataObject(DBSIG_DataObject):
+ 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={}):
+ GDebug.printMesg(1,"Postgresql database driver initializing")
+ try:
+ self._dataConnection = pgdb.connect(user=connectData['_username'],
+ password=connectData['_password'],
+ host=connectData['host'],
+ database=connectData['dbname'])
+ except self._DatabaseError, value:
+ raise DBError, value
+
+
+class PG_DataObject_Object(PG_DataObject, \
+ DBSIG_DataObject_Object):
+
+ def __init__(self):
+ # Call DBSIG init first because PG_DataObject needs to overwrite
+ # some of its values
+ DBSIG_DataObject_Object.__init__(self)
+ PG_DataObject.__init__(self)
+
+ def _buildQuery(self, conditions={}):
+ return DBSIG_DataObject_Object._buildQuery(self, conditions)
+
+
+class PG_DataObject_SQL(PG_DataObject, \
+ DBSIG_DataObject_SQL):
+ def __init__(self):
+ # Call DBSIG init first because PG_DataObject needs to overwrite
+ # some of its values
+ DBSIG_DataObject_SQL.__init__(self)
+ PG_DataObject.__init__(self)
+
+ def _buildQuery(self, conditions={}):
+ return DBSIG_DataObject_SQL._buildQuery(self, conditions)
+
+
+
+supportedDataObjects = {
+ 'object': PG_DataObject_Object,
+ 'sql': PG_DataObject_SQL
+}
+
+
+
+
+
+##########################################################################
+##########################################################################
+##
+## The following is the old-style (pre-GDataObject/GDataSource) driver
+## code. It will soon be deleted after GForms is converted to new style.
+##
+##########################################################################
+##########################################################################
+
import pg
import string
-import sys
from gnue.forms import GFOptions
from gnue.forms.GFError import DBError
class DBdriver:
def __init__(self):
- if GFOptions.DEBUG:
- print "Postgresql database driver initializing"
+ GDebug.printMesg(1, "Postgresql database driver initializing")
self.connection = None
self.uniqueKey = None
def connect(self, host, dbname, user, passwd):
- if GFOptions.DEBUG:
- print "connecting"
+ GDebug.printMesg(1, "connecting")
try:
self.connection = pg.DB(dbname, host, -1, None, None, user, passwd)
if GFOptions.Encoding != 'DEFAULT':
@@ -151,9 +274,6 @@
else:
print "constructSQL: unsupport SQL statement type"
-
- if GFOptions.DEBUG > 50:
- print sql
return sql
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/gnue-common/gnue/common/dbdrivers _dbsig/D...,
Jason Cater <=