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
# SQLRelay/DBdriver.py
25
# Driver to provide access to data via SQLRelay's Python Driver
26
# Requires SQLRelay + Python-DB Driver (http://www.firstworks.com/sqlrelay)
30
# Supported attributes (via connections.conf or <database> tag)
32
# host= This is the SQLRelay host for your connection (required)
33
# In the format hostname:port (or ipaddr:port)
36
#### THIS IS AN UNTESTED DRIVER ####
37
#### Any volunteers? ####
40
from string import lower
42
from gnue.common.datasources import GDataObjects, GConditions, GConnections
43
from gnue.common.apps import GDebug
44
from gnue.common.datasources.drivers import DBSIG2
46
raise "This data driver has not been upgraded to the new format."
50
from SQLRelay import PySQLRDB as SIG2api
51
except ImportError, message:
52
tmsg = u_("Driver not installed: SQLRelay Python API\n[%s]") % message
53
raise GConnections.AdapterNotInstalled, tmsg
56
class SQLRelay_RecordSet(DBSIG2.RecordSet):
60
class SQLRelay_ResultSet(DBSIG2.ResultSet):
61
def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
62
DBSIG2.ResultSet.__init__(self, dataObject, \
63
cursor, defaultValues, masterRecordSet)
64
self._recordSetClass = SQLRelay_RecordSet
68
class SQLRelay_DataObject(DBSIG2.DataObject):
70
DBSIG2.DataObject.__init__(self)
71
self._DatabaseError = SIG2api.DatabaseError
72
self._resultSetClass = SQLRelay_ResultSet
75
def connect(self, connectData={}):
76
GDebug.printMesg(9,"SQLRelay database driver initializing")
79
host, port = string.split(connectData['host'],':')
82
host = connectData['host']
86
self._dataConnection = SIG2api.connect( host, port, '', \
87
connectData['_username'], \
88
connectData['_password'], \
90
except self._DatabaseError, value:
91
raise GDataObjects.LoginError, value
98
# Schema (metadata) functions
101
# TODO: See postgresql for an example of what these functions do.
103
# Return a list of the types of Schema objects this driver provides
104
def getSchemaTypes(self):
105
return [('view',_('Views'),1),
106
('table',_('Tables'),1)]
108
# Return a list of Schema objects
109
def getSchemaList(self, type=None):
112
# Find a schema object with specified name
113
def getSchemaByName(self, name, type=None):
116
def _postConnect(self):
117
self.triggerExtensions = TriggerExtensions(self._dataConnection)
120
class SQLRelay_DataObject_Object(SQLRelay_DataObject, \
121
DBSIG2.DataObject_Object):
124
SQLRelay_DataObject.__init__(self)
126
def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
127
return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
130
class SQLRelay_DataObject_SQL(SQLRelay_DataObject, \
131
DBSIG2.DataObject_SQL):
133
# Call DBSIG init first because SQLRelay_DataObject needs to overwrite
135
DBSIG2.DataObject_SQL.__init__(self)
136
SQLRelay_DataObject.__init__(self)
138
def _buildQuery(self, conditions={}):
139
return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
143
# Extensions to Trigger Namespaces
145
class TriggerExtensions:
147
def __init__(self, connection):
148
self.__connection = connection
154
######################################
156
# The following hashes describe
157
# this driver's characteristings.
159
######################################
162
# All datasouce "types" and corresponding DataObject class
164
supportedDataObjects = {
165
'object': SQLRelay_DataObject_Object,
166
'sql': SQLRelay_DataObject_SQL