[svn-commits] r44 - in drivers/python/trunk: dbi hdr

crogr01 at ingres.com crogr01 at ingres.com
Thu Jun 5 10:33:36 PDT 2008


Author: crogr01
Date: 2008-06-05 10:33:36 -0700 (Thu, 05 Jun 2008)
New Revision: 44

Modified:
   drivers/python/trunk/dbi/ingresdbi.c
   drivers/python/trunk/hdr/iidbi.h
Log:
The Python driver SEGVs when ODBCSYSINI is not set or when /usr/local/etc/odbcinst.ini does not exist

Modified: drivers/python/trunk/dbi/ingresdbi.c
===================================================================
--- drivers/python/trunk/dbi/ingresdbi.c	2008-04-26 09:30:14 UTC (rev 43)
+++ drivers/python/trunk/dbi/ingresdbi.c	2008-06-05 17:33:36 UTC (rev 44)
@@ -9,6 +9,8 @@
 #include <structmember.h>
 #include <time.h>
 #include <datetime.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 /**
 ** Name: iingresdbi.c - Ingres Python DB API base module classes and
@@ -1079,6 +1081,9 @@
 ** History:
 **     26-May-06 Ralph.Loen at ingres.com
 **         Created.
+**     28-Apr-08 grant.croker at ingres.com
+**         Extend search for odbcinst.ini, look in $II_SYSTEM/ingres/files.
+**         Use MAX_PATH as the maximum path length
 }*/
 
 static PyObject * IIDBI_connect(PyObject *self, PyObject *args, 
@@ -1113,6 +1118,9 @@
     int i;
     int result = FALSE;
     int p;
+    struct stat buf;
+    char odbcconfig[MAX_PATH];
+    char *ii_system;
     static char *kwlist[] = 
     {
         "dsn", "database", "vnode", "uid", "pwd", "autocommit", "selectloops",
@@ -1222,6 +1230,39 @@
         IIDBIpdbc->conn = (void *)conn;
         if (!IIDBIenv.hdr.handle)
         {
+#ifndef WIN32
+            /* The Ingres ODBC CLI expects /usr/local/etc/odbcinst.ini to exist */
+            /* if ODBCSYSINI is not defined. This is only true if unixODBC has */
+            /* been built and installed from source. Redhat, SuSE, Debian etc. */
+            /* typically use /etc or /etc/unixODBC. Ingres tends to keep a copy */
+            /* of odbcinst.ini in $II_SYSTEM/ingres/files if it was not installed */
+            /* to /usr/local/etc. */
+            if ((ii_system = getenv("II_SYSTEM")) == NULL)
+            {
+                PyErr_SetString(IIDBI_Error, "II_SYSTEM is not set");
+                goto errorExit;
+            }
+            if (getenv("ODBCSYSINI") == NULL)
+            {
+                snprintf(odbcconfig, MAX_PATH,"/usr/local/etc/odbcinst.ini");
+                if (stat(odbcconfig, &buf)== -1)
+                {
+                    /* Try $II_SYSTEM/ingres/files/odbcinst.ini */
+                    snprintf(odbcconfig, MAX_PATH, "%s/ingres/files/odbcinst.ini", ii_system);
+                    if (stat(odbcconfig, &buf) == -1)
+                    {
+                        PyErr_SetString(IIDBI_Error, "Unable to load odbc configuration, please set the environment variable ODBCSYSINI.");
+                        goto errorExit;
+                    }
+                    else
+                    {
+                        /* Use $II_SYSTEM/ingres/files/odbcinst.ini */
+                        sprintf(odbcconfig,"%s/ingres/files", ii_system);
+                        setenv("ODBCSYSINI",odbcconfig, 1);
+                    }
+                }
+            }
+#endif
             rc = dbi_alloc_env(&IIDBIenv, IIDBIpdbc);
    
             if (rc != DBI_SQL_SUCCESS)

Modified: drivers/python/trunk/hdr/iidbi.h
===================================================================
--- drivers/python/trunk/hdr/iidbi.h	2008-04-26 09:30:14 UTC (rev 43)
+++ drivers/python/trunk/hdr/iidbi.h	2008-06-05 17:33:36 UTC (rev 44)
@@ -52,6 +52,8 @@
 **          IIDBI_cursorIterNext().
 **      20-may-2006 (Ralph.Loen at ingres.com)
 **          Added cursor.setinputsizes() and cursor.setoutputsize().
+**      28-Apr-2008 (grant.croker at ingres.com)
+**          Define MAX_PATH as 256 if not already defined
 **/
 
 # ifndef __IIDBI_H_INCLUDED
@@ -67,6 +69,10 @@
 # include <sql.h>
 # include <sqlext.h>
 
+# ifndef MAX_PATH
+# define MAX_PATH 256
+# endif /* MAX_PATH */
+
 /*
 ** Name: IIDBI_ERROR - DBI error message structure.
 **




More information about the svn-commits mailing list