List:Commits« Previous MessageNext Message »
From:pharvey Date:June 22 2006 7:33pm
Subject:Connector/ODBC 5 commit: r361 - in trunk: MYODBCC/MYODBCCLib MYODBCC/include MYODBCIns/MYODBCInsLib MYODBCIns/MYODBCInsTest MYODBCSetup/MYODBCSetupLib...
View as plain text  
Modified:
   trunk/MYODBCC/MYODBCCLib/MYODBCC.cpp
   trunk/MYODBCC/include/MYODBCC.h
   trunk/MYODBCIns/MYODBCInsLib/MYODBCIns.cpp
   trunk/MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
   trunk/MYODBCIns/MYODBCInsTest/MYODBCInsTest.cpp
   trunk/MYODBCSetup/MYODBCSetupLib/ConfigDSNW.cpp
   trunk/MYODBCSetup/MYODBCSetupLib/MYODBCSetupDataSourceConfig.cpp
Log:
- fixed problem with key/value (attribute) string parse
- added test for getKeywordValuesLength and getKeywordValues

Modified: trunk/MYODBCC/MYODBCCLib/MYODBCC.cpp
===================================================================
--- trunk/MYODBCC/MYODBCCLib/MYODBCC.cpp	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCC/MYODBCCLib/MYODBCC.cpp	2006-06-22 19:33:17 UTC (rev 361)
@@ -54,6 +54,9 @@
 {
     WCHAR *pc = (WCHAR*)pszzKeywordValues;
 
+    if ( !pc )
+        return 0;
+
     for ( ; pc[0] || pc[1]; pc++ ) {}
 
     return (pc - pszzKeywordValues);

Modified: trunk/MYODBCC/include/MYODBCC.h
===================================================================
--- trunk/MYODBCC/include/MYODBCC.h	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCC/include/MYODBCC.h	2006-06-22 19:33:17 UTC (rev 361)
@@ -148,6 +148,21 @@
     */
     static size_t  getStrLen( const SQLWCHAR *psz, size_t nMaxChars );
 
+    /*!
+        \brief  Get string length.
+
+                Use this to get the number of characters in a wide character
+                string where the delimiter is two null wchars.
+
+                The length will NOT include the two null wchar terminators but 
+                will include any other nulls.
+
+        \param  pszKeywordValues A wide character string appropriately delimited.
+
+        \return int
+
+        \retval n The number of wide characters found (could be 0).
+    */
     static int getKeywordValuesLength( LPCWSTR pszKeywordValues );
 
     /*!

Modified: trunk/MYODBCIns/MYODBCInsLib/MYODBCIns.cpp
===================================================================
--- trunk/MYODBCIns/MYODBCInsLib/MYODBCIns.cpp	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCIns/MYODBCInsLib/MYODBCIns.cpp	2006-06-22 19:33:17 UTC (rev 361)
@@ -171,6 +171,7 @@
     /* scan the input (we can not use QString::split() due to possible use of {} to
embrace values and type of delim) */
     while ( 1 )
     {
+// printf( "[PAH][%s][%d] (%c)\n", __FILE__, __LINE__,
stringKeywordValues[nScanChar].toAscii() );
         switch ( nState )
         {
             case PARSE_STATE_NAME_START:
@@ -188,6 +189,7 @@
                     {
                         stringKeyword = stringKeywordValues.mid( nAnchorChar, nScanChar -
nAnchorChar );
                         nState = PARSE_STATE_VALUE_START;
+// printf( "[PAH][%s][%d] (%s)\n", __FILE__, __LINE__, stringKeyword.toAscii().data() );
                     }
                 }
                 break;
@@ -228,18 +230,27 @@
 
                     nScanChar++;
                 }
+// printf( "[PAH][%s][%d] (%s)=(%s) nAnchorChar=%d nScanChar=%d\n", __FILE__, __LINE__,
stringKeyword.toAscii().data(), stringKeywordValues.mid( nAnchorChar, nScanChar -
nAnchorChar ).toAscii().data(), nAnchorChar, nScanChar );
 
                 /*
                     \internal ODBC Rule
 
                     If the DSN and DRIVER keywords are included in the same connection
string, 
                     the Driver Manager and the driver use whichever keyword appears
first.
+
+                    \note
+
+                    We assume we are processing for a ConfigDSN(), not a connection
string, when
+                    we are using DELIM_NULL.
                 */
-                if ( stringKeyword == "DSN" &&
!(*phashKeywordValues)["DRIVER"].isNull() )
-                    break;
+                if ( nDelim != MYODBCIns::DELIM_NULL )
+                {
+                    if ( stringKeyword == "DSN" &&
phashKeywordValues->contains( "DRIVER" ) )
+                        break;
 
-                if ( stringKeyword == "DRIVER" &&
!(*phashKeywordValues)["DSN"].isNull() )
-                    break;
+                    if ( stringKeyword == "DRIVER" &&
phashKeywordValues->contains( "DSN" ) )
+                        break;
+                }
 
                 /*
                     \internal ODBC Rule

Modified: trunk/MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
===================================================================
--- trunk/MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp	2006-06-22 19:33:17 UTC (rev 361)
@@ -407,7 +407,7 @@
 {
     MYODBCDbgEnter();
 
-    BOOLEAN    bReturn         = false;
+    BOOLEAN bReturn         = false;
     UWORD   nScopeToRestore = ODBC_BOTH_DSN;
 
     if ( !SQLGetConfigMode( &nScopeToRestore ) )

Modified: trunk/MYODBCIns/MYODBCInsTest/MYODBCInsTest.cpp
===================================================================
--- trunk/MYODBCIns/MYODBCInsTest/MYODBCInsTest.cpp	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCIns/MYODBCInsTest/MYODBCInsTest.cpp	2006-06-22 19:33:17 UTC (rev 361)
@@ -32,6 +32,7 @@
     QFile fileDebugOut;
 
 private slots:
+    void slotKeywordValues();
     void slotRegisterDriver();
     void slotVerifyRegisterDriver();
     void slotCreateDataSourceName();
@@ -61,6 +62,50 @@
     fileDebugOut.close();
 }
 
+void MYODBCInsTest::slotKeywordValues()
+{
+    QHash<QString,QString>  hashKeywordValues;
+    WCHAR                   szzAttributes[1024];
+    WCHAR *                 pszz = szzAttributes;
+    int                     nLength;
+
+    /* empty, DELIM_NULL, string length */
+    szzAttributes[0] = '\0';
+    szzAttributes[1] = '\0';
+    nLength = MYODBCC::getKeywordValuesLength( szzAttributes );
+    QVERIFY( nLength == 0 );
+
+    /* DELIM_NULL string - as per ConfigDSN() */
+    wcscpy( pszz, TEXT("DRIVER=my driver") );
+    pszz    += 16; *pszz   = '\0'; pszz++;
+    wcscpy( pszz, TEXT("DSN=my dsn") );
+    pszz    += 10; *pszz   = '\0'; pszz++;
+    wcscpy( pszz, TEXT("DATABASE=my database") );
+    pszz    += 20; *pszz   = '\0'; pszz++; 
+    *pszz   = '\0';
+
+    nLength = MYODBCC::getKeywordValuesLength( szzAttributes );
+    QVERIFY( nLength == 48 );
+
+    if ( !MYODBCIns::getKeywordValues( &hashKeywordValues, QString::fromUtf16(
szzAttributes, nLength + 1 ), MYODBCIns::DELIM_NULL ) )
+        QFAIL( "getKeywordValues failed" );
+    QVERIFY( hashKeywordValues.count() == 3 );
+    QVERIFY( hashKeywordValues.value( "DRIVER" ) == "my driver" );
+    QVERIFY( hashKeywordValues.value( "DSN" ) == "my dsn" );
+    QVERIFY( hashKeywordValues.value( "DATABASE" ) == "my database" );
+
+    /* DELIM_SEMI string - as per SQLDriverConnect() */
+    hashKeywordValues.clear();
+    wcscpy( szzAttributes, TEXT("DRIVER=my driver;DSN=my dsn;DATABASE=my database") );
+
+    if ( !MYODBCIns::getKeywordValues( &hashKeywordValues, QString::fromUtf16(
szzAttributes ), MYODBCIns::DELIM_SEMI ) )
+        QFAIL( "getKeywordValues failed" );
+    QVERIFY( hashKeywordValues.count() == 2 );
+    QVERIFY( hashKeywordValues.value( "DRIVER" ) == "my driver" );
+    QVERIFY( !hashKeywordValues.contains( "DSN" ) ); // DRIVER and DSN are mutually
exclusive in this context - we get which ever was provided first
+    QVERIFY( hashKeywordValues.value( "DATABASE" ) == "my database" );
+}
+
 void MYODBCInsTest::slotRegisterDriver()
 {
     MYODBCInsDriver driver;

Modified: trunk/MYODBCSetup/MYODBCSetupLib/ConfigDSNW.cpp
===================================================================
--- trunk/MYODBCSetup/MYODBCSetupLib/ConfigDSNW.cpp	2006-06-20 06:07:12 UTC (rev 360)
+++ trunk/MYODBCSetup/MYODBCSetupLib/ConfigDSNW.cpp	2006-06-22 19:33:17 UTC (rev 361)
@@ -43,7 +43,7 @@
         null byte, and the entire list is terminated with a null byte.
     */
     QHash<QString,QString> hashKeywordValues;
-    if ( !MYODBCIns::getKeywordValues( &hashKeywordValues, QString::fromUtf16(
pszzAttributes, MYODBCC::getKeywordValuesLength( pszzAttributes ) + 1 ),
MYODBCIns::DELIM_NULL ) )
+    if ( !MYODBCIns::getKeywordValues( &hashKeywordValues, QString::fromUtf16(
pszzAttributes, MYODBCC::getKeywordValuesLength( pszzAttributes ) + 2 ),
MYODBCIns::DELIM_NULL ) )
     {
         MYODBCIns::setError( "Data Source string seems invalid.",
ODBC_ERROR_INVALID_KEYWORD_VALUE );
         MYODBCDbgReturn3( "%d", false );
@@ -74,12 +74,26 @@
     {
         case ODBC_ADD_DSN:
             datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_ADD );
-            bReturn = MYODBCSetupDataSourceConfig( hWnd, &datasource );
+            if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
+            {
+                if ( !datasource.doWrite() )
+                {
+                    MYODBCIns::setError( "Failed to add DSN." );
+                    MYODBCDbgReturn3( "%d", false );
+                }
+            }
             break;
 
         case ODBC_CONFIG_DSN:
             datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_EDIT );
-            bReturn = MYODBCSetupDataSourceConfig( hWnd, &datasource );
+            if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
+            {
+                if ( !datasource.doWrite() )
+                {
+                    MYODBCIns::setError( "Failed to update DSN." );
+                    MYODBCDbgReturn3( "%d", false );
+                }
+            }
             break;
 
         case ODBC_REMOVE_DSN:

Modified: trunk/MYODBCSetup/MYODBCSetupLib/MYODBCSetupDataSourceConfig.cpp
===================================================================
--- trunk/MYODBCSetup/MYODBCSetupLib/MYODBCSetupDataSourceConfig.cpp	2006-06-20 06:07:12
UTC (rev 360)
+++ trunk/MYODBCSetup/MYODBCSetupLib/MYODBCSetupDataSourceConfig.cpp	2006-06-22 19:33:17
UTC (rev 361)
@@ -6,9 +6,14 @@
 {
     BOOL bReturn = FALSE;
 
-    // No window handle - no gui - regardless of the fact that we may not use the window
handle anyway :)
+    /*!
+        \internal MYODBC RULE
+
+        No window handle - no gui - regardless of the fact that we may not use the window
handle anyway :)
+        We must return true to support ODBC_ADD_DSN - which allows add even when no GUI.
+    */
     if ( !hWnd )
-        return FALSE;
+        return true;
 
     /*!
         \note   XP

Thread
Connector/ODBC 5 commit: r361 - in trunk: MYODBCC/MYODBCCLib MYODBCC/include MYODBCIns/MYODBCInsLib MYODBCIns/MYODBCInsTest MYODBCSetup/MYODBCSetupLibpharvey22 Jun