/[gnue]/gnue-common/src/datasources/drivers/dbf/dbf/DataObject.py
ViewVC logotype

Diff of /gnue-common/src/datasources/drivers/dbf/dbf/DataObject.py

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

revision 1.1 by jcater, Fri Oct 10 01:21:15 2003 UTC revision 1.2 by jcater, Tue Nov 25 17:01:33 2003 UTC
# Line 0  Line 1 
1    #
2    # This file is part of GNU Enterprise.
3    #
4    # GNU Enterprise is free software; you can redistribute it
5    # and/or modify it under the terms of the GNU General Public
6    # License as published by the Free Software Foundation; either
7    # version 2, or (at your option) any later version.
8    #
9    # GNU Enterprise is distributed in the hope that it will be
10    # useful, but WITHOUT ANY WARRANTY; without even the implied
11    # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12    # PURPOSE. See the GNU General Public License for more details.
13    #
14    # You should have received a copy of the GNU General Public
15    # License along with program; see the file COPYING. If not,
16    # write to the Free Software Foundation, Inc., 59 Temple Place
17    # - Suite 330, Boston, MA 02111-1307, USA.
18    #
19    # Copyright 2001-2003 Free Software Foundation
20    #
21    # FILE:
22    # dbf/DBdriver.py
23    #
24    # DESCRIPTION:
25    # Virtual database driver for loading data from a DBF file
26    #
27    # NOTES:
28    # Used whenever a data has to be imported from dbase III+
29    #
30    
31    __all__ = ['DataObject']
32    
33    from gnue.common.apps import GDebug
34    import string
35    from gnue.common.datasources.GDataObjects import *
36    from gnue.common.drivers.special.static.Driver import *
37    import dbf
38    
39    
40    ###########################################################
41    #
42    # This is an static data driver for connectionless clients
43    #
44    ###########################################################
45    class DataObject (StaticDataObject):
46    
47      def __init__(self):
48        DataObject.__init__(self)
49        self.triggerExtensions = TriggerExtensions(self)
50        self._DatabaseError = Error
51      
52      def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None, sql=""):
53        return DBF_ResultSet(self, masterRecordSet=masterRecordSet)
54    
55    
56      #
57      # Schema (metadata) functions
58      #
59    
60      # Return a list of the types of Schema objects this driver provides
61      def getSchemaTypes(self):
62        return [('table',_('Tables'),1)]
63    
64    
65    
66    
67    ###########################################################
68    #
69    #
70    #
71    ###########################################################
72    class DBF_ResultSet(STATIC_ResultSet):
73    
74      def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
75        ResultSet.__init__(self, dataObject, \
76                cursor, defaultValues, masterRecordSet)
77    
78        self._recordSetClass = STATIC_RecordSet
79    
80      # Returns 1=DataObject has uncommitted changes
81      def isPending(self):
82        return 0    # Static DataObjects cannot have pending changes :)
83    
84      # Post changes to the database
85      def post(self):
86        # Leave this here in case (for some bizarro reason)
87        # a bound dataobject uses us as a master
88        for record in (self._cachedRecords):
89          record.post()
90    
91      # Load cacheCount number of new records
92      def _loadNextRecord(self):
93        if hasattr(self,"_alldataloaded"):
94          return 0
95        
96        # Load static data
97        for row in self._dataObject._dataConnection:
98          dict = {}
99          c=0
100          for f in self._dataObject._dataConnection.fields:
101            dict[string.lower(f[0])] = row[c]
102            c+=1
103    
104          record=self._recordSetClass(parent=self,initialData=dict)
105          
106          self._cachedRecords.append (record)
107          
108          self._recordCount=self._recordCount+1
109    
110        self._alldataloaded = 1
111          
112        return 1
113    
114    
115    
116    ######################################
117    #
118    #  The following hashes describe
119    #  this driver's characteristings.
120    #
121    ######################################
122    
123    #
124    #  All datasouce "types" and corresponding DataObject class
125    #
126    supportedDataObjects = {
127      'static': DBF_DataObject,
128      'object': DBF_DataObject
129    }
130    
131    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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