~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/datasources/drivers/dbf/dbf/DataObject.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2005 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
import string
 
34
from gnue.common.datasources.GDataObjects import *
 
35
from gnue.common.datasources.drivers.special.static import *
 
36
import dbf
 
37
 
 
38
 
 
39
###########################################################
 
40
#
 
41
# This is an static data driver for connectionless clients
 
42
#
 
43
###########################################################
 
44
class DBF_DataObject (DataObject.STATIC_DataObject):
 
45
 
 
46
  def __init__(self, connection):
 
47
    DataObject.STATIC_DataObject.__init__(self, connection)
 
48
    self._DatabaseError = Error
 
49
  
 
50
  def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None, sql=""):
 
51
    return DBF_ResultSet(self, masterRecordSet=masterRecordSet)
 
52
 
 
53
 
 
54
  #
 
55
  # Schema (metadata) functions
 
56
  #
 
57
 
 
58
  # Return a list of the types of Schema objects this driver provides
 
59
  def getSchemaTypes(self):
 
60
    return [('table',_('Tables'),1)]
 
61
 
 
62
 
 
63
 
 
64
 
 
65
###########################################################
 
66
#
 
67
#
 
68
#
 
69
###########################################################
 
70
class DBF_ResultSet(ResultSet.STATIC_ResultSet):
 
71
 
 
72
  def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
 
73
    ResultSet.STATIC_ResultSet.__init__(self, dataObject, \
 
74
            cursor, defaultValues, masterRecordSet)
 
75
 
 
76
    self._recordSetClass = RecordSet.STATIC_RecordSet
 
77
 
 
78
  # Returns 1=DataObject has uncommitted changes
 
79
  def isPending(self):
 
80
    return 0    # Static DataObjects cannot have pending changes :)
 
81
 
 
82
  # Post changes to the database
 
83
  def post(self):
 
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):
 
87
      record.post()
 
88
 
 
89
  # Load cacheCount number of new records
 
90
  def _loadNextRecord(self):
 
91
    if hasattr(self,"_alldataloaded"):
 
92
      return 0
 
93
    
 
94
    # Load static data
 
95
    for row in self._dataObject._dataConnection:
 
96
      dict = {}
 
97
      c=0
 
98
      for f in self._dataObject._dataConnection.fields:
 
99
        dict[string.lower(f[0])] = row[c]
 
100
        c+=1
 
101
 
 
102
      record=self._recordSetClass(parent=self,initialData=dict)
 
103
      
 
104
      self._cachedRecords.append (record)
 
105
      
 
106
      self._recordCount=self._recordCount+1
 
107
 
 
108
    self._alldataloaded = 1
 
109
      
 
110
    return 1
 
111
 
 
112
 
 
113
 
 
114
######################################
 
115
#
 
116
#  The following hashes describe
 
117
#  this driver's characteristings.
 
118
#
 
119
######################################
 
120
 
 
121
#
 
122
#  All datasouce "types" and corresponding DataObject class
 
123
#
 
124
supportedDataObjects = {
 
125
  'static': DBF_DataObject,
 
126
  'object': DBF_DataObject
 
127
}
 
128
 
 
129