[fdo-commits] r727 - in branches/3.2.x/Providers/GenericRdbms/Src:
Fdo/Connection ODBC/Fdo UnitTest/Odbc
svn_fdo at osgeo.org
svn_fdo at osgeo.org
Fri Feb 2 16:58:27 EST 2007
Author: romicadascalescu
Date: 2007-02-02 16:58:26 -0500 (Fri, 02 Feb 2007)
New Revision: 727
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
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcConnectionUtil.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-02-02 16:07:20 UTC (rev 726)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.cpp 2007-02-02 21:58:26 UTC (rev 727)
@@ -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;
}
@@ -1096,3 +1097,12 @@
return GetSchemaUtil()->GetSchemaManager();
}
+unsigned long DbiConnection::GetDbVersion()
+{
+ if (mContext == NULL)
+ return RDBI_DBVERSION_UNKNOW;
+ rdbi_vndr_info_def info;
+ rdbi_vndr_info( mContext, &info );
+
+ return info.dbversion;
+}
Modified: branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h 2007-02-02 16:07:20 UTC (rev 726)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Fdo/Connection/DbiConnection.h 2007-02-02 21:58:26 UTC (rev 727)
@@ -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,8 @@
FdoStringP GetPassword();
FdoStringP GetSchema ();
FdoStringP GetDataSource ();
+ FdoStringP GetConnectionString ();
+ unsigned long GetDbVersion();
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-02-02 16:07:20 UTC (rev 726)
+++ branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcConnection.cpp 2007-02-02 21:58:26 UTC (rev 727)
@@ -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"
@@ -174,17 +182,30 @@
FdoSchemaManagerP FdoRdbmsOdbcConnection::CreateSchemaManager()
{
- FdoStringP userName = GetDbiConnection()->GetUser();
- FdoStringP schemaName = GetSchemaNameFromDsn();
-
- if (schemaName.GetLength() > 0)
+ DbiConnection* pConn = GetDbiConnection();
+ FdoStringP userName = pConn->GetUser();
+ FdoStringP schemaName = pConn->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 = pConn->GetConnectionString();
+ if (connectionStringProperty.GetLength() != 0 && pConn->GetDbVersion() == RDBI_DBVERSION_ODBC_ORACLE)
+ {
+ FdoCommonConnStringParser parser (NULL, connectionStringProperty);
+ if (parser.IsConnStringValid())
+ schemaName = parser.GetPropertyValueW(L"XSM");
+ }
+ 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).
+ pConn->SetDbSchemaName(schemaName);
+ }
}
#if 0
@@ -197,7 +218,7 @@
{
// Set sane default for the RDBMS' schema (where things go for cases where
// we do not specify a schema in this provider).
- GetDbiConnection()->SetActiveSchema(schemaName);
+ pConn->SetActiveSchema(schemaName);
}
// Call base class' method.
@@ -419,86 +440,42 @@
}
#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)
+ DbiConnection* pConn = GetDbiConnection();
+ FdoStringP dsn = pConn->GetDataSource();
+ wchar_t buffValue[ODBCDR_CONNECTION_SIZE];
+ if (pConn->GetDbVersion() == RDBI_DBVERSION_ODBC_ORACLE)
{
- FdoStringP driver = GetRegistryValue(hkey, KEYNAME_DRIVER);
- if (driver.Contains(DRIVER_NAME_ORACLENATIVE))
- {
- 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
+ DbiConnection* pConn = GetDbiConnection();
+ FdoStringP dsn = pConn->GetDataSource();
+ char buffValue[ODBCDR_CONNECTION_SIZE];
+ if (pConn->GetDbVersion() == RDBI_DBVERSION_ODBC_ORACLE)
+ {
+ if(0 != ::SQLGetPrivateProfileString( dsn, "UserID", "", buffValue, ODBCDR_CONNECTION_SIZE, ODBC_FODBC_INI ))
+ schemaName = buffValue;
+ }
#endif
-
return schemaName;
}
+#endif
Modified: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcConnectionUtil.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcConnectionUtil.cpp 2007-02-02 16:07:20 UTC (rev 726)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcConnectionUtil.cpp 2007-02-02 21:58:26 UTC (rev 727)
@@ -524,7 +524,7 @@
swprintf(
connectString,
sizeof(connectString)/sizeof(wchar_t),
- L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;XSM=Default;\"",
+ L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;\"",
(FdoString*)OracleDriverName,
(FdoString*)pDatastore /*username*/,
(FdoString*)password,
@@ -643,7 +643,7 @@
swprintf(
connectString,
sizeof(connectString)/sizeof(wchar_t),
- L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;XSM=Default;\"",
+ L"ConnectionString=\"DRIVER={%ls};UID=%ls;PWD=%ls;DBQ=%ls;;\"",
(FdoString*)OracleDriverName,
(FdoString*)username,
(FdoString*)password,
More information about the fdo-commits
mailing list