[fdo-commits] r721 - in branches/3.2.x/Providers/GenericRdbms/Src: Fdo/Connection ODBC/Fdo

svn_fdo at osgeo.org svn_fdo at osgeo.org
Tue Jan 30 18:32:51 EST 2007


Author: romicadascalescu
Date: 2007-01-30 18:32:50 -0500 (Tue, 30 Jan 2007)
New Revision: 721

Modified:
   branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.cpp
   branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h
   branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcConnection.cpp
Log:
Fixed ODBC(Oracle) provider describe schema is slow

Modified: branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.cpp	2007-01-30 01:51:33 UTC (rev 720)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.cpp	2007-01-30 23:32:50 UTC (rev 721)
@@ -81,8 +81,7 @@
     mFilterProcessor( NULL ),
     mSchemaUtil( NULL ),
     mIndex(0),
-    mContext(NULL),
-    mParsedConnection(NULL)
+    mContext(NULL)
 {
     // Set the flag that indicates whether or not the RDBMS user has a Workspace
     // Manager environment.
@@ -92,8 +91,8 @@
     //       Workspace Manager or Alternate API.
 
     mIsWorkspaceManagerEnvironment = FALSE;
+    mParsedConnection = new ParseInfo();
 
-
 }
 
 DbiConnection::~DbiConnection(void)
@@ -181,8 +180,6 @@
             mGdbiConnection->SetIsGeometryFromOrdinatesWanted((char*)(const char*)(mParsedConnection->mIsGeometryFromOrdinatesWanted));
     }
     
-    mDbSchemaName = mParsedConnection->mSchema;
-
     return mOpen;
 }
 
@@ -204,7 +201,7 @@
         rdbi_disconnect( mContext );
         mOpen = FdoConnectionState_Closed;
 		mGdbiConnection->Close();
-        mDbSchemaName = L"";
+        mParsedConnection->mSchema = L"";
         mDbiContextId  = -1;
     }
 }
@@ -264,25 +261,29 @@
 
 FdoStringP DbiConnection::GetUser()
 {
-    return (NULL == mParsedConnection) ? L"" : mParsedConnection->mUser;
+    return mParsedConnection->mUser;
 }
 
 FdoStringP DbiConnection::GetPassword()
 {
-    return (NULL == mParsedConnection) ? L"" : mParsedConnection->mPassword;
+    return mParsedConnection->mPassword;
 }
 
 FdoStringP DbiConnection::GetSchema()
 {
-    return (NULL == mParsedConnection) ? L"" : mParsedConnection->mSchema;
+    return mParsedConnection->mSchema;
 }
 
-
 FdoStringP DbiConnection::GetDataSource()
 {
-    return (NULL == mParsedConnection) ? L"" : mParsedConnection->mDataSource;
+    return mParsedConnection->mDataSource;
 }
 
+FdoStringP DbiConnection::GetConnectionString()
+{
+    return mParsedConnection->mConnectionStringProperty;
+}
+
 void DbiConnection::SetConnectData (FdoString *datasource, FdoString *user, FdoString *password, FdoString *schema, FdoString *connectionString, FdoString *defaultGeometryWanted)
 {
     if ( !mParsedConnection ) 
@@ -760,12 +761,12 @@
 
 FdoStringP DbiConnection::GetDbSchemaName()
 {
-    return mDbSchemaName;
+    return mParsedConnection->mSchema;
 }
 
 void DbiConnection::SetDbSchemaName(const wchar_t * schemaName)
 {
-    mDbSchemaName = schemaName;
+    mParsedConnection->mSchema = schemaName;
 }
 
 

Modified: branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h	2007-01-30 01:51:33 UTC (rev 720)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h	2007-01-30 23:32:50 UTC (rev 721)
@@ -62,7 +62,8 @@
             FdoStringP mConnectionStringProperty;    // A connection property actually named "ConnectionString"
             FdoStringP mIsGeometryFromOrdinatesWanted;   // Unspecified if empty.  Can be "true" or "false".
 
-            ParseInfo (FdoString *datasource, FdoString *user, FdoString *password, FdoString *schema, FdoString *connectionString, FdoString *defaultGeometryWanted);
+            ParseInfo (FdoString *datasource = L"", FdoString *user = L"", FdoString *password = L"", FdoString *schema = L"", 
+                FdoString *connectionString = L"", FdoString *defaultGeometryWanted = L"");
             virtual ~ParseInfo ();
     };
 
@@ -70,8 +71,6 @@
 
     ParseInfo* mParsedConnection;
 
-    FdoStringP mDbSchemaName;
-
     FdoConnectionState     mOpen;     // if the database is open
 
     bool    mIsWorkspaceManagerEnvironment;
@@ -106,6 +105,7 @@
     FdoStringP GetPassword();
     FdoStringP GetSchema ();
     FdoStringP GetDataSource ();
+    FdoStringP GetConnectionString ();
     FDORDBMS_TEST  void Close ();
 
     //dbi_context_def *GetCtxt() { return mContext; }

Modified: branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcConnection.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcConnection.cpp	2007-01-30 01:51:33 UTC (rev 720)
+++ branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcConnection.cpp	2007-01-30 23:32:50 UTC (rev 721)
@@ -22,8 +22,15 @@
 
 #ifdef _WIN32
 #include <tchar.h>
+#include<odbcinst.h>
+#else
+// remove #if 0 when FdoRdbmsOdbcConnection::GetSchemaNameFromDsn is active on Linux
+#if 0
+#include<odbcinst.h>
 #endif
 
+#endif
+
 #include <Inc/ut.h>
 #include "FdoRdbmsOdbcConnectionInfo.h"
 #include "FdoRdbmsOdbcConnection.h"
@@ -45,6 +52,7 @@
 #include "FdoRdbmsOdbcSpatialManager.h"
 
 #include "DbiConnection.h"
+#include <FdoCommonConnStringParser.h>
 
 #include <Inc/Rdbi/proto.h>
 #include "../../ODBCDriver/context.h"
@@ -175,16 +183,37 @@
 FdoSchemaManagerP FdoRdbmsOdbcConnection::CreateSchemaManager()
  {
     FdoStringP userName = GetDbiConnection()->GetUser();
-    FdoStringP schemaName = GetSchemaNameFromDsn();
-
-    if (schemaName.GetLength() > 0)
+    FdoStringP schemaName = GetDbiConnection()->GetDbSchemaName();
+    if (schemaName.GetLength() == 0)
     {
-        // If the DSN contained a schema name, take that as the only one that
-        // we want to see, and which will be specified in all future requests
-        // from this provider.
-        // If this is not set, all schemas will be visible (occasionally more
-        // useful, but also can be slow).
-        GetDbiConnection()->SetDbSchemaName(schemaName);
+        FdoStringP connectionStringProperty = GetDbiConnection()->GetConnectionString();
+        if (connectionStringProperty.GetLength() != 0)
+        {
+            FdoCommonConnStringParser parser (NULL, connectionStringProperty);
+            if (parser.IsConnStringValid())
+            {
+                FdoStringP drvName = parser.GetPropertyValueW(L"DRIVER");
+                if (drvName.Contains(L"Oracle") && drvName.Contains(L"10g"))
+                {
+                    schemaName = parser.GetPropertyValueW(L"XSM");
+                    if (schemaName == L"Default")
+                        schemaName = L"";
+                }
+            }
+        }
+
+        if (schemaName.GetLength() == 0)
+            schemaName = GetSchemaNameFromDsn();
+
+        if (schemaName.GetLength() > 0)
+        {
+            // If the DSN contained a schema name, take that as the only one that
+            // we want to see, and which will be specified in all future requests
+            // from this provider.
+            // If this is not set, all schemas will be visible (occasionally more
+            // useful, but also can be slow).
+            GetDbiConnection()->SetDbSchemaName(schemaName);
+        }
     }
 
 #if 0
@@ -419,86 +448,48 @@
 }
 
 #ifdef _WIN32
-static HKEY GetRegistryKey(HKEY topkey, const char * subkeyName)
-{
-    HKEY hkey = NULL;
-    TCHAR value[ODBCDR_CONNECTION_SIZE];
-    DWORD size = sizeof(value) / sizeof(value[0]);;
-    LONG errStatus = ERROR_SUCCESS;
-    int status = FALSE;
-
-    if (ERROR_SUCCESS != RegOpenKeyEx (
-        topkey,
-        _T(subkeyName),     /* subkey name */
-        0L,                 /* reserved */
-        KEY_QUERY_VALUE,    /* security access mask */
-        &hkey))             /* handle to open key */
-    {
-        hkey = NULL;
-    }
-    return hkey;
-}
-
-static FdoStringP GetRegistryValue(HKEY hkey, const char * name)
-{
-    TCHAR value[ODBCDR_CONNECTION_SIZE];
-    DWORD size = sizeof(value) / sizeof(value[0]);;
-    LONG errStatus = ERROR_SUCCESS;
-    DWORD type;
-    FdoStringP valueP;
-
-    errStatus = RegQueryValueEx (
-        hkey,         /* handle to key */
-        _T(name),     /* value name */
-        NULL,         /* reserved */
-        &type,        /* type buffer */
-        (LPBYTE)value,/* data buffer */
-        &size);       /* size of data buffer */
-
-    if (ERROR_SUCCESS == errStatus)
-    {
-        valueP = FdoStringP::Format(L"%hs", (char *) value);
-    }
-    return valueP;
-}
-
-#endif
-
-#define SUBKEYNAME_PREFIX           "Software\\ODBC\\ODBC.INI\\"
-#define KEYNAME_DRIVER              "Driver"
-#define KEYNAME_USERID_ORACLENATIVE "UserID"
-#define DRIVER_NAME_ORACLENATIVE    L"SQORA32"
-
+#define ODBC_FODBC_INI        L"ODBC.INI"
 FdoStringP FdoRdbmsOdbcConnection::GetSchemaNameFromDsn()
 {
     FdoStringP schemaName;
 
-#ifdef _WIN32
     // For Oracle on Windows, get the UserId field.
     // This field is normally just a default for the username, so this use does overload
     // it.  However, Oracle's driver does not offer a separate "schema" field as other
     // drivers do.
-
     FdoStringP dsn = GetDbiConnection()->GetDataSource();
-    HKEY hkey = NULL;
-    char subkeyName[ODBCDR_CONNECTION_SIZE];
-    size_t subkeyNameSize = sizeof(subkeyName) / sizeof(subkeyName[0]);
-    (void) _snprintf(subkeyName, subkeyNameSize-1, "%s%ls", SUBKEYNAME_PREFIX, (const wchar_t *)dsn);
-
-    hkey = GetRegistryKey(HKEY_CURRENT_USER, subkeyName);
-    if (NULL == hkey)
-        hkey = GetRegistryKey(HKEY_LOCAL_MACHINE, subkeyName);
-    if (NULL != hkey)
+    wchar_t buffValue[ODBCDR_CONNECTION_SIZE];
+    if(0 != ::SQLGetPrivateProfileStringW( L"ODBC Data Sources", dsn, L"", buffValue, ODBCDR_CONNECTION_SIZE, ODBC_FODBC_INI ))
     {
-        FdoStringP driver = GetRegistryValue(hkey, KEYNAME_DRIVER);
-        if (driver.Contains(DRIVER_NAME_ORACLENATIVE))
+        FdoStringP drvName = buffValue;
+        if (drvName.Contains(L"Oracle") && drvName.Contains(L"10g"))
         {
-            FdoStringP userId = GetRegistryValue(hkey, KEYNAME_USERID_ORACLENATIVE);
-            if (userId.GetLength() > 0)
-                schemaName = userId;
+	        if(0 != ::SQLGetPrivateProfileStringW( dsn, L"UserID", L"", buffValue, ODBCDR_CONNECTION_SIZE, ODBC_FODBC_INI ))
+		        schemaName = buffValue;
         }
     }
+    return schemaName;
+}
+#else
+#define ODBC_FODBC_INI        "ODBC.INI"
+FdoStringP FdoRdbmsOdbcConnection::GetSchemaNameFromDsn()
+{
+    FdoStringP schemaName;
+#if 0
+    // this code is intended for Linux but is untested. 
+    // not sure if SQLGetPrivateProfileString is implemented on Linux
+    FdoStringP dsn = GetDbiConnection()->GetDataSource();
+    char buffValue[ODBCDR_CONNECTION_SIZE];
+    if(0 != ::SQLGetPrivateProfileString( "ODBC Data Sources", dsn, "", buffValue, ODBCDR_CONNECTION_SIZE, ODBC_FODBC_INI ))
+    {
+        FdoStringP drvName = buffValue;
+        if (drvName.Contains("Oracle") && drvName.Contains("10g"))
+        {
+	        if(0 != ::SQLGetPrivateProfileString( dsn, "UserID", "", buffValue, ODBCDR_CONNECTION_SIZE, ODBC_FODBC_INI ))
+		        schemaName = buffValue;
+        }
+    }
 #endif
-
     return schemaName;
 }
+#endif



More information about the fdo-commits mailing list