commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnue-common/src GConnections.py dbdrivers/...


From: Jason Cater
Subject: gnue/gnue-common/src GConnections.py dbdrivers/...
Date: Sun, 04 Nov 2001 18:25:02 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/11/04 18:25:02

Modified files:
        gnue-common/src: GConnections.py 
        gnue-common/src/dbdrivers/odbc: DBdriver.py 

Log message:
        finished (I hope) support for ODBC; misc fixes

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GConnections.py.diff?cvsroot=OldCVS&tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.6&tr2=1.7&r1=text&r2=text

Patches:
Index: gnue/gnue-common/src/GConnections.py
diff -u gnue/gnue-common/src/GConnections.py:1.21 
gnue/gnue-common/src/GConnections.py:1.22
--- gnue/gnue-common/src/GConnections.py:1.21   Sun Nov  4 17:13:33 2001
+++ gnue/gnue-common/src/GConnections.py        Sun Nov  4 18:25:02 2001
@@ -1,19 +1,19 @@
 #
 # This file is part of GNU Enterprise.
 #
-# GNU Enterprise is free software; you can redistribute it 
-# and/or modify it under the terms of the GNU General Public 
-# License as published by the Free Software Foundation; either 
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
 # version 2, or (at your option) any later version.
 #
-# GNU Enterprise is distributed in the hope that it will be 
-# useful, but WITHOUT ANY WARRANTY; without even the implied 
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 # PURPOSE. See the GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
 # Copyright 2000, 2001 Free Software Foundation
@@ -46,7 +46,7 @@
   # exist in the Connections Definition File.
   pass
 
-class AdapterNotAvailable (Error):
+class AdapterNotInstalled (Error):
   # Raised if a provider is requested for which
   # the python libraries are not installed.
   pass
Index: gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py:1.6 
gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py:1.7
--- gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py:1.6 Sun Nov  4 17:22:35 2001
+++ gnue/gnue-common/src/dbdrivers/odbc/DBdriver.py     Sun Nov  4 18:25:02 2001
@@ -23,32 +23,34 @@
 #
 # DESCRIPTION:
 # Driver to provide access to data via the mxODBC Driver
-# Requires mxODBC (http://www.lemburg.com/files/python/mxODBC/)
 #
 # NOTES:
+# Requires mxODBC (http://www.lemburg.com/files/python/mxODBC.html)
 #
 #   Supported attributes (via connections.conf or <database> tag)
 #
-#     host=      This is the ODBC host for your connection (required)
-#     service=   This is the ODBC connection string to use
+#     service=   This is the ODBC DSN= string to use.
 #
+#
 
 #### THIS IS AN UNTESTED DRIVER ####
 ####      Any volunteers?       ####
 
 
-from string import lower
-import sys
+import sys, string
 from gnue.common import GDebug, GDataObjects, GConnections
 from gnue.common.dbdrivers._dbsig.DBdriver \
    import DBSIG_RecordSet, DBSIG_ResultSet, DBSIG_DataObject, \
           DBSIG_DataObject_SQL, DBSIG_DataObject_Object
 
 try:
-  import odbc as SIG2api
+  # This isn't actually used at this point, but is imported
+  # to generate an ImportError early on if not installed.
+  from mx import ODBC
 except ImportError, message:
   raise GConnections.AdapterNotInstalled, \
-         "Driver not installed: ODBC\n[%s]" % message
+         "Driver not installed: ODBC\nGrab mxODBC from "\
+         "http://www.lemburg.com/files/python/mxODBC.html\n\n[%s]"; % message
 
 
 class ODBC_RecordSet(DBSIG_RecordSet):
@@ -66,26 +68,33 @@
 class ODBC_DataObject(DBSIG_DataObject):
   def __init__(self):
     DBSIG_DataObject.__init__(self)
-    self._DatabaseError = SIG2api.DatabaseError
     self._resultSetClass = ODBC_ResultSet
-
+    self._backend = None
 
   def connect(self, connectData={}):
-    GDebug.printMesg(1,"SAP database driver initializing")
+    GDebug.printMesg(1,"ODBC database driver initializing")
     try:
-      self._dataConnection = SIG2api.connect( \
+      backend, dsn = string.split(connectData['service'],'|',1)
+      self._backend = __import__("mx/ODBC/%s" % backend)
+      self._DatabaseError = self._backend.DatabaseError
+    except ValueError:
+      raise GDataObjects.ConnectionError, \
+          'Invalid service string for ODBC driver.\n' +\
+          'Format: service="Backend|DSNString"'
+    except ImportError, mesg:
+      raise GConnections.AdapterNotInstalled, \
+          'Unable to load the ODBC drivers for %s' % backend
+
+    try:
+      self._dataConnection = SIG2api.connect( dsn, \
                    user=connectData['_username'], \
-                   password=connectData['_password'], \
-                   database=connectData['dbname'], \
-                   host=connectData['host'], \
-                   autocommit="off")
+                   password=connectData['_password'])
     except self._DatabaseError, value:
       raise GDataObjects.LoginError, value
 
     self._postConnect()
 
 
-
   #
   # Schema (metadata) functions
   #
@@ -94,7 +103,7 @@
 
   # Return a list of the types of Schema objects this driver provides
   def getSchemaTypes(self):
-    return [('view','View',1), ('table','Table',1)]
+    return [('table','Table',1)]
 
   # Return a list of Schema objects
   def getSchemaList(self, type=None):



reply via email to

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