/[gnue]/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
ViewVC logotype

Diff of /gnue-common/src/datasources/drivers/interbase/interbase/Connection.py

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

revision 1.1 by jcater, Fri Oct 10 01:21:19 2003 UTC revision 1.2 by jcater, Tue Nov 25 17:01:37 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    # interbase/DBdriver.py
23    #
24    # DESCRIPTION:
25    # Driver to provide access to data via the Kinterbasdb Interbase/Firebird Python Driver
26    # Requires Kinterbasdb > 3.0 (http://kinterbasdb.sourceforge.net/)
27    #
28    # NOTES:
29    #
30    #   Supported attributes (via connections.conf or <database> tag)
31    #
32    #     host=      This is the Interbase host for your connection  (required)
33    #     dbame=      This is the Interbase database to use (required)
34    #
35    
36    __all__ = ['Connection']
37    
38    from string import upper, lower, rstrip
39    import sys
40    from gnue.common.datasources import GDataObjects, GConditions, GConnections
41    from gnue.common.apps import GDebug
42    from gnue.common.datasources.drivers import DBSIG2
43    from DataObject import *
44    from gnue.common.datasources.drivers.interbase.Schema.Discovery.Introspection import Introspection
45    
46    
47    try:
48      import kinterbasdb as SIG2api
49    except ImportError, message:
50      tmsg = _("Driver not installed: Kinterbasdb for Interbase [%s]") % message
51      raise GConnections.AdapterNotInstalled, tmsg
52    
53    
54    ######################################################################
55    #
56    #  GConnection object for Interbase drivers
57    #
58    class Connection(DBSIG2.Connection):
59    
60      defaultBehavior = Introspection
61      _DatabaseError = SIG2api.DatabaseError
62      supportedDataObjects = {
63        'object': DataObject_Object,
64        'sql':    DataObject_SQL
65      }
66      # The date/time format used in insert/select statements
67      # (based on format used for time.strftime())
68      _dateTimeFormat = "cast('%Y-%m-%d %H:%M:%S' as timestamp)"
69    
70      def connect(self, connectData={}):
71        GDebug.printMesg(1,"Interbase database driver initializing")
72    
73        try:
74          charset = connectData['charset']
75        except KeyError:
76          charset = ""
77    
78        try:
79          self.native = SIG2api.connect( \
80                     user=str(connectData['_username']), \
81                     password=str(connectData['_password']), \
82                     charset=charset, \
83                     database=connectData['dbname'], \
84                     host=connectData['host'])
85        except self._DatabaseError, value:
86          raise GDataObjects.LoginError, value
87    
88        self._postConnect()
89    
90    
91      # Return the current date, according to database
92      def getTimeStamp(self):
93        return self.__singleQuery("select cast('now' as date) from rdb$database")
94    
95      # Return a sequence number from sequence 'name'
96      def getSequence(self, name):
97        return self.__singleQuery("select gen_id(%s,1) from rdb$database" % name)
98    
99      # Run the SQL statement 'statement'
100      def sql(self, statement):
101        cursor = self.__connection.cursor()
102        try:
103          cursor.execute(statement)
104          cursor.close()
105        except:
106          cursor.close()
107          raise
108    
109      # Used internally
110      def __singleQuery(self, statement):
111        cursor = self.__connection.cursor()
112        try:
113          cursor.execute(statement)
114          rv = cursor.fetchone()
115          cursor.close()
116        except mesg:
117          GDebug.printMesg(1,"**** Unable to execute extension query")
118          GDebug.printMesg(1,"**** %s" % mesg)
119          cursor.close()
120          return None
121    
122        try:
123          return rv[0]
124        except:
125          return None

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