/[gnue]/gnue-common/src/datasources/drivers/sqlrelay/sqlrelay/DataObject.py
ViewVC logotype

Diff of /gnue-common/src/datasources/drivers/sqlrelay/sqlrelay/DataObject.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jcater, Fri Oct 10 01:21:34 2003 UTC revision 1.2 by jcater, Tue Nov 25 17:01:46 2003 UTC
# Line 0  Line 1 
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    #### 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.DBSIG2.Driver \
45       import DBSIG2.RecordSet, DBSIG2.ResultSet, DBSIG2.DataObject, \
46              DBSIG2.DataObject_SQL, DBSIG2.DataObject_Object
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    class SQLRelay_RecordSet(DBSIG2.RecordSet):
56      pass
57    
58    
59    class SQLRelay_ResultSet(DBSIG2.ResultSet):
60      def __init__(self, dataObject, cursor=None, defaultValues={}, masterRecordSet=None):
61        DBSIG2.ResultSet.__init__(self, dataObject, \
62                cursor, defaultValues, masterRecordSet)
63        self._recordSetClass = SQLRelay_RecordSet
64    
65    
66    
67    class SQLRelay_DataObject(DBSIG2.DataObject):
68      def __init__(self):
69        DBSIG2.DataObject.__init__(self)
70        self._DatabaseError = SIG2api.DatabaseError
71        self._resultSetClass = SQLRelay_ResultSet
72    
73    
74      def connect(self, connectData={}):
75        GDebug.printMesg(1,"SQLRelay database driver initializing")
76    
77        try:
78          host, port = string.split(connectData['host'],':')
79          port = int(port)
80        except ValueError:
81          host = connectData['host']
82          port = 9000
83    
84        try:
85          self._dataConnection = SIG2api.connect( host, port, '', \
86                       connectData['_username'], \
87                       connectData['_password'], \
88                       0,1)
89        except self._DatabaseError, value:
90          raise GDataObjects.LoginError, value
91    
92        self._postConnect()
93    
94    
95    
96      #
97      # Schema (metadata) functions
98      #
99    
100      # TODO: See postgresql for an example of what these functions do.
101    
102      # Return a list of the types of Schema objects this driver provides
103      def getSchemaTypes(self):
104        return [('view',_('Views'),1),
105                ('table',_('Tables'),1)]
106    
107      # Return a list of Schema objects
108      def getSchemaList(self, type=None):
109        return []
110    
111      # Find a schema object with specified name
112      def getSchemaByName(self, name, type=None):
113        return None
114    
115      def _postConnect(self):
116        self.triggerExtensions = TriggerExtensions(self._dataConnection)
117    
118    
119    class SQLRelay_DataObject_Object(SQLRelay_DataObject, \
120          DBSIG2.DataObject_Object):
121    
122      def __init__(self):
123        SQLRelay_DataObject.__init__(self)
124    
125      def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
126        return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
127    
128    
129    class SQLRelay_DataObject_SQL(SQLRelay_DataObject, \
130          DBSIG2.DataObject_SQL):
131      def __init__(self):
132        # Call DBSIG init first because SQLRelay_DataObject needs to overwrite
133        # some of its values
134        DBSIG2.DataObject_SQL.__init__(self)
135        SQLRelay_DataObject.__init__(self)
136    
137      def _buildQuery(self, conditions={}):
138        return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
139    
140    
141    #
142    #  Extensions to Trigger Namespaces
143    #
144    class TriggerExtensions:
145    
146      def __init__(self, connection):
147        self.__connection = connection
148    
149    
150    
151    
152    
153    ######################################
154    #
155    #  The following hashes describe
156    #  this driver's characteristings.
157    #
158    ######################################
159    
160    #
161    #  All datasouce "types" and corresponding DataObject class
162    #
163    supportedDataObjects = {
164      'object': SQLRelay_DataObject_Object,
165      'sql':    SQLRelay_DataObject_SQL
166    }
167    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26