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

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

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

revision 1.1 by jcater, Fri Oct 10 01:21:35 2003 UTC revision 1.2 by jcater, Tue Nov 25 17:01:47 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    # sybase/DBdriver.py
23    #
24    # DESCRIPTION:
25    # Driver to provide access to data via Dave Cole's Sybase ASE/Python Driver
26    # Requires Sybase.py (http://www.object-craft.com.au/projects/sybase/)
27    #
28    # NOTES:
29    #
30    #   Supported attributes (via connections.conf or <database> tag)
31    #
32    #     service=    This is the Sybase DSN for your connection  (required)
33    #     dbame=      This is the Sybase database to use (optional)
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      import Sybase as SIG2api
50    except ImportError, message:
51      tmsg = _("Driver not installed: Sybase.py for Sybase ASE 11.0/11.9 [%s]") % message
52      raise GConnections.AdapterNotInstalled, tmsg
53    
54    
55    class Sybase_RecordSet(DBSIG2.RecordSet):
56      pass
57    
58    
59    class Sybase_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 = Sybase_RecordSet
64    
65    
66    
67    class Sybase_DataObject(DBSIG2.DataObject):
68      def __init__(self):
69        DBSIG2.DataObject.__init__(self)
70        self._DatabaseError = SIG2api.DatabaseError
71        self._resultSetClass = Sybase_ResultSet
72    
73    
74      def connect(self, connectData={}):
75        GDebug.printMesg(1,"Sybase database driver initializing")
76        try:
77          if connectData.has_key('dbname'):
78            self._dataConnection = SIG2api.connect( \
79                      service=connectData['service'],  \
80                      user=connectData['_username'], \
81                      passwd=connectData['_password'], \
82                      datbase=connectData['dbname'])
83          else:
84            self._dataConnection = SIG2api.connect( \
85                      service=connectData['service'],  \
86                      user=connectData['_username'], \
87                      passwd=connectData['_password'])
88        except self._DatabaseError, value:
89          raise GDataObjects.LoginError, value
90    
91        self._postConnect()
92    
93    
94    
95      #
96      # Schema (metadata) functions
97      #
98    
99      # TODO: See postgresql for an example of what these functions do.
100    
101      # Return a list of the types of Schema objects this driver provides
102      def getSchemaTypes(self):
103        return [('view',_('Views'),1),
104                ('table',_('Tables'),1)]
105    
106      # Return a list of Schema objects
107      def getSchemaList(self, type=None):
108        return []
109    
110      # Find a schema object with specified name
111      def getSchemaByName(self, name, type=None):
112        return None
113    
114      def _postConnect(self):
115        self.triggerExtensions = TriggerExtensions(self._dataConnection)
116    
117    
118    class Sybase_DataObject_Object(Sybase_DataObject, \
119          DBSIG2.DataObject_Object):
120    
121      def __init__(self):
122        Sybase_DataObject.__init__(self)
123    
124      def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
125        return DBSIG2.DataObject_Object._buildQuery(self, conditions,forDetail,additionalSQL)
126    
127    
128    class Sybase_DataObject_SQL(Sybase_DataObject, \
129          DBSIG2.DataObject_SQL):
130      def __init__(self):
131        # Call DBSIG init first because Sybase_DataObject needs to overwrite
132        # some of its values
133        DBSIG2.DataObject_SQL.__init__(self)
134        Sybase_DataObject.__init__(self)
135    
136      def _buildQuery(self, conditions={}):
137        return DBSIG2.DataObject_SQL._buildQuery(self, conditions)
138    
139    
140    #
141    #  Extensions to Trigger Namespaces
142    #
143    class TriggerExtensions:
144    
145      def __init__(self, connection):
146        self.__connection = connection
147    
148    
149    
150    
151    ######################################
152    #
153    #  The following hashes describe
154    #  this driver's characteristings.
155    #
156    ######################################
157    
158    #
159    #  All datasouce "types" and corresponding DataObject class
160    #
161    supportedDataObjects = {
162      'object': Sybase_DataObject_Object,
163      'sql':    Sybase_DataObject_SQL
164    }
165    

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