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__ = ['Connection'] |
32 |
|
|
33 |
|
from gnue.common.datasources.GDataObjects import Error |
34 |
|
from gnue.common.datasource import GConnection |
35 |
|
|
36 |
|
|
37 |
|
class Connection(GConnection.Connection): |
38 |
|
supportedDataObjects = {'object': DataObject, |
39 |
|
'static': DataObject} # TODO: Why static?!? |
40 |
|
_DatabaseError = Error |
41 |
|
|
42 |
|
|
43 |
|
# We don't do connections (we are connectionless) |
44 |
|
def connect(self, connectData={}): |
45 |
|
try: |
46 |
|
GDebug.printMesg(3,'Open file: %s' % (connectData['directory']+connectData['dbname'])) |
47 |
|
self._dataConnection = dbf.dbf(connectData['directory']+\ |
48 |
|
connectData['dbname']) |
49 |
|
except IOError: |
50 |
|
tmsg = _('DBF file not found.') |
51 |
|
raise self._DatabaseError, tmsg |
52 |
|
except TypeError: |
53 |
|
tmsg = _('Wrong file format.') |
54 |
|
raise self._DatabaseError, tmsg |
55 |
|
|
56 |
|
# build field list |
57 |
|
self._fieldReferences=[] |
58 |
|
for f in self._dataConnection.fields: |
59 |
|
self._fieldReferences.append(string.lower(f[0])) |
60 |
|
|