/[gnue]/gnue-common/src/datasources/drivers/postgresql/pypgsql/Driver.py
ViewVC logotype

Diff of /gnue-common/src/datasources/drivers/postgresql/pypgsql/Driver.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35 by siesel, Thu Oct 9 21:27:49 2003 UTC revision 1.36 by jcater, Tue Nov 25 17:01:44 2003 UTC
# Line 1  Line 1 
1  #  #
2  # This file is part of GNU Enterprise.  # This file is part of GNU Enterprise.
3  #  #
4  # GNU Enterprise is free software; you can redistribute it  # GNU Enterprise is free software; you can redistribute it
5  # and/or modify it under the terms of the GNU General Public  # and/or modify it under the terms of the GNU General Public
6  # License as published by the Free Software Foundation; either  # License as published by the Free Software Foundation; either
7  # version 2, or(at your option) any later version.  # version 2, or(at your option) any later version.
8  #  #
9  # GNU Enterprise is distributed in the hope that it will be  # GNU Enterprise is distributed in the hope that it will be
10  # useful, but WITHOUT ANY WARRANTY; without even the implied  # useful, but WITHOUT ANY WARRANTY; without even the implied
11  # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  # PURPOSE. See the GNU General Public License for more details.  # PURPOSE. See the GNU General Public License for more details.
13  #  #
14  # You should have received a copy of the GNU General Public  # You should have received a copy of the GNU General Public
15  # License along with program; see the file COPYING. If not,  # License along with program; see the file COPYING. If not,
16  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
17  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
# Line 28  Line 28 
28  # NOTES:  # NOTES:
29  #  #
30    
31  import sys,string,types  __all__ = ('Connection')
32    
33    import sys
34  from gnue.common.datasources import GDataObjects, GConditions, GConnections  from gnue.common.datasources import GDataObjects, GConditions, GConnections
35  from gnue.common.apps import GDebug  from gnue.common.apps import GDebug
36  from gnue.common.datasources.drivers.postgresql.Base.Driver \  from gnue.common.datasources.drivers.postgresql import Base
    import PGSQL_RecordSet, PGSQL_ResultSet, PGSQL_DataObject, \  
           PGSQL_DataObject_SQL, PGSQL_DataObject_Object, \  
           PGSQL_TriggerExtensions  
37    
38  try:  try:
39    from pyPgSQL import PgSQL # pyPgSQL 2.0 support    from pyPgSQL import PgSQL # pyPgSQL 2.0 support
40  except ImportError:  except ImportError:
41      # TODO: Re-evaluate the minimum version we support!
42    import PgSQL              # pyPgSQL 1.6 support    import PgSQL              # pyPgSQL 1.6 support
43    
44      
45  class PG_RecordSet(PGSQL_RecordSet):  
46    pass  class ResultSet(Base.ResultSet):
47    
 class PG_ResultSet(PGSQL_ResultSet):  
   def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):  
     PGSQL_ResultSet.__init__(self, dataObject, \  
                              cursor, defaultValues, masterRecordSet)  
     self._recordSetClass = PG_RecordSet  
       
48    # TODO: Override the base _loadNextRecord as the fetchmany() from the cursor    # TODO: Override the base _loadNextRecord as the fetchmany() from the cursor
49    # TODO: returns an exception instead of None.  Not sure wazzup with that.    # TODO: returns an exception instead of None.  Not sure wazzup with that.
50    def _loadNextRecord(self):    def _loadNextRecord(self):
# Line 70  class PG_ResultSet(PGSQL_ResultSet): Line 64  class PG_ResultSet(PGSQL_ResultSet):
64              i = 0              i = 0
65              dict = {}              dict = {}
66              for f in (rs):              for f in (rs):
67                if self._dataObject._unicodeMode and type(f)==types.StringType:                dict[self._fieldNames[i]] = f
                 f=unicode(f,self._dataObject._databaseEncoding)  
               dict[string.lower(self._fieldNames[i])] = f  
68                i += 1                i += 1
69              self._cachedRecords.append (self._recordSetClass(parent=self, \              self._cachedRecords.append (self._recordSetClass(parent=self, \
70                                                               initialData=dict))                                                               initialData=dict))
# Line 84  class PG_ResultSet(PGSQL_ResultSet): Line 76  class PG_ResultSet(PGSQL_ResultSet):
76      else:      else:
77        return 0        return 0
78    
 class PG_DataObject(PGSQL_DataObject):  
   def __init__(self):  
     PGSQL_DataObject.__init__(self, PgSQL, PG_ResultSet)  
     self._connectString = '%s::%s:%s:%s::%s'  
79    
 class PG_DataObject_Object(PG_DataObject, \  
       PGSQL_DataObject_Object):  
80    
81    def __init__(self):  class DataObject_Object(Base.DataObject_Object):
82      # Call PGSQL init first because PG_DataObject needs to overwrite    _resultSetClass = ResultSet
     # some of its values  
     PG_DataObject.__init__(self)  
83    
   def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):  
     return PGSQL_DataObject_Object._buildQuery(self, conditions,forDetail,  
                                                additionalSQL)  
84    
85    class DataObject_SQL(Base.DataObject_SQL):
86      _resultSetClass = ResultSet
87    
 class PG_DataObject_SQL(PG_DataObject, \  
       PGSQL_DataObject_SQL):  
   def __init__(self):  
     # Call PGSQL init first because PG_DataObject needs to overwrite  
     # some of its values  
     PG_DataObject.__init__(self)  
88    
89    def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):  class Connection(Base.Connection):
90      return PGSQL_DataObject_SQL._buildQuery(self, conditions,forDetail,\    _pg_driver = PgSQL
91                                              additionalSQL)    _pg_connectString = '%s::%s:%s:%s::%s'
92    
93      supportedDataObjects = {
94        'object': DataObject_Object,
95        'sql':    DataObject_SQL
96      }
97    
 #  
 #  Extensions to Trigger Namespaces  
 #  
 class TriggerExtensions(PGSQL_TriggerExtensions):  
   pass  
98    
 ######################################  
 #  
 #  The following hashes describe  
 #  this driver's characteristings.  
 #  
 ######################################  
   
 #  
 #  All datasouce "types" and corresponding DataObject class  
 #  
 supportedDataObjects = {  
   'object': PG_DataObject_Object,  
   'sql':    PG_DataObject_SQL  
 }  

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26