List:Commits« Previous MessageNext Message »
From:pharvey Date:May 29 2006 4:12am
Subject:Connector/ODBC 5 commit: r283 - MYSQLPlus/MYSQLPlusLib
View as plain text  
Modified:
   MYSQLPlus/MYSQLPlusLib/MConnection.cpp
Log:


Modified: MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-05-28 17:35:19 UTC (rev 282)
+++ MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-05-29 04:11:59 UTC (rev 283)
@@ -231,6 +231,8 @@
 {
     MYODBCDbgEnter();
 
+    BOOLEAN bCopyOk;
+
     /* handle case where we are not provided viable pnStringLength */
     SQLINTEGER      nLen        = 0;
     SQLINTEGER *    pnLen;
@@ -303,23 +305,15 @@
             if ( nBufferLength < 1 )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY090 ) );
 
-            /* copy string */
-            if ( pValue )
-            {
-                if ( getCurrentCatalog().isNull() )
-                {
-                    MYODBCDbgReturn( SQL_NO_DATA );
-                    *pnLen = 0;
-                }
-                else if ( !MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getCurrentCatalog().utf16() ) )
-                    MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doStringCopyOut() failed.") ) );
-            }
+            *pnLen = 0;
 
-            /* copy len */
-            *pnLen = getCurrentCatalog().length() * sizeof(SQLWCHAR);
+            if ( getCurrentCatalog().isNull() )
+                MYODBCDbgReturn( SQL_NO_DATA );
 
-            /* are we truncated */
-            if ( *pnLen > nBufferLength )
+            /* copy string */
+            bCopyOk = MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getCurrentCatalog().utf16(), pnLen );
+            *pnLen = *pnLen * sizeof(SQLWCHAR); /* because we have char len but we want
byte len */
+            if ( !bCopyOk )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_01004 ) );
             break;
 
@@ -368,23 +362,15 @@
             if ( nBufferLength < 1 )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY090 ) );
 
-            /* copy string */
-            if ( pValue )
-            {
-                if ( getTracefile().isNull() )
-                {
-                    MYODBCDbgReturn( SQL_NO_DATA );
-                    *pnLen = 0;
-                }
-                else if ( !MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getTracefile().utf16() ) )
-                    MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doStringCopyOut() failed.") ) );
-            }
+            *pnLen = 0;
 
-            /* copy len */
-            *pnLen = getTracefile().length() * sizeof(SQLWCHAR);
+            if ( getTracefile().isNull() )
+                MYODBCDbgReturn( SQL_NO_DATA );
 
-            /* are we truncated */
-            if ( *pnLen > nBufferLength )
+            /* copy string */
+            bCopyOk = MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getTracefile().utf16(), pnLen );
+            *pnLen = *pnLen * sizeof(SQLWCHAR); /* because we have char len but we want
byte len */
+            if ( !bCopyOk )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_01004 ) );
             break;
 
@@ -397,23 +383,15 @@
             if ( nBufferLength < 1 )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY090 ) );
 
-            /* copy string */
-            if ( pValue )
-            {
-                if ( getTranslateLib().isNull() )
-                {
-                    MYODBCDbgReturn( SQL_NO_DATA );
-                    *pnLen = 0;
-                }
-                else if ( !MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getTranslateLib().utf16() ) )
-                    MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doStringCopyOut() failed.") ) );
-            }
+            *pnLen = 0;
 
-            /* copy len */
-            *pnLen = getTranslateLib().length() * sizeof(SQLWCHAR);
+            if ( getTranslateLib().isNull() )
+                MYODBCDbgReturn( SQL_NO_DATA );
 
-            /* are we truncated */
-            if ( *pnLen > nBufferLength )
+            /* copy string */
+            bCopyOk = MYODBCC::doStringCopyOut( (SQLWCHAR*)pValue, nBufferLength /
sizeof(SQLWCHAR), (SQLWCHAR*)getTranslateLib().utf16(), pnLen );
+            *pnLen = *pnLen * sizeof(SQLWCHAR); /* because we have char len but we want
byte len */
+            if ( !bCopyOk )
                 MYODBCDbgReturn( pDiagnostic->doAppend( MDiagnostic::DIA_01004 ) );
             break;
 
@@ -829,25 +807,22 @@
                 /*!
                     \internal MYODBC Rule
 
-                    We account for the fact that the cached current catalog name may be
inaccurate due
+                    We account for the fact that SQL_ATTR_CURRENT_CATALOG may be
inaccurate due
                     to the possible use of "USE DATABASE". So this may not be the value
of 'database' from
                     a DSN.
                 */
-                /* update the cached value for the current catalog */
-                SQLRETURN nReturn = MYODBCDrvGetCatalog( pDbc );
-                if ( !SQL_SUCCEEDED(nReturn) )
-                    return nReturn;
-                /* return the current catalog */
-                if ( pDbc->attr_current_catalog )
+                QString stringDatabaseName = getCurrentCatalog();
+
+                if ( stringDatabaseName.isEmpty() )
                 {
-                    bCopyOk = MYODBCC::doStringCopyOut( pszSQLWCHAR, nBufferLength /
sizeof(SQLWCHAR), pDbc->attr_current_catalog, &nStringLengthChars );
+                    bCopyOk = MYODBCC::doStringCopyOut( pszSQLWCHAR, nBufferLength /
sizeof(SQLWCHAR), L"", &nStringLengthChars );
                     *pnStringLengthBytes = nStringLengthChars * sizeof(SQLWCHAR);
                     if ( !bCopyOk )
                         MYODBCDbgReturn( getDiagnostic()->doAppend(
MDiagnostic::DIA_01004 ) );
                 }
                 else
                 {
-                    bCopyOk = MYODBCC::doStringCopyOut( pszSQLWCHAR, nBufferLength /
sizeof(SQLWCHAR), L"", &nStringLengthChars );
+                    bCopyOk = MYODBCC::doStringCopyOut( pszSQLWCHAR, nBufferLength /
sizeof(SQLWCHAR), stringDatabaseName.utf16(), &nStringLengthChars );
                     *pnStringLengthBytes = nStringLengthChars * sizeof(SQLWCHAR);
                     if ( !bCopyOk )
                         MYODBCDbgReturn( getDiagnostic()->doAppend(
MDiagnostic::DIA_01004 ) );
@@ -896,6 +871,7 @@
             if ( !bCopyOk )
                 MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_01004 )
);
             break;
++++++++++++++++
         case SQL_DRIVER_HDBC:
             /*!
                 \internal MYODBC Rule
@@ -916,20 +892,29 @@
             break;
         case SQL_DRIVER_HDESC:
             /*!
-                \internal MYODBC Rule
+                \internal ODBC RULE (DM)
 
-                We are not, of course, a Driver Manager. However; applications may link
to
-                us directly so lets handle this.
+                The InfoType argument was SQL_DRIVER_HDESC, and the value pointed to by 
+                InfoValuePtr was not a valid descriptor handle.
+
+                \note
+
+                We can not validate the handle type so we assume any non-null is valid.
             */
+            if ( !pInfoValue )
+                MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY024 )
);
+
             /*!
-                \internal ODBC Rule
+                \internal
+                \note
 
-                (DM) The InfoType argument was SQL_DRIVER_HDESC, and the value pointed to
by 
-                InfoValuePtr was not a valid descriptor handle.
+                The request is to get the *drivers* descriptor handle for the given
*driver managers* descriptor
+                handle. 
+
+                The only way we would get this request is if the app linked directly to
the driver - if there
+                is no driver manager in the equation. With this in mind we must have been
passed our own 
+                descriptor handle so we just return success.
             */
-            if ( !pInfoValue || MYODBCRttiType( pInfoValue ) != MYODBC_RTTI_DES )
-                MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY024 )
);
-            *pnSQLUINTEGER  = (SQLUINTEGER)pInfoValue;
             break;
         case SQL_DRIVER_HLIB:
             /*!
@@ -2455,6 +2440,41 @@
 {
     MYODBCDbgEnter();
 
+    /*!
+        \internal MYODBC RULE
+
+        If we are called while we are connected - then we return the current database
accounting for
+        any "USE DATABASE" possibly submitted since we connected. Otherwise we just
return the 
+        connection attribute.
+
+        We do NOT alter the connection attribute just because the current database has
been changed
+        by other means.
+    */
+    if ( getState() > STATE_C3 )
+    {
+        QString stringDatabase;
+
+        if ( !mysql_query( getMySQL(), "SELECT database()" ) )
+        {
+            MYSQL_RES *pResult = mysql_use_result( getMySQL() );
+            if ( pResult )
+            {
+                MYSQL_ROW pRow = mysql_fetch_row( pResult );
+                if ( pRow && pRow[0] )
+                    stringDatabase = pRow[0];
+
+                mysql_free_result( pResult ); 
+            }
+            else
+                getDiagnotsic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno(
getMySQL() ), mysql_error( getMySQL() ) );
+        }
+        else
+            getDiagnotsic()->doAppend( MDiagnostic::DIA_HY000, mysql_errno( getMySQL()
), mysql_error( getMySQL() ) );
+        
+        if ( !stringDatabase.isEmpty() )
+            MYODBCDbgReturn3( "%s", stringDatabase );
+    }
+
     MYODBCDbgReturn3( "%s", stringCurrentCatalog );
 }
 

Thread
Connector/ODBC 5 commit: r283 - MYSQLPlus/MYSQLPlusLibpharvey29 May