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 2000-2003 Free Software Foundation |
20 |
|
# |
21 |
|
# FILE: |
22 |
|
# db2/Connection.py |
23 |
|
# |
24 |
|
# DESCRIPTION: |
25 |
|
# Driver to provide access to data stored in a DB2 database |
26 |
|
# |
27 |
|
# NOTES: |
28 |
|
# |
29 |
|
|
30 |
|
__all__ = ['Connection'] |
31 |
|
|
32 |
|
import string |
33 |
|
import sys |
34 |
|
|
35 |
|
from string import lower |
36 |
|
# from gnue.forms import GFOptions |
37 |
|
from gnue.forms.GFError import DBError |
38 |
|
from gnue.common.apps import GDebug |
39 |
|
from gnue.common.datasources import GDataObjects |
40 |
|
from gnue.common.datasources.drivers import DBSIG2 |
41 |
|
|
42 |
|
try: |
43 |
|
import DB2 |
44 |
|
except ImportError, message: |
45 |
|
tmsg = _("Driver not installed: db2 for DB2 [%s]") % message |
46 |
|
raise GConnections.AdapterNotInstalled, tmsg |
47 |
|
|
48 |
|
from gnue.common.datasources.drivers.sqlite.Schema.Discovery.Introspection import Introspection |
49 |
|
|
50 |
|
class Connection(DBSIG2.DataObject): |
51 |
|
_DatabaseError = "Database Error" |
52 |
|
defaultBehavior = Introspection |
53 |
|
supportedDataObjects = { |
54 |
|
'object': DBSIG2.DataObject_Object, |
55 |
|
'sql': DBSIG2.DataObject_SQL |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
def connect(self, connectData={}): |
60 |
|
GDebug.printMesg(1,"DB2 database driver initializing") |
61 |
|
try: |
62 |
|
self.native = DB2.connect(uid=connectData['_username'], |
63 |
|
pwd=connectData['_password'], |
64 |
|
dsn=connectData['service']) |
65 |
|
except self._DatabaseError, value: |
66 |
|
raise GDataObjects.LoginError, value |
67 |
|
|