Description: Adding support also for libodbc.so.1
 odbcStubInit.c attempts to load also libodbc.so.1 
 if libodbc.so is not present
Author: Sergei Golovan <sgolovan@debian.org>
Bug: http://core.tcl.tk/tdbcodbc/tktview/4c45c353f703bc7f0c814996fa96773c6f015ce3
Reviewed-by: Massimo Manghi <mxmanghi@apache.org>
Last-Update: 2016-02-21
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/generic/odbcStubInit.c
+++ b/generic/odbcStubInit.c
@@ -39,6 +39,16 @@
     "libodbccp", "libodbccp32", "libodbcinst", NULL
 };
 
+/* ABI Version numbers of the ODBC API that we can cope with */
+
+static const char *const odbcSuffixes[] = {
+    "", ".1", NULL
+};
+
+static const char *const odbcOptSuffixes[] = {
+    "", ".1", NULL
+};
+
 /*
  * Names of the functions that we need from ODBC
  */
@@ -119,7 +129,7 @@
 				/* Pointer to a second load handle
 				 * that represents the ODBCINST library */
 {
-    int i;
+    int i,j;
     int status;			/* Status of Tcl library calls */
     Tcl_Obj* path;		/* Path name of a module to be loaded */
     Tcl_Obj* shlibext;		/* Extension to use for load modules */
@@ -144,17 +154,20 @@
      */
     status = TCL_ERROR;
     for (i = 0; status == TCL_ERROR && odbcStubLibNames[i] != NULL; ++i) {
-	path = Tcl_NewStringObj(odbcStubLibNames[i], -1);
-	Tcl_AppendObjToObj(path, shlibext);
-	Tcl_IncrRefCount(path);
-	Tcl_ResetResult(interp);
+	for (j = 0; status == TCL_ERROR && odbcSuffixes[j] != NULL; ++j) {
+	    path = Tcl_NewStringObj(odbcStubLibNames[i], -1);
+	    Tcl_AppendObjToObj(path, shlibext);
+	    Tcl_AppendToObj(path, odbcSuffixes[j], -1);
+	    Tcl_IncrRefCount(path);
+	    Tcl_ResetResult(interp);
 
 	/*
 	 * Try to load a client library and resolve the ODBC API within it.
 	 */
-	status = Tcl_LoadFile(interp, path, odbcSymbolNames, 0,
-			      (void*)odbcStubs, &handle);
-	Tcl_DecrRefCount(path);
+	    status = Tcl_LoadFile(interp, path, odbcSymbolNames, 0,
+				  (void*)odbcStubs, &handle);
+	    Tcl_DecrRefCount(path);
+	}
     }
 
     /*
@@ -163,27 +176,30 @@
     if (status == TCL_OK) {
 	int status2 = TCL_ERROR;
 	for (i = 0; status2 == TCL_ERROR && odbcOptLibNames[i] != NULL; ++i) {
-	    path = Tcl_NewStringObj(odbcOptLibNames[i], -1);
-	    Tcl_AppendObjToObj(path, shlibext);
-	    Tcl_IncrRefCount(path);
-	    status2 = Tcl_LoadFile(interp, path, NULL, 0, NULL, handle2Ptr);
-	    if (status2 == TCL_OK) {
-		SQLConfigDataSourceW =
-		    (BOOL (INSTAPI*)(HWND, WORD, LPCWSTR, LPCWSTR))
-		    Tcl_FindSymbol(NULL, *handle2Ptr, "SQLConfigDataSourceW");
-		if (SQLConfigDataSourceW == NULL) {
-		    SQLConfigDataSource =
-			(BOOL (INSTAPI*)(HWND, WORD, LPCSTR, LPCSTR))
-			Tcl_FindSymbol(NULL, *handle2Ptr,
-				       "SQLConfigDataSource");
+	    for (j = 0; status2 == TCL_ERROR && odbcOptSuffixes[j] != NULL; ++j) {
+		path = Tcl_NewStringObj(odbcOptLibNames[i], -1);
+		Tcl_AppendObjToObj(path, shlibext);
+		Tcl_AppendToObj(path, odbcOptSuffixes[j], -1);
+		Tcl_IncrRefCount(path);
+		status2 = Tcl_LoadFile(interp, path, NULL, 0, NULL, handle2Ptr);
+		if (status2 == TCL_OK) {
+		    SQLConfigDataSourceW = 
+			(BOOL (INSTAPI*)(HWND, WORD, LPCWSTR, LPCWSTR))
+			Tcl_FindSymbol(NULL, *handle2Ptr, "SQLConfigDataSourceW");
+		    if (SQLConfigDataSourceW == NULL) {
+			SQLConfigDataSource =
+			    (BOOL (INSTAPI*)(HWND, WORD, LPCSTR, LPCSTR))
+			    Tcl_FindSymbol(NULL, *handle2Ptr,
+					   "SQLConfigDataSource");
+		    }
+		    SQLInstallerError =
+			(BOOL (INSTAPI*)(WORD, DWORD*, LPSTR, WORD, WORD*))
+			Tcl_FindSymbol(NULL, *handle2Ptr, "SQLInstallerError");
+		} else {
+		    Tcl_ResetResult(interp);
 		}
-		SQLInstallerError =
-		    (BOOL (INSTAPI*)(WORD, DWORD*, LPSTR, WORD, WORD*))
-		    Tcl_FindSymbol(NULL, *handle2Ptr, "SQLInstallerError");
-	    } else {
-		Tcl_ResetResult(interp);
+                Tcl_DecrRefCount(path);
 	    }
-	    Tcl_DecrRefCount(path);
 	}
     }
 
