2
# This file is part of GNU Enterprise.
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.
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.
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.
19
# Copyright 2001-2005 Free Software Foundation
25
# Virtual database driver for loading data from a DBF file
28
# Used whenever a data has to be imported from dbase III+
31
__all__ = ['DataObject']
34
from gnue.common.datasources.GDataObjects import *
35
from gnue.common.datasources.drivers.special.static import *
39
###########################################################
41
# This is an static data driver for connectionless clients
43
###########################################################
44
class DBF_DataObject (DataObject.STATIC_DataObject):
46
def __init__(self, connection):
47
DataObject.STATIC_DataObject.__init__(self, connection)
48
self._DatabaseError = Error
50
def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None, sql=""):
51
return DBF_ResultSet(self, masterRecordSet=masterRecordSet)
55
# Schema (metadata) functions
58
# Return a list of the types of Schema objects this driver provides
59
def getSchemaTypes(self):
60
return [('table',_('Tables'),1)]
65
###########################################################
69
###########################################################
70
class DBF_ResultSet(ResultSet.STATIC_ResultSet):
72
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
73
ResultSet.STATIC_ResultSet.__init__(self, dataObject, \
74
cursor, defaultValues, masterRecordSet)
76
self._recordSetClass = RecordSet.STATIC_RecordSet
78
# Returns 1=DataObject has uncommitted changes
80
return 0 # Static DataObjects cannot have pending changes :)
82
# Post changes to the database
84
# Leave this here in case (for some bizarro reason)
85
# a bound dataobject uses us as a master
86
for record in (self._cachedRecords):
89
# Load cacheCount number of new records
90
def _loadNextRecord(self):
91
if hasattr(self,"_alldataloaded"):
95
for row in self._dataObject._dataConnection:
98
for f in self._dataObject._dataConnection.fields:
99
dict[string.lower(f[0])] = row[c]
102
record=self._recordSetClass(parent=self,initialData=dict)
104
self._cachedRecords.append (record)
106
self._recordCount=self._recordCount+1
108
self._alldataloaded = 1
114
######################################
116
# The following hashes describe
117
# this driver's characteristings.
119
######################################
122
# All datasouce "types" and corresponding DataObject class
124
supportedDataObjects = {
125
'static': DBF_DataObject,
126
'object': DBF_DataObject