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 |
|
# informix/DBdriver.py |
23 |
|
# |
24 |
|
# DESCRIPTION: |
25 |
|
# Driver to provide access to data via Alexander Kuznetsov's |
26 |
|
# Informix/Python Driver * Requires Kinfxdb 0.2+ |
27 |
|
# (http://thor.prohosting.com/~alexan/pub/Kinfxdb/Kinfxdb-0.2.tar.gz) |
28 |
|
# |
29 |
|
# NOTES: |
30 |
|
# |
31 |
|
# dbame= This is the Informix database to use (required) |
32 |
|
# host= This is the Informix host for your connection (optional) |
33 |
|
# |
34 |
|
|
35 |
|
#### THIS IS AN UNTESTED DRIVER #### |
36 |
|
#### Any volunteers? #### |
37 |
|
|
38 |
|
|
39 |
|
from string import lower |
40 |
|
import sys |
41 |
|
from gnue.common.datasources import GDataObjects, GConditions |
42 |
|
from gnue.common.apps import GDebug |
43 |
|
from gnue.common.datasources.drivers.DBSIG2.Driver \ |
44 |
|
import DBSIG2.RecordSet, DBSIG2.ResultSet, DBSIG2.DataObject, \ |
45 |
|
DBSIG2.DataObject_SQL, DBSIG2.DataObject_Object |
46 |
|
|
47 |
|
try: |
48 |
|
import informixdb as SIG2api |
49 |
|
except ImportError, message: |
50 |
|
tmsg = _("Driver not installed: Kinfxdb for Informix [%s]") % message |
51 |
|
raise GConnections.AdapterNotInstalled, tmsg |
52 |
|
|
53 |
|
|
54 |
|
class Informix_RecordSet(DBSIG2.RecordSet): |
55 |
|
pass |
56 |
|
|
57 |
|
|
58 |
|
class Informix_ResultSet(DBSIG2.ResultSet): |
59 |
|
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None): |
60 |
|
DBSIG2.ResultSet.__init__(self, dataObject, \ |
61 |
|
cursor, defaultValues, masterRecordSet) |
62 |
|
self._recordSetClass = Informix_RecordSet |
63 |
|
self._uniqueIdField = "__GNUeF__uniqueKey_%s" % (self._dataObject.table) |
64 |
|
self._uniqueIdFormat = "ROWID='%s'" |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
class Informix_DataObject(DBSIG2.DataObject): |
69 |
|
def __init__(self): |
70 |
|
DBSIG2.DataObject.__init__(self) |
71 |
|
self._DatabaseError = SIG2api.DatabaseError |
72 |
|
self._resultSetClass = Informix_ResultSet |
73 |
|
|
74 |
|
|
75 |
|
def connect(self, connectData={}): |
76 |
|
GDebug.printMesg(1,"Informix database driver initializing") |
77 |
|
try: |
78 |
|
if connectData.has_key('host') and len(connectData['host']): |
79 |
|
db = connectData['dbname'] + "@" + connectData['host'] |
80 |
|
else: |
81 |
|
db = connectData['dbname'] |
82 |
|
self._dataConnection = SIG2api.connect( \ |
83 |
|
dbname=connectData['dbname'], \ |
84 |
|
user=connectData['_username'], \ |
85 |
|
passwd=connectData['_password']) |
86 |
|
except self._DatabaseError, value: |
87 |
|
raise GDataObjects.LoginError, value |
88 |
|
|
89 |
|
self._postConnect() |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
# |
94 |
|
# Schema (metadata) functions |
95 |
|
# |
96 |
|
|
97 |
|
# TODO: See postgresql for an example of what these functions do. |
98 |
|
|
99 |
|
# Return a list of the types of Schema objects this driver provides |
100 |
|
def getSchemaTypes(self): |
101 |
|
return [('view',_('Views'),1), |
102 |
|
('table',_('Tables'),1)] |
103 |
|
|
104 |
|
# Return a list of Schema objects |
105 |
|
def getSchemaList(self, type=None): |
106 |
|
return [] |
107 |
|
|
108 |
|
# Find a schema object with specified name |
109 |
|
def getSchemaByName(self, name, type=None): |
110 |
|
return None |
111 |
|
|
112 |
|
def _postConnect(self): |
113 |
|
self.triggerExtensions = TriggerExtensions(self._dataConnection) |
114 |
|
|
115 |
|
|
116 |
|
class Informix_DataObject_Object(Informix_DataObject, \ |
117 |
|
DBSIG2.DataObject_Object): |
118 |
|
|
119 |
|
def __init__(self): |
120 |
|
Informix_DataObject.__init__(self) |
121 |
|
|
122 |
|
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""): |
123 |
|
return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL) |
124 |
|
|
125 |
|
|
126 |
|
class Informix_DataObject_SQL(Informix_DataObject, \ |
127 |
|
DBSIG2.DataObject_SQL): |
128 |
|
def __init__(self): |
129 |
|
# Call DBSIG init first because Informix_DataObject needs to overwrite |
130 |
|
# some of its values |
131 |
|
DBSIG2.DataObject_SQL.__init__(self) |
132 |
|
Informix_DataObject.__init__(self) |
133 |
|
|
134 |
|
def _buildQuery(self, conditions={}): |
135 |
|
return DBSIG2.DataObject_SQL._buildQuery(self, conditions) |
136 |
|
|
137 |
|
|
138 |
|
# |
139 |
|
# Extensions to Trigger Namespaces |
140 |
|
# |
141 |
|
class TriggerExtensions: |
142 |
|
|
143 |
|
def __init__(self, connection): |
144 |
|
self.__connection = connection |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
###################################### |
150 |
|
# |
151 |
|
# The following hashes describe |
152 |
|
# this driver's characteristings. |
153 |
|
# |
154 |
|
###################################### |
155 |
|
|
156 |
|
# |
157 |
|
# All datasouce "types" and corresponding DataObject class |
158 |
|
# |
159 |
|
supportedDataObjects = { |
160 |
|
'object': Informix_DataObject_Object, |
161 |
|
'sql': Informix_DataObject_SQL |
162 |
|
} |
163 |
|
|