Modified:
MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
MYODBCIns/include/MYODBCInsDataSource.h
Log:
Modified: MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp 2006-04-17 20:10:18 UTC (rev 79)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp 2006-04-17 22:55:52 UTC (rev 80)
@@ -58,14 +58,14 @@
MYODBCIns::setError( QString( "[%1][%2][ERROR] Data source attributes empty."
).arg( __FILE__ ).arg( __LINE__ ) );
MYODBCDbgReturn3( "%d", false );
}
-/*
- QHash<QString, QString>::const_iterator i = map.constBegin();
- while ( i != map.constEnd() )
+
+ QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
+ while ( i != hashAttributes.constEnd() )
{
- if ( !setKeywords.contains( i.key() << ": " << i.value() <<
endl;
+ this->hashAttributes[i.key()] = i.value();
++i;
}
-*/
+
MYODBCDbgReturn3( "%d", true )
}
@@ -301,9 +301,9 @@
{
MYODBCDbgEnter();
- SQLWCHAR szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- SQLWCHAR * pszEntryName;
- SQLWCHAR szValue[4096];
+ SQLWCHAR sEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
+ SQLWCHAR * psEntryName;
+ SQLWCHAR sValue[4096];
int nChars = 0;
UWORD nScopeToRestore = ODBC_BOTH_DSN;
bool bReturn = false;
@@ -316,13 +316,13 @@
SQLSetConfigMode( (UWORD)nScope );
- *szEntryNames = '\0';
- if ( ( nChars = SQLGetPrivateProfileString( stringDataSourceName.utf16(), NULL, NULL,
szEntryNames, sizeof(szEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1 )
+ *sEntryNames = '\0';
+ if ( ( nChars = SQLGetPrivateProfileString( stringDataSourceName.utf16(), NULL, NULL,
sEntryNames, sizeof(sEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1 )
goto doReadExit1;
#if defined(WIN32)
{
- int nLen = MYODBCC::getStrLen( szEntryNames, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES );
+ int nLen = MYODBCC::getStrLen( sEntryNames, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES );
/*!
\note XP
@@ -337,12 +337,12 @@
The solution is to detect this condition and set mode to
ODBC_SYSTEM_DSN and try again. We
also ensure we reset the mode when done - regardless of outcome.
*/
- if ( nScope == MYODBC_INS_DATASOURCE_SCOPE_BOTH && nLen < nChars
&& szEntryNames[nLen + 1 ] == '\0' )
+ if ( nScope == MYODBC_INS_DATASOURCE_SCOPE_BOTH && nLen < nChars
&& sEntryNames[nLen + 1 ] == '\0' )
{
- *szEntryNames = '\0';
+ *sEntryNames = '\0';
SQLSetConfigMode( ODBC_SYSTEM_DSN );
- if ( ( nChars = SQLGetPrivateProfileString( stringDataSourceName.utf16(),
NULL, NULL, szEntryNames, sizeof(szEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1
)
+ if ( ( nChars = SQLGetPrivateProfileString( stringDataSourceName.utf16(),
NULL, NULL, sEntryNames, sizeof(sEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1 )
goto doReadExit1;
}
}
@@ -351,20 +351,20 @@
/*!
Looks like things are going to work. Lets set DSN.
*/
- stringDSN = stringDataSourceName;
+ stringName = stringDataSourceName;
/*!
Scan result and return MYODBC_C_TRUE if we find a match.
*/
- pszEntryName = szEntryNames;
- while ( *pszEntryName )
+ psEntryName = sEntryNames;
+ while ( *psEntryName )
{
- *szValue = '\0';
- if ( SQLGetPrivateProfileString( stringDataSourceName.utf16(), pszEntryName, L"",
szValue, sizeof( szValue ) / sizeof(SQLWCHAR), L"ODBC.INI" ) > 0 )
+ *sValue = '\0';
+ if ( SQLGetPrivateProfileString( stringDataSourceName.utf16(), psEntryName, L"",
sValue, sizeof( sValue ) / sizeof(SQLWCHAR), L"ODBC.INI" ) > 0 )
{
- QString stringEntryName( QString::fromUtf16( pszEntryName ) );
+ QString stringEntryName( QString::fromUtf16( psEntryName ) );
QString stringEntryNameUpper = stringEntryName.toUpper();
- QString stringValue( QString::fromUtf16( szValue ) );
+ QString stringValue( QString::fromUtf16( sValue ) );
/*!
\internal ODBC Rule
@@ -376,115 +376,17 @@
connection string, the driver uses the information in the connection
string.
*/
- if ( QString::localeAwareCompare( stringEntryNameUpper, "DATABASE" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "DB" ) == 0 )
- {
- if ( stringDATABASE.isNull() )
- stringDATABASE = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "DESCRIPTION" )
== 0 || QString::localeAwareCompare( stringEntryNameUpper, "DESC" ) == 0 )
- {
- if ( stringDESCRIPTION.isNull() )
- stringDESCRIPTION = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "DRIVER" ) == 0
)
- {
-#if defined(WIN32)
- if ( stringDriverFileName.isEmpty() )
- stringDriverFileName = QString::fromUtf16( szValue );
-#else
- if ( *szValue == '/' )
- {
- if ( stringDriverFileName.isEmpty() )
- stringDriverFileName = QString::fromUtf16( szValue );
- }
- else
- {
- if ( stringDRIVER.isEmpty() )
- stringDRIVER = QString::fromUtf16( szValue );
- }
-#endif
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "OPTION" ) == 0
)
- {
- if ( stringOPTION.isNull() )
- stringOPTION = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "PWD" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "PASSWORD" ) == 0 )
- {
- if ( stringPASSWORD.isNull() )
- stringPASSWORD = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "PORT" ) == 0 )
- {
- if ( stringPORT.isNull() )
- stringPORT = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "SERVER" ) == 0
)
- {
- if ( stringSERVER.isNull() )
- stringSERVER = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "SOCKET" ) == 0
)
- {
- if ( stringSOCKET.isNull() )
- stringSOCKET = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "STMT" ) == 0 )
- {
- if ( stringSTMT.isNull() )
- stringSTMT = QString::fromUtf16( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryNameUpper, "UID" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "USER" ) == 0 )
- {
- if ( stringUSER.isNull() )
- stringUSER = QString::fromUtf16( szValue );
- }
+ if ( hashAttributes.contains( stringEntryNameUpper ) )
+ hashAttributes[stringEntryNameUpper] = stringValue;
else
- {
- /* What the ? */
- MYODBCDbgError( "Unknown attribute (%s).", pszEntryName );
- }
+ MYODBCDbgError( "Unknown attribute (%s).", psEntryName );
}
else
- MYODBCDbgWarning( "Failed to get value for attribute (%s).", pszEntryName );
+ MYODBCDbgWarning( "Failed to get value for attribute (%s).", psEntryName );
- pszEntryName += MYODBCC::getStrLen( pszEntryName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
+ psEntryName += MYODBCC::getStrLen( psEntryName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
} /* while */
-
- /* try harder to get the friendly driver name */
- if ( stringDRIVER.isEmpty() )
- {
- if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION, NULL, NULL,
szEntryNames, sizeof(szEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) < 1 )
- goto doReadExit1;
-
- pszEntryName = szEntryNames;
- while ( *pszEntryName )
- {
- QString stringEntryName( QString::fromUtf16( pszEntryName ) );
- *szValue = '\0';
- if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION,
pszEntryName, NULL, szValue, sizeof(szValue) / sizeof(SQLWCHAR), L"ODBC.INI" ) > 0 )
- {
-
- if ( QString::localeAwareCompare( stringEntryName.toUpper(),
stringDataSourceName.toUpper() ) == 0 )
- {
- stringDRIVER = QString::fromUtf16( szValue );
- break;
- }
- }
- pszEntryName += MYODBCC::getStrLen( pszEntryName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
- }
- }
-
-#if defined(WIN32)
- /*!
- XP
-
- Some people have reported that the friendly driver name is never found so...
- */
- if ( stringDRIVER.isEmpty() )
- stringDRIVER = MYODBCINST_DRIVER_NAME;
-#endif
bReturn = true;
doReadExit1:
@@ -506,7 +408,7 @@
{
MYODBCDbgEnter();
- bool bReturn = doRead( stringDSN, nScope );
+ bool bReturn = doRead( stringName, nScope );
MYODBCDbgReturn3( "%d", bReturn );
}
@@ -521,7 +423,8 @@
if ( !SQLGetConfigMode( &nScopeToRestore ) )
MYODBCDbgReturn3( "%d", false )
- SQLSetConfigMode( (UWORD)nScope );
+ if ( !SQLSetConfigMode( (UWORD)nScope ) )
+ MYODBCDbgReturn3( "%d", false )
/*
SQLWriteDSNToIni is *supposed* to replace any existing DSN
@@ -529,45 +432,30 @@
So we ensure that any existing DSN with same name is removed
with the following call.
*/
- if ( !SQLRemoveDSNFromIni( stringDSN.utf16() ) )
- goto doReadExit1;
+ if ( !SQLRemoveDSNFromIni( stringName.utf16() ) )
+ goto doWriteExit1;
/* create/replace data source name */
- if ( !SQLWriteDSNToIni( stringDSN.utf16(), stringDRIVER.utf16() ) )
- goto doReadExit1;
+ if ( !SQLWriteDSNToIni( stringName.utf16(), hashAttributes["DRIVER"].utf16() ) )
+ goto doWriteExit1;
- /* add details */
- if ( !stringDATABASE.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"DATABASE",
stringDATABASE.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringDESCRIPTION.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"DESCRIPTION",
stringDESCRIPTION.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringOPTION.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"OPTION",
stringOPTION.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringPASSWORD.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"PWD",
stringPASSWORD.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringPORT.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"PORT", stringPORT.utf16(),
L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringSERVER.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"SERVER",
stringSERVER.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringSOCKET.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"SOCKET",
stringSOCKET.utf16(), L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringSTMT.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"STMT", stringSTMT.utf16(),
L"odbc.ini" ) )
- goto doReadExit1;
- if ( !stringUSER.isNull() &&
- !SQLWritePrivateProfileString( stringDSN.utf16(), L"UID", stringUSER.utf16(),
L"odbc.ini" ) )
- goto doReadExit1;
+ /* add attributes */
+ {
+ QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
+ while ( i != hashAttributes.constEnd() )
+ {
+ if ( !i.value().isEmpty() )
+ {
+ if ( !SQLWritePrivateProfileString( stringName.utf16(), i.key().utf16(),
i.value().utf16(), L"odbc.ini" ) )
+ goto doWriteExit1;
+ }
+ ++i;
+ }
+ }
bReturn = true;
-doReadExit1:
+doWriteExit1:
SQLSetConfigMode( nScopeToRestore );
MYODBCDbgReturn3( "%d", bReturn );
@@ -603,7 +491,7 @@
hashAttributes["STMT"] = QString::null; /*!< Statement that will be
exec when connecting to MySQL. */
hashAttributes["OPTION"] = QString::null; /*!< Options that specify how
MyODBC should work. */
- MYODBCDbgReturn();
+ MYODBCDbgReturn2();
}
bool MYODBCInsDataSource::doDelete( const QString &stringDataSourceName )
@@ -611,58 +499,34 @@
MYODBCDbgEnter();
bool bReturn = SQLRemoveDSNFromIni( stringDataSourceName.utf16() );
+
+ MYODBCDbgReturn3( "%d", bReturn );
}
bool MYODBCInsDataSource::isValidAttributes( const QHash<QString,QString>
&hashAttributes )
{
MYODBCDbgEnter();
- // lookup table of valid keywords
-/*
- QSet<QString> setKeywords;
-
- setKeywords.insert( "DATABASE" );
- setKeywords.insert( "DESCRIPTION" );
- setKeywords.insert( "DRIVER" );
- setKeywords.insert( "DSN" );
- setKeywords.insert( "OPTION" );
- setKeywords.insert( "PASSWORD" );
- setKeywords.insert( "PORT" );
- setKeywords.insert( "SERVER" );
- setKeywords.insert( "SOCKET" );
- setKeywords.insert( "STMT" );
- setKeywords.insert( "USER" );
-*/
// validate keywords
-/*
- QHash<QString, QString>::const_iterator i = map.constBegin();
- while ( i != map.constEnd() )
+ QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
+ while ( i != hashAttributes.constEnd() )
{
- if ( !setKeywords.contains( i.key() );
+ if ( !this->hashAttributes.contains( i.key() ) )
{
- }
+ MYODBCIns::setError( QString( "[%1][%2][ERROR] %3 is an unsupported
attribute." ).arg( __FILE__ ).arg( __LINE__ ).arg( i.key() ) );
MYODBCDbgReturn3( "%d", false );
+ }
++i;
}
-*/
+
MYODBCDbgReturn3( "%d", true );
}
MYODBCInsDataSource MYODBCInsDataSource::operator=( MYODBCInsDataSource rval )
{
- hashAttributes["DATABASE"] = rval.hashAttributes["DATABASE"];
- hashAttributes["DESCRIPTION"] = rval.hashAttributes["DESCRIPTION"];
- hashAttributes["DRIVER"] = rval.hashAttributes["DRIVER;
- hashAttributes["DSN"] = rval.hashAttributes["DSN"];
- hashAttributes["OPTION"] = rval.hashAttributes["OPTION"];
- hashAttributes["PWD"] = rval.hashAttributes["PWD"];
- hashAttributes["PORT"] = rval.hashAttributes["PORT"];
- hashAttributes["SERVER"] = rval.hashAttributes["SERVER"];
- hashAttributes["SOCKET"] = rval.hashAttributes["SOCKET"];
- hashAttributes["STMT"] = rval.hashAttributes["STMT"];
- hashAttributes["UID"] = rval.hashAttributes["UID"];
+ hashAttributes = rval.hashAttributes;
-// stringDriverFileName = rval.stringDriverFileName;
+ stringName = rval.stringName;
nScope = rval.nScope;
return *this;
@@ -670,19 +534,14 @@
QTextStream &operator<<( QTextStream &stream, const MYODBCInsDataSource
&rval )
{
- stream << "DATABASE : " << rval.hashAttributes.value( "DATABASE" )
<< endl;
- stream << "DESCRIPTION : " << rval.hashAttributes.value( "DESCRIPTION"
) << endl;
- stream << "DRIVER : " << rval.hashAttributes.value( "DRIVER" )
<< endl;
- stream << "DSN : " << rval.hashAttributes.value( "DSN" )
<< endl;
- stream << "OPTION : " << rval.hashAttributes.value( "OPTION" )
<< endl;
- stream << "PASSWORD : " << rval.hashAttributes.value( "PWD" )
<< endl;
- stream << "PORT : " << rval.hashAttributes.value( "PORT" )
<< endl;
- stream << "SERVER : " << rval.hashAttributes.value( "SERVER" )
<< endl;
- stream << "SOCKET : " << rval.hashAttributes.value( "SOCKET" )
<< endl;
- stream << "STMT : " << rval.hashAttributes.value( "STMT" )
<< endl;
- stream << "USER : " << rval.hashAttributes.value( "UID" )
<< endl;
+ stream << "Name : " << rval.stringName << endl;
-// stream << "DriverFileName: " << rval.stringDriverFileName <<
endl;
+ QHash<QString, QString>::const_iterator i = rval.hashAttributes.constBegin();
+ while ( i != rval.hashAttributes.constEnd() )
+ {
+ stream << i.key() << " : " << i.value() << endl;
+ ++i;
+ }
return stream;
}
Modified: MYODBCIns/include/MYODBCInsDataSource.h
===================================================================
--- MYODBCIns/include/MYODBCInsDataSource.h 2006-04-17 20:10:18 UTC (rev 79)
+++ MYODBCIns/include/MYODBCInsDataSource.h 2006-04-17 22:55:52 UTC (rev 80)
@@ -42,8 +42,8 @@
bool setDRIVER( const QString &stringDRIVER );
bool setDESCRIPTION( const QString &stringDESCRIPTION );
bool setSERVER( const QString &stringSERVER );
- bool setUSER( const QString &stringUSER );
- bool setPASSWORD( const QString &stringPASSWORD );
+ bool setUID( const QString &stringUSER );
+ bool setPWD( const QString &stringPASSWORD );
bool setDATABASE( const QString &stringDATABASE );
bool setPORT( const QString &stringPORT );
bool setSOCKET( const QString &stringSOCKET );
@@ -57,8 +57,8 @@
QString getDRIVER();
QString getDESCRIPTION();
QString getSERVER();
- QString getUSER();
- QString getPASSWORD();
+ QString getUID();
+ QString getPWD();
QString getDATABASE();
QString getPORT();
QString getSOCKET();
@@ -75,7 +75,7 @@
void doClear();
static bool doDelete( const QString &stringDataSourceName );
- static bool isValidAttributes( const QHash<QString,QString> &hashAttributes
);
+ bool isValidAttributes( const QHash<QString,QString> &hashAttributes );
MYODBCInsDataSource operator=( MYODBCInsDataSource rval );
friend QTextStream &operator<<( QTextStream &stream, const
MYODBCInsDataSource &rval );
| Thread |
|---|
| • Connector/ODBC 5 commit: r80 - in MYODBCIns: MYODBCInsLib include | pharvey | 18 Apr |