List:Commits« Previous MessageNext Message »
From:pharvey Date:June 23 2006 3:12am
Subject:Connector/ODBC 5 commit: r364 - in trunk: MYODBCIns/include MYSQLPlus/MYSQLPlusLib
View as plain text  
Modified:
   trunk/MYODBCIns/include/MYODBCInsDriverConnect.h
   trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
Log:
work on SQLDriverConnect

Modified: trunk/MYODBCIns/include/MYODBCInsDriverConnect.h
===================================================================
--- trunk/MYODBCIns/include/MYODBCInsDriverConnect.h	2006-06-22 21:53:20 UTC (rev 363)
+++ trunk/MYODBCIns/include/MYODBCInsDriverConnect.h	2006-06-23 01:12:48 UTC (rev 364)
@@ -69,7 +69,6 @@
     MYODBCInsDriverConnect( DRIVERCONNECT_METHOD  nConnectMethod =
DRIVERCONNECT_METHOD_DRIVER, 
                             DRIVERCONNECT_PROMPT  nPrompt        =
DRIVERCONNECT_PROMPT_NOPROMPT );  
 
-
     BOOLEAN setConnectString( const QString &stringConnectString );
     BOOLEAN setConnectMethod( DRIVERCONNECT_METHOD nConnectMethod );
     BOOLEAN setPrompt( DRIVERCONNECT_PROMPT nPrompt );

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-22 21:53:20 UTC (rev 363)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-23 01:12:48 UTC (rev 364)
@@ -1986,9 +1986,19 @@
 {
     MYODBCDbgEnter();
 
-    pDiagnostic->doClear();
+    MYODBCInsDriverConnect  driverconnect;
+    SQLRETURN               nReturn     = SQL_SUCCESS;
+    BOOLEAN                 bPrompt     = false;
+    MYODBC_C_DLL            hModule     = NULL;
 
     /*!
+        \internal ODBC RULE
+
+        We clear diagnostic each time an ODBC API call is made (with exceptions).
+    */
+    getDiagnostic()->doClear();
+
+    /*!
         \internal ODBC RULE (DM)
 
         The specified ConnectionHandle had already been used to establish a 
@@ -2001,24 +2011,18 @@
         directly to driver.
     */
     if ( getState() != STATE_C2 )
-        MYODBCDbgReturn( MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_08002, 0, NULL ) );
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_08002 ) );
 
-    MYODBC_INS_DATASOURCE * pDataSource = MYODBCInsAllocDataSource(
MYODBC_INS_DATASOURCE_MODE_DRIVER_CONNECT );
-    MYODBC_INS_DRIVER *     pDriver     = MYODBCInsAllocDriver();      /* we have to read
in driver info to get setup lib */
-    SQLRETURN               nReturn     = SQL_SUCCESS;
-    MYODBC_C_BOOL           bPrompt     = MYODBC_C_FALSE;
-    char                    szError[1024];
-    MYODBC_C_DLL            hModule     = NULL;
+    /*!
+        \internal MYODBC RULE
 
-    /* parse incoming string */
-    if ( !MYODBCInsReadConnectStr( pDataSource, (LPCSTR)pszInConnectionString ) )
-    {
-        nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, "Failed to parse
the incoming connect string." );
-        goto MYODBCDrvDriverConnectExit1;
-    }
+        We generalize some of the errors that can occur while parsing the connection
string.
+    */
+    if ( !driverconnect.setConnectString( QString::fromUtf16( pszInConnectionString ) ) )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, "Failed
to apply parsed incoming connect string." ) );
 
     /*!
-        \internal ODBC Rule
+        \internal ODBC RULE
 
         If the connection string contains the DSN keyword, the driver 
         retrieves the information for the specified data source (and
@@ -2026,14 +2030,15 @@
         having precedence).
 
         \note
-                This also allows us to get pszDRIVER (if not already given).
+
+        This also allows us to get pszDRIVER (if not already given).
     */    
-    if ( pDataSource->pszDSN )
+    if ( !driverconnect.getName().isEmpty() )
     {
-        if ( !MYODBCInsReadDataSource( pDataSource, pDataSource->pszDSN ) )
+        if ( !driverconnect.doRead() )
         {
             /*!
-                \internal ODBC Rule
+                \internal ODBC RULE
 
                 Establish a connection to a data source that is not defined in the system

                 information. If the application supplies a partial connection string, the

@@ -2042,12 +2047,6 @@
         }
     }
 
-    /* 
-        Make pDataSource good for mysql_real_connect(). Mostly
-        means making some "" values NULL.
-    */
-    MYODBCInsDefaultDataSource( pDataSource );
-
     /*!
        \internal MYODBC Rule
 
@@ -2064,12 +2063,8 @@
        if the DSN does not exist the app can at least provide the driver
        name for us in the connection string.
     */
-    if ( !pDataSource->pszDRIVER && nDriverCompletion != SQL_DRIVER_NOPROMPT )
-    {
-        sprintf( szError, "Need driver name to lookup setup library. DSN=(%s)\n",
pDataSource->pszDSN );
-        nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, szError );
-        goto MYODBCDrvDriverConnectExit1;
-    }
+    if ( driverconnect.getDRIVER().isEmpty() && nDriverCompletion !=
SQL_DRIVER_NOPROMPT )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, "Need
driver name to lookup setup library." ) );
 
     /*!
        \internal ODBC Rule
@@ -2077,13 +2072,10 @@
        We can not present a prompt if we have a null window handle.
     */
     if ( !hWnd && nDriverCompletion != SQL_DRIVER_NOPROMPT )
-    {
-        nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_IM008, 0, "Invalid window
handle for connection completion argument." );
-        goto MYODBCDrvDriverConnectExit1;
-    }
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_IM008, 0,
"Invalid window handle for connection completion argument." ) );
 
     /*!
-        \internal ODBC Rule
+        \internal ODBC RULE
 
         We only prompt if we need to. 
 
@@ -2095,83 +2087,80 @@
     switch ( nDriverCompletion )
     {
         case SQL_DRIVER_PROMPT:
-            pDataSource->nPrompt= MYODBC_INS_DATASOURCE_PROMPT_PROMPT;
+            driverconnect.setPrompt( MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_PROMPT
);
             bPrompt             = MYODBC_C_TRUE;
             break;
 
         case SQL_DRIVER_COMPLETE:
-            pDataSource->nPrompt = MYODBC_INS_DATASOURCE_PROMPT_COMPLETE;
-            if ( MYODBCDrvConnect( pDbc, pDataSource ) == SQL_SUCCESS )
+            driverconnect.setPrompt(
MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_COMPLETE );
+            nReturn = doConnect( driverconnect );
+            if ( SQL_SUCCEEDED( nReturn ) )
                 goto MYODBCDrvDriverConnectExit3;
             bPrompt = MYODBC_C_TRUE;
             break;
 
         case SQL_DRIVER_COMPLETE_REQUIRED:
-            pDataSource->nPrompt = MYODBC_INS_DATASOURCE_PROMPT_REQUIRED;
-            if ( MYODBCDrvConnect( pDbc, pDataSource ) == SQL_SUCCESS )
+            driverconnect.setPrompt(
MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_REQUIRED );
+            nReturn = doConnect( driverconnect );
+            if ( SQL_SUCCEEDED( nReturn ) )
                 goto MYODBCDrvDriverConnectExit3;
             bPrompt = MYODBC_C_TRUE;
             break;
 
         case SQL_DRIVER_NOPROMPT:
-            pDataSource->nPrompt = MYODBC_INS_DATASOURCE_PROMPT_NOPROMPT;
+            driverconnect.setPrompt(
MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_NOPROMPT );
             /*!
                \internal ODBC Rule
 
                We need a DSN or DRIVER in order to work without prompting.
             */    
-            if ( !pDataSource->pszDSN && !pDataSource->pszDRIVER )
-            {
-                nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_IM007, 0, "Missing
DSN and/or DRIVER and SQL_DRIVER_NOPROMPT." );
-                goto MYODBCDrvDriverConnectExit1;
-            }
-            break;
+            if ( driverconnect.getName().isEmpty() &&
driverconnect.getDRIVER().isEmpty() )
+                MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_IM007, 0,
"Missing DSN and/or DRIVER and SQL_DRIVER_NOPROMPT." ) );
+
+            nReturn = doConnect( driverconnect );
+            if ( SQL_SUCCEEDED( nReturn ) )
+                goto MYODBCDrvDriverConnectExit3;
+            goto MYODBCDrvDriverConnectExit2;
+
         default:
-            {
-                nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY110, 0, "Invalid
driver completion." );
-                goto MYODBCDrvDriverConnectExit1;
-            }
+                MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY110, 0,
"Invalid driver completion." ) );
     }
 
+    /* failed to connect above so lets take it to another level */
     if ( bPrompt )
     {
-        BOOL (*pFunc)( SQLHDBC, SQLHWND, MYODBC_INS_DATASOURCE * );
+        BOOL (*pFunc)( SQLHDBC, SQLHWND, MYODBCInsDriverConnect * );
 
         /* 
            At this point we should have a driver name (friendly name) either loaded
            from DSN or provided in connection string. So lets determine the setup
            library file name (better to not assume name). We read from ODBC system 
            info. This allows someone to configure for a custom setup interface.
+           ya - we are good like that :)
         */
-        if ( !MYODBCInsReadDriver( pDriver, pDataSource->pszDRIVER ) )
-        {
-            sprintf( szError, "Could not find driver %s in system information.",
pDataSource->pszDRIVER );
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, szError );
-            goto MYODBCDrvDriverConnectExit1;
-        }
+        MYODBCInsDriver driver;
+        if ( !driver.doRead( driverconnect.getDRIVER() ) )
+            MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
QString( "Could not find driver %1 in system information." ).arg(
driverconnect.getDRIVER() ) ) );
 
-        if ( !pDriver->pszSETUP )
-        {
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, "Could not
determine the file name of setup library." );
-            goto MYODBCDrvDriverConnectExit1;
-        }
+        if ( driver.getSETUP().isEmpty() )
+            MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
"Could not determine the file name of setup library." ) );
 
         /*
-           We dynamically load setup lib to avoid introducing gui link dependencies 
-           into driver and also allowing the setup library to be pluggable. So 
-           a ncurses ver or a gtk ver etc could be created/used and this code is ok.
+           We dynamically load setup lib to avoid introducing any additional gui based 
+           dependencies into driver and also allowing the setup library to be pluggable. 
+           So a ncurses ver or a gtk ver etc could be created/used and this code is ok.
         */
         MYODBCCInitLibrary();
         if ( !(hModule = MYODBCCLoadLibrary( pDriver->pszSETUP )) )
         {
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, "Could not
load the setup library." );
+            nReturn = getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, "Could not
load the setup library." );
             goto MYODBCDrvDriverConnectExit1;
         }
         /*
            The setup library should expose a MYODBCSetupDriverConnect() C entry point
            for us to call.
         */
-        pFunc = (BOOL (*)( SQLHDBC, SQLHWND, MYODBC_INS_DATASOURCE * ))
MYODBCCGetProcAddress( hModule, "MYODBCSetupDriverConnect" );
+        pFunc = (BOOL (*)( SQLHDBC, SQLHWND, MYODBCInsDriverConnect * ))
MYODBCCGetProcAddress( hModule, "MYODBCSetupDriverConnect" );
         if ( pFunc == NULL )
         {
 #ifdef WIN32
@@ -2184,11 +2173,11 @@
                           (LPTSTR) &pszMsg,
                           0, 
                           NULL );
-            MYODBCCfprintf( stderr, pszMsg );
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, pszMsg );
+//            MYODBCCfprintf( stderr, pszMsg );
+            nReturn = getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, pszMsg );
             LocalFree( pszMsg );
 #else
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, "Could not
find MYODBCSetupDriverConnect in setup library." );
+            nReturn = getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, "Could not
find MYODBCSetupDriverConnect in setup library." );
 #endif
             goto MYODBCDrvDriverConnectExit2;
         }
@@ -2196,18 +2185,20 @@
         /*
            Prompt. Function returns false if user cancels.
         */
-        if ( !pFunc( pDbc, hWnd, pDataSource ) )
+        if ( !pFunc( pDbc, hWnd, &driver ) )
         {
-            nReturn = MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_HY000, 0, "User
cancelled." );
+            nReturn = getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, "User
cancelled." );
             goto MYODBCDrvDriverConnectExit2;
         }
     } /* if prompt */
 
     /* lordy tunderin by - we finally get here! */
-    if ( (nReturn = MYODBCDrvConnect( pDbc, pDataSource )) != SQL_SUCCESS )
+    nReturn = doConnect( driverconnect );
+    if ( !SQL_SUCCEEDED( nReturn ) )
         goto MYODBCDrvDriverConnectExit2;
 
 MYODBCDrvDriverConnectExit3:
+    /* we have a SQL_SUCCESS or SQL_SUCCESS_WITH_INFO and we are connected so update our
state */
     pDbc->attr_current_catalog  = MYODBCCStrDup( pDataSource->pszDATABASE, SQL_NTS
);
     pDbc->nFlag                 = atol( pDataSource->pszOPTION );
     pDbc->nPort                 = atoi( pDataSource->pszPORT );
@@ -2240,7 +2231,7 @@
             *pszOutConnectionString = '\0';
             if ( !MYODBCInsWriteConnectStr( pDataSource, (char *)pszOutConnectionString,
nBufferLength ) )
             {
-                MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_01000, 0, "Something went
wrong while building the outgoing connect string." );
+                getDiagnostic()->doAppend( MDiagnostic::DIA_01000, 0, "Something went
wrong while building the outgoing connect string." );
                 nReturn = SQL_SUCCESS_WITH_INFO;
             }
         }
@@ -2253,10 +2244,6 @@
     if ( hModule )
         MYODBCCFreeLibrary( hModule );
 
-MYODBCDrvDriverConnectExit1:
-    MYODBCInsFreeDriver( pDriver );
-    MYODBCInsFreeDataSource( pDataSource );
-
     MYODBCDbgReturn( nReturn );
 }
 

Thread
Connector/ODBC 5 commit: r364 - in trunk: MYODBCIns/include MYSQLPlus/MYSQLPlusLibpharvey23 Jun