List:Commits« Previous MessageNext Message »
From:pharvey Date:June 23 2006 7:34pm
Subject:Connector/ODBC 5 commit: r366 - in trunk/MYSQLPlus: MYSQLPlusLib include
View as plain text  
Modified:
   trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
   trunk/MYSQLPlus/include/MConnection.h
Log:
more work on SQLDriverConnect

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-23 18:54:19 UTC (rev 365)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-23 19:34:23 UTC (rev 366)
@@ -1779,42 +1779,8 @@
     if ( !stringAuthentication.isEmpty() )
         datasource.setPWD( stringAuthentication );
 
-    /* allocate the MYSQL handle (this will silently do the library init as needed) */
-    pMySQL = mysql_init( NULL );
-    
-    /* translate our flags into client while appling pre-connect flags */
-    ulong nFlags = getClientFlag( datasource.getOPTION().toULong(), datasource.getSTMT()
);
-
-    /* ask mysql for a connection */
-    if ( !mysql_real_connect( (MYSQL*)pMySQL,
-                           datasource.getSERVER().toUtf8().data(),
-                           datasource.getUID().toUtf8().data(),
-                           datasource.getPWD().toUtf8().data(),
-                           datasource.getDATABASE().toUtf8().data(),
-                           datasource.getPORT().toInt(),
-                           datasource.getSOCKET().toUtf8().data(),
-                           (uint)nFlags ) )
-    {
-        pDiagnostic->doAppend( MDiagnostic::DIA_HY000, mysql_errno( (MYSQL*)pMySQL ),
mysql_error( (MYSQL*)pMySQL ) );
-        mysql_close( (MYSQL*)pMySQL );
-        pMySQL = NULL;
-        MYODBCDbgReturn( SQL_ERROR );
-    }
-
-    /*! 
-        \internal 
-        \todo
-
-        getDiagnostic()->setServerName();
-    */
-    getDiagnostic()->setConnectionName( datasource.getName() );
-
-    setCurrentCatalog( datasource.getDATABASE() );
-    setDataSourceName( datasource.getName() );
-    setUserIdentifier( datasource.getUID() );
-    setState( STATE_C4 );
-
-    MYODBCDbgReturn( SQL_SUCCESS );
+    /* do it */
+    MYODBCDbgReturn( doConnectInternal( &datasource ) );
 }
 
 SQLRETURN MConnection::doConnect( MYODBCInsDataSource *pDataSource )
@@ -1841,41 +1807,8 @@
     if ( getState() != STATE_C2 )
         MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_08002 ) );
 
-    /* allocate the MYSQL handle (this will silently do the library init as needed) */
-    pMySQL = mysql_init( NULL );
-
-    /* translate our flags into client while appling pre-connect flags */
-    ulong nFlags = getClientFlag( pDataSource->getOPTION().toULong(),
pDataSource->getSTMT() );
-
-    /* ask mysql for a connection */
-    if ( !mysql_real_connect( (MYSQL*)pMySQL,
-                           pDataSource->getSERVER().toUtf8().data(),
-                           pDataSource->getUID().toUtf8().data(),
-                           pDataSource->getPWD().toUtf8().data(),
-                           pDataSource->getDATABASE().toUtf8().data(),
-                           pDataSource->getPORT().toInt(),
-                           pDataSource->getSOCKET().toUtf8().data(),
-                           (uint)nFlags ) )
-    {
-        pDiagnostic->doAppend( MDiagnostic::DIA_HY000, mysql_errno( (MYSQL*)pMySQL ),
mysql_error( (MYSQL*)pMySQL ) );
-        mysql_close( (MYSQL*)pMySQL );
-        pMySQL = NULL;
-        MYODBCDbgReturn( SQL_ERROR );
-    }
-
-    /*! 
-        \internal 
-        \todo
-
-        getDiagnostic()->setConnectionName();
-        getDiagnostic()->setServerName();
-    */
-
-    setCurrentCatalog( pDataSource->getDATABASE() );
-    setUserIdentifier( pDataSource->getUID() );
-    setState( STATE_C4 );
-
-    MYODBCDbgReturn( SQL_SUCCESS );
+    /* do it */
+    MYODBCDbgReturn( doConnectInternal( pDataSource ) );
 }
 
 SQLRETURN MConnection::doDisconnect()
@@ -2088,23 +2021,23 @@
     {
         case SQL_DRIVER_PROMPT:
             driverconnect.setPrompt( MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_PROMPT
);
-            bPrompt             = MYODBC_C_TRUE;
+            bPrompt = true;
             break;
 
         case SQL_DRIVER_COMPLETE:
             driverconnect.setPrompt(
MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_COMPLETE );
-            nReturn = doConnect( driverconnect );
+            nReturn = doConnectInternal( &driverconnect );
             if ( SQL_SUCCEEDED( nReturn ) )
                 goto MYODBCDrvDriverConnectExit3;
-            bPrompt = MYODBC_C_TRUE;
+            bPrompt = true;
             break;
 
         case SQL_DRIVER_COMPLETE_REQUIRED:
             driverconnect.setPrompt(
MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT_REQUIRED );
-            nReturn = doConnect( driverconnect );
+            nReturn = doConnectInternal( &driverconnect );
             if ( SQL_SUCCEEDED( nReturn ) )
                 goto MYODBCDrvDriverConnectExit3;
-            bPrompt = MYODBC_C_TRUE;
+            bPrompt = true;
             break;
 
         case SQL_DRIVER_NOPROMPT:
@@ -2117,7 +2050,7 @@
             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 );
+            nReturn = doConnectInternal( &driverconnect );
             if ( SQL_SUCCEEDED( nReturn ) )
                 goto MYODBCDrvDriverConnectExit3;
             goto MYODBCDrvDriverConnectExit2;
@@ -2193,21 +2126,11 @@
     } /* if prompt */
 
     /* lordy tunderin by - we finally get here! */
-    nReturn = doConnect( driverconnect );
+    nReturn = doConnectInternal( &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 );
-    pDbc->pszDataSourceName     = MYODBCCStrDup( pDataSource->pszDSN, SQL_NTS );
-    pDbc->pszPassword           = MYODBCCStrDup( pDataSource->pszPASSWORD, SQL_NTS
);
-    pDbc->pszServer             = MYODBCCStrDup( pDataSource->pszSERVER, SQL_NTS );
-    pDbc->pszUser               = MYODBCCStrDup( pDataSource->pszUSER, SQL_NTS );
-    MYODBCDrvSetDbcState( pDbc, MYODBC_DRV_STATE_C4 );
-
     /*! 
         \internal ODBC Rule
 
@@ -2228,8 +2151,9 @@
         if ( pszOutConnectionString != pszInConnectionString )
 #endif
         {
-            *pszOutConnectionString = '\0';
-            if ( !MYODBCInsWriteConnectStr( pDataSource, (char *)pszOutConnectionString,
nBufferLength ) )
+            QString stringConnectString = driverconnect.getConnectString();
+
+            if ( !MYODBCC::doStringCopyOut( pszOutConnectionString, nBufferLength /
sizeof(SQLWCHAR), stringConnectString.utf16() ) )
             {
                 getDiagnostic()->doAppend( MDiagnostic::DIA_01000, 0, "Something went
wrong while building the outgoing connect string." );
                 nReturn = SQL_SUCCESS_WITH_INFO;
@@ -2931,34 +2855,68 @@
     MYODBCDbgReturn3( "%d", nTxnIsolation );
 }
 
-SQLRETURN MConnection::doConnect( MYODBCInsDriverConnect *pDriverConnect )
+SQLRETURN MConnection::doConnectInternal( MYODBCInsDataSource *pDataSource )
 {
     MYODBCDbgEnter();
 
-    ulong nFlag = 0;
+    /* allocate the MYSQL handle (this will silently do the library init as needed) */
+    pMySQL = mysql_init( NULL );
 
-    pDbc->pMySQL = mysql_init( NULL );
+    /* translate our flags into client while appling pre-connect flags */
+    ulong nFlags = getClientFlag( pDataSource->getOPTION().toULong(),
pDataSource->getSTMT() );
 
-    nFlag = MYODBCDrvGetClientFlag( pDbc->pMySQL, 
-                                    pDataSource->pszOPTION ? atol(
pDataSource->pszOPTION ) : 0, 
-                                    (uint)pDbc->attr_login_timeout, 
-                                    pDataSource->pszSTMT ? pDataSource->pszSTMT :
"" );
-
-    if ( !mysql_real_connect( pDbc->pMySQL,
-                              pDataSource->pszSERVER, 
-                              pDataSource->pszUSER,
-                              pDataSource->pszPASSWORD,
-                              pDataSource->pszDATABASE,
-                              atoi( pDataSource ->pszPORT ),
-                              pDataSource->pszSOCKET,
-                              nFlag ) )
+    /* ask mysql for a connection */
+    if ( !mysql_real_connect( (MYSQL*)pMySQL,
+                           pDataSource->getSERVER().toUtf8().data(),
+                           pDataSource->getUID().toUtf8().data(),
+                           pDataSource->getPWD().toUtf8().data(),
+                           pDataSource->getDATABASE().toUtf8().data(),
+                           pDataSource->getPORT().toInt(),
+                           pDataSource->getSOCKET().toUtf8().data(),
+                           (uint)nFlags ) )
     {
-        MYODBCDiaAppend( pDbc->hDia, MYODBC_DIA_08001, mysql_errno( pDbc->pMySQL ),
(SQLCHAR*)mysql_error( pDbc->pMySQL ) );
-        mysql_close( pDbc->pMySQL );
-        pDbc->pMySQL    = NULL;
+        pDiagnostic->doAppend( MDiagnostic::DIA_08001, mysql_errno( (MYSQL*)pMySQL ),
mysql_error( (MYSQL*)pMySQL ) );
+        mysql_close( (MYSQL*)pMySQL );
+        pMySQL = NULL;
         MYODBCDbgReturn( SQL_ERROR );
     }
 
+    /*! 
+        \internal ODBC RULE
+        \todo
+
+        A string that indicates the name of the connection that the diagnostic record
relates to. This field is 
+        driver-defined. For diagnostic data structures associated with the environment
handle and for diagnostics 
+        that do not relate to any connection, this field is a zero-length string.
+
+        \note
+
+        We query the server for its name and use it here.
+    */
+    // getDiagnostic()->setConnectionName( zzzzzzzz );
+
+    /*!
+        \internal ODBC RULE
+
+        A string that indicates the server name that the diagnostic record relates to. It
is the same as the value 
+        returned for a call to SQLGetInfo with the SQL_DATA_SOURCE_NAME option. For
diagnostic data structures 
+        associated with the environment handle and for diagnostics that do not relate to
any server, this field is 
+        a zero-length string.
+
+        A character string with the data source name used during connection. If the
application called SQLConnect, 
+        this is the value of the szDSN argument. If the application called
SQLDriverConnect or SQLBrowseConnect, 
+        this is the value of the DSN keyword in the connection string passed to the
driver. If the connection string 
+        did not contain the DSN keyword (such as when it contains the DRIVER keyword),
this is an empty string.
+    */
+    getDiagnostic()->setServerName( pDataSource->getName() );
+
+    /* we avoid using setCurrentCatalog() as it will try to "USE db" and that is
redundant in this context */
+    stringCurrentCatalog = pDataSource->getDATABASE();
+
+    setDataSourceName( pDataSource->getName() );
+    setUserIdentifier( pDataSource->getUID() );
+    setState( STATE_C4 );
+
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 

Modified: trunk/MYSQLPlus/include/MConnection.h
===================================================================
--- trunk/MYSQLPlus/include/MConnection.h	2006-06-23 18:54:19 UTC (rev 365)
+++ trunk/MYSQLPlus/include/MConnection.h	2006-06-23 19:34:23 UTC (rev 366)
@@ -110,7 +110,7 @@
     qint32      getTxnIsolation();
 
     /* doers */
-    SQLRETURN   doConnect( MYODBCInsDriverConnect *pDriverConnect );
+    SQLRETURN   doConnectInternal( MYODBCInsDataSource *pDataSource );
     SQLRETURN   doSubmitCommand( const QString &stringCommand );
     BOOLEAN     doServerAliveSanityCheck();
 

Thread
Connector/ODBC 5 commit: r366 - in trunk/MYSQLPlus: MYSQLPlusLib includepharvey23 Jun