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 |
|
# SQLRelay/DBdriver.py |
23 |
|
# |
24 |
|
# DESCRIPTION: |
25 |
|
# Driver to provide access to data via SQLRelay's Python Driver |
26 |
|
# Requires SQLRelay + Python-DB Driver (http://www.firstworks.com/sqlrelay) |
27 |
|
# |
28 |
|
# NOTES: |
29 |
|
# |
30 |
|
# Supported attributes (via connections.conf or <database> tag) |
31 |
|
# |
32 |
|
# host= This is the SQLRelay host for your connection (required) |
33 |
|
# In the format hostname:port (or ipaddr:port) |
34 |
|
# |
35 |
|
|
36 |
|
__all__ = ['Connection'] |
37 |
|
|
38 |
|
#### THIS IS AN UNTESTED DRIVER #### |
39 |
|
#### Any volunteers? #### |
40 |
|
|
41 |
|
|
42 |
|
from string import lower |
43 |
|
import sys |
44 |
|
from gnue.common.datasources import GDataObjects, GConditions, GConnections |
45 |
|
from gnue.common.apps import GDebug |
46 |
|
from gnue.common.datasources.drivers import DBSIG2 |
47 |
|
|
48 |
|
try: |
49 |
|
from SQLRelay import PySQLRDB as SIG2api |
50 |
|
except ImportError, message: |
51 |
|
tmsg = _("Driver not installed: SQLRelay Python API\n[%s]") % message |
52 |
|
raise GConnections.AdapterNotInstalled, tmsg |
53 |
|
|
54 |
|
|
55 |
|
from gnue.common.datasources.drivers.sqlrelay.Schema.Discovery.Introspection import Introspection |
56 |
|
|
57 |
|
|
58 |
|
###################################################################### |
59 |
|
# |
60 |
|
# GConnection object for PostgreSQL-based drivers |
61 |
|
# |
62 |
|
class Connection(DBSIG2.Connection): |
63 |
|
|
64 |
|
defaultBehavior = Introspection |
65 |
|
_DatabaseError = SIG2api.DatabaseError |
66 |
|
supportedDataObjects = { |
67 |
|
'object': DataObject_Object, |
68 |
|
'sql': DataObject_SQL |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
def connect(self, connectData={}): |
73 |
|
GDebug.printMesg(1,"SQLRelay database driver initializing") |
74 |
|
|
75 |
|
try: |
76 |
|
host, port = string.split(connectData['host'],':') |
77 |
|
port = int(port) |
78 |
|
except ValueError: |
79 |
|
host = connectData['host'] |
80 |
|
port = 9000 |
81 |
|
|
82 |
|
try: |
83 |
|
self.native = SIG2api.connect( host, port, '', \ |
84 |
|
connectData['_username'], \ |
85 |
|
connectData['_password'], \ |
86 |
|
0,1) |
87 |
|
except self._DatabaseError, value: |
88 |
|
raise GDataObjects.LoginError, value |
89 |
|
|
90 |
|
|