~ubuntu-branches/ubuntu/hardy/gnue-common/hardy

« back to all changes in this revision

Viewing changes to src/datasources/drivers/sqlrelay/sqlrelay/RecordSet.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-03-09 11:06:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050309110631-8gvvn39q7tjz1kj6
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2005 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
#### THIS IS AN UNTESTED DRIVER ####
 
37
####      Any volunteers?       ####
 
38
 
 
39
 
 
40
from string import lower
 
41
import sys
 
42
from gnue.common.datasources import GDataObjects, GConditions, GConnections
 
43
from gnue.common.apps import GDebug
 
44
from gnue.common.datasources.drivers import DBSIG2
 
45
 
 
46
raise "This data driver has not been upgraded to the new format."
 
47
 
 
48
 
 
49
try:
 
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
 
54
 
 
55
 
 
56
class SQLRelay_RecordSet(DBSIG2.RecordSet):
 
57
  pass
 
58
 
 
59
 
 
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
 
65
 
 
66
 
 
67
 
 
68
class SQLRelay_DataObject(DBSIG2.DataObject):
 
69
  def __init__(self):
 
70
    DBSIG2.DataObject.__init__(self)
 
71
    self._DatabaseError = SIG2api.DatabaseError
 
72
    self._resultSetClass = SQLRelay_ResultSet
 
73
 
 
74
 
 
75
  def connect(self, connectData={}):
 
76
    GDebug.printMesg(9,"SQLRelay database driver initializing")
 
77
 
 
78
    try: 
 
79
      host, port = string.split(connectData['host'],':')
 
80
      port = int(port)
 
81
    except ValueError: 
 
82
      host = connectData['host']
 
83
      port = 9000
 
84
 
 
85
    try:
 
86
      self._dataConnection = SIG2api.connect( host, port, '', \
 
87
                   connectData['_username'], \
 
88
                   connectData['_password'], \
 
89
                   0,1)
 
90
    except self._DatabaseError, value:
 
91
      raise GDataObjects.LoginError, value
 
92
 
 
93
    self._postConnect()
 
94
 
 
95
 
 
96
 
 
97
  #
 
98
  # Schema (metadata) functions
 
99
  #
 
100
 
 
101
  # TODO: See postgresql for an example of what these functions do.
 
102
 
 
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)]
 
107
 
 
108
  # Return a list of Schema objects
 
109
  def getSchemaList(self, type=None):
 
110
    return []
 
111
 
 
112
  # Find a schema object with specified name
 
113
  def getSchemaByName(self, name, type=None):
 
114
    return None
 
115
 
 
116
  def _postConnect(self):
 
117
    self.triggerExtensions = TriggerExtensions(self._dataConnection)
 
118
 
 
119
 
 
120
class SQLRelay_DataObject_Object(SQLRelay_DataObject, \
 
121
      DBSIG2.DataObject_Object):
 
122
 
 
123
  def __init__(self):
 
124
    SQLRelay_DataObject.__init__(self)
 
125
 
 
126
  def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
 
127
    return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
 
128
 
 
129
 
 
130
class SQLRelay_DataObject_SQL(SQLRelay_DataObject, \
 
131
      DBSIG2.DataObject_SQL):
 
132
  def __init__(self):
 
133
    # Call DBSIG init first because SQLRelay_DataObject needs to overwrite
 
134
    # some of its values
 
135
    DBSIG2.DataObject_SQL.__init__(self)
 
136
    SQLRelay_DataObject.__init__(self)
 
137
 
 
138
  def _buildQuery(self, conditions={}):
 
139
    return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
 
140
 
 
141
 
 
142
#
 
143
#  Extensions to Trigger Namespaces
 
144
#
 
145
class TriggerExtensions:
 
146
 
 
147
  def __init__(self, connection):
 
148
    self.__connection = connection
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
######################################
 
155
#
 
156
#  The following hashes describe
 
157
#  this driver's characteristings.
 
158
#
 
159
######################################
 
160
 
 
161
#
 
162
#  All datasouce "types" and corresponding DataObject class
 
163
#
 
164
supportedDataObjects = {
 
165
  'object': SQLRelay_DataObject_Object,
 
166
  'sql':    SQLRelay_DataObject_SQL
 
167
}
 
168