commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5836 - in trunk/gnue-common/src/datasources/drivers: DBSIG2 interbase/i


From: johannes
Subject: r5836 - in trunk/gnue-common/src/datasources/drivers: DBSIG2 interbase/interbase
Date: Thu, 27 May 2004 09:52:01 -0500 (CDT)

Author: johannes
Date: 2004-05-27 09:52:00 -0500 (Thu, 27 May 2004)
New Revision: 5836

Modified:
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
   trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
Log:
Fixed handling of booleans in dbsig2.connection and fixed transaction-handling 
in interbase/firebird driver


Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2004-05-26 17:55:09 UTC (rev 5835)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2004-05-27 14:52:00 UTC (rev 5836)
@@ -30,6 +30,7 @@
 #
 # HISTORY:
 #
+# $Id$
 
 __all__ = ['Connection']
 
@@ -57,12 +58,14 @@
       (defaults to '0')
   @param _boolean_true: Value to post to the database for boolean TRUE
       (defaults to '1')
+  @param _numbers_as_string: Flags wether to convert numbers to strings or not
   """
   _driver = None                        # DBSIG2 compatible driver module
   _boolean_false = '0'                  # value to pass for boolean FALSE
   _boolean_true  = '1'                  # value to pass for boolean TRUE
   _broken_fetchmany = False             # Does fetchmany () raise an exception
                                         # when no records are left?
+  _numbers_as_string = True             # Convert numbers into strings
 
   # This should be over-ridden only if driver needs more than user/pass
   def getLoginFields(self):
@@ -73,6 +76,7 @@
 
     try:
       self.native.commit()
+      
     except self._DatabaseError, value:
       raise Exceptions.ConnectionError, value
 
@@ -123,23 +127,30 @@
       # Unicode: return encoded string
       return value.encode (self._encoding)
 
+    elif sys.hexversion >= 0x02030000 and isinstance (value, BooleanType):
+      # Booleans (Python 2.3 and later)
+      if value:
+        return self._boolean_true
+      else:
+        return self._boolean_false
+
     elif isinstance (value, IntType):
       # Sometimes (sigh), IntType is used for booleans. Some datbases (e.g.
       # postgres) want boolean 0 and 1 values as strings.
       # Can be removed as soon as we require Python 2.3
-      return str (value)
+      if self._numbers_as_string:
+        return str (value)
+      else:
+        return value
+    
 
     elif isinstance (value, FloatType):
       # Some databases (especially postgres) want floating point numbers
       # passed as strings
-      return str (value)
-
-    elif sys.hexversion >= 0x02030000 and isinstance (value, BooleanType):
-      # Booleans (Python 2.3 and later)
-      if value:
-        return self._boolean_true
+      if self._numbers_as_string:
+        return str (value)
       else:
-        return self._boolean_false
+        return value
 
     elif isinstance (value, mx.DateTime.DateTimeType):
       # mx.DateTime
@@ -233,6 +244,7 @@
     """
     checktype (statement, [StringType, UnicodeType])
     checktype (parameters, [DictionaryType, NoneType])
+
     if parameters:
       for (parameters_key, parameters_value) in parameters.items ():
         checktype (parameters_key, [StringType, UnicodeType])
@@ -264,13 +276,15 @@
 
     gDebug (1, "DBSIG2 Statement: %s" % s)
     gDebug (1, "DBSIG2 Parameters: %s" % p)
+
     # Create DBSIG2 cursor and execute statement
     try:
       cursor = self.native.cursor ()
-      if p:
+      if p is not None:
         cursor.execute (s, p)
       else:
         cursor.execute (s)
+
     except:
       (exc_type, exc_value, exc_traceback) = sys.exc_info ()
       try:
@@ -278,6 +292,7 @@
       except:
         pass
       raise exc_type, exc_value, exc_traceback
+
     return cursor
 
   # ---------------------------------------------------------------------------
@@ -302,8 +317,12 @@
       result = cursor.fetchall ()
     except:
       pass
-    cursor.close ()
 
+    try:
+      cursor.close ()
+    except:
+      pass
+
     if result:
       return result
     else:


Property changes on: 
trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py 
2004-05-26 17:55:09 UTC (rev 5835)
+++ trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py 
2004-05-27 14:52:00 UTC (rev 5836)
@@ -32,6 +32,7 @@
 #     host=      This is the Interbase host for your connection  (required)
 #     dbame=      This is the Interbase database to use (required)
 #
+# $Id$
 
 __all__ = ['Connection']
 
@@ -59,11 +60,14 @@
 #
 #  GConnection object for Interbase drivers
 #
-class Connection(DBSIG2.Connection):
+class Connection (DBSIG2.Connection):
 
-  defaultBehavior = Introspection
-  _driver = SIG2api
-  _DatabaseError = SIG2api.DatabaseError
+  _boolean_true      = 1
+  _boolean_false     = 0
+  _numbers_as_string = False
+  defaultBehavior    = Introspection
+  _driver            = SIG2api
+  _DatabaseError     = SIG2api.DatabaseError
   supportedDataObjects = {
     'object': DataObject_Object,
     'sql':    DataObject_SQL
@@ -72,56 +76,99 @@
   # (based on format used for time.strftime())
   _dateTimeFormat = "cast('%Y-%m-%d %H:%M:%S' as timestamp)"
 
+  # ---------------------------------------------------------------------------
+  # Establish a new connection
+  # ---------------------------------------------------------------------------
+
   def connect(self, connectData={}):
-    GDebug.printMesg(1,"Interbase database driver initializing")
 
+    GDebug.printMesg (1, "Interbase database driver initializing")
+
     try:
-      ib_encoding = ib_encTable[self._encoding]
+      ib_encoding = ib_encTable [self._encoding]
+
     except KeyError:
-      GDebug.printMesg(1,_("Encoding '%s' is not supported by interbase 
dbdriver.") % \
-                       self._encoding + _('Using default encoding.'))
+      GDebug.printMesg (1, u_("Encoding '%s' is not supported by interbase "
+                              "dbdriver. Using default encoding.") % \
+                              self._encoding)
       ib_encoding = ''
 
     if ib_encoding:
-      GDebug.printMesg(1,'Setting interbase client_encoding to %s (%s)' % 
(ib_encoding,self._encoding))
+      GDebug.printMesg (1, u_("Setting interbase client_encoding to %s (%s)" \
+                           % (ib_encoding, self._encoding)))
 
     try:
-      self.native = SIG2api.connect( \
-                 user=str(connectData['_username']), \
-                 password=str(connectData['_password']), \
-                 charset=ib_encoding, \
-                 database=connectData['dbname'], \
-                 host=connectData['host'])
+      self.native = SIG2api.connect ( \
+                            user     = str (connectData ['_username']), \
+                            password = str (connectData ['_password']), \
+                            charset  = ib_encoding,                     \
+                            database = connectData ['dbname'],          \
+                            host     = connectData ['host'])
+
+      # automatically start a new transaction
+      self._beginTransaction ()
+
     except self._DatabaseError, value:
       raise GDataObjects.LoginError, value
 
 
+  # ---------------------------------------------------------------------------
+  # Start a new transaction
+  # ---------------------------------------------------------------------------
+
+  def _beginTransaction (self):
+    self.native.begin ()
+
+
+  # ---------------------------------------------------------------------------
   # Return the current date, according to database
-  def getTimeStamp(self):
-    return self.__singleQuery("select cast('now' as date) from rdb$database")
+  # ---------------------------------------------------------------------------
 
+  def getTimeStamp (self):
+    return self.__singleQuery ("SELECT CAST('now' AS DATE) FROM rdb$database")
+
+
+  # ---------------------------------------------------------------------------
   # Return a sequence number from sequence 'name'
-  def getSequence(self, name):
-    return self.__singleQuery("select gen_id(%s,1) from rdb$database" % name)
+  # ---------------------------------------------------------------------------
 
-  # Used internally
-  def __singleQuery(self, statement):
-    cursor = self.native.cursor()
+  def getSequence (self, name):
+    return self.__singleQuery ("SELECt gen_id(%s,1) FROM rdb$database" % name)
+
+
+  # ---------------------------------------------------------------------------
+  # Execute an SQL statement for internal use only
+  # ---------------------------------------------------------------------------
+
+  def __singleQuery (self, statement):
+    cursor = self.native.cursor ()
+
     try:
-      cursor.execute(statement)
-      rv = cursor.fetchone()
-      cursor.close()
+      cursor.execute (statement)
+      rv = cursor.fetchone ()
+      cursor.close ()
+
     except mesg:
-      GDebug.printMesg(1,"**** Unable to execute extension query")
-      GDebug.printMesg(1,"**** %s" % mesg)
-      cursor.close()
+      GDebug.printMesg (1, "**** Unable to execute extension query")
+      GDebug.printMesg (1, "**** %s" % mesg)
+
+      try:
+        cursor.close ()
+
+      except:
+        pass
+
       return None
 
     try:
-      return rv[0]
+      return rv [0]
+
     except:
       return None
-
+
+
+
+
 # RDB$CHARACTER_SETS.RDB$CHARACTER_SET_NAME
 ib_encTable =  {'ascii'     :  'ASCII',
                 ''          :  'BIG_5',


Property changes on: 
trunk/gnue-common/src/datasources/drivers/interbase/interbase/Connection.py
___________________________________________________________________
Name: svn:keywords
   + Id





reply via email to

[Prev in Thread] Current Thread [Next in Thread]