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 2000-2005 Free Software Foundation
22
# informix/DBdriver.py
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)
31
# dbame= This is the Informix database to use (required)
32
# host= This is the Informix host for your connection (optional)
35
#### THIS IS AN UNTESTED DRIVER ####
36
#### Any volunteers? ####
39
from string import lower
41
from gnue.common.datasources import GDataObjects, GConditions
42
from gnue.common.apps import GDebug
43
from gnue.common.datasources.drivers import DBSIG2
45
raise "This data driver has not been upgraded to the new format."
48
import informixdb as SIG2api
51
class Informix_RecordSet(DBSIG2.RecordSet):
55
class Informix_ResultSet(DBSIG2.ResultSet):
56
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
57
DBSIG2.ResultSet.__init__(self, dataObject, \
58
cursor, defaultValues, masterRecordSet)
59
self._recordSetClass = Informix_RecordSet
60
self._uniqueIdField = "__GNUeF__uniqueKey_%s" % (self._dataObject.table)
61
self._uniqueIdFormat = "ROWID='%s'"
65
class Informix_DataObject(DBSIG2.DataObject):
67
DBSIG2.DataObject.__init__(self)
68
self._DatabaseError = SIG2api.DatabaseError
69
self._resultSetClass = Informix_ResultSet
72
def connect(self, connectData={}):
73
GDebug.printMesg(9,"Informix database driver initializing")
75
if connectData.has_key('host') and len(connectData['host']):
76
db = connectData['dbname'] + "@" + connectData['host']
78
db = connectData['dbname']
79
self._dataConnection = SIG2api.connect( \
80
dbname=connectData['dbname'], \
81
user=connectData['_username'], \
82
passwd=connectData['_password'])
83
except self._DatabaseError, value:
84
raise GDataObjects.LoginError, value
91
# Schema (metadata) functions
94
# TODO: See postgresql for an example of what these functions do.
96
# Return a list of the types of Schema objects this driver provides
97
def getSchemaTypes(self):
98
return [('view',_('Views'),1),
99
('table',_('Tables'),1)]
101
# Return a list of Schema objects
102
def getSchemaList(self, type=None):
105
# Find a schema object with specified name
106
def getSchemaByName(self, name, type=None):
109
def _postConnect(self):
110
self.triggerExtensions = TriggerExtensions(self._dataConnection)
113
class Informix_DataObject_Object(Informix_DataObject, \
114
DBSIG2.DataObject_Object):
117
Informix_DataObject.__init__(self)
119
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
120
return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
123
class Informix_DataObject_SQL(Informix_DataObject, \
124
DBSIG2.DataObject_SQL):
126
# Call DBSIG init first because Informix_DataObject needs to overwrite
128
DBSIG2.DataObject_SQL.__init__(self)
129
Informix_DataObject.__init__(self)
131
def _buildQuery(self, conditions={}):
132
return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
136
# Extensions to Trigger Namespaces
138
class TriggerExtensions:
140
def __init__(self, connection):
141
self.__connection = connection
146
######################################
148
# The following hashes describe
149
# this driver's characteristings.
151
######################################
154
# All datasouce "types" and corresponding DataObject class
156
supportedDataObjects = {
157
'object': Informix_DataObject_Object,
158
'sql': Informix_DataObject_SQL