List:Commits« Previous MessageNext Message »
From:pharvey Date:June 27 2006 11:40pm
Subject:Connector/ODBC 5 commit: r407 - trunk/MYSQLPlus/MYSQLPlusLib
View as plain text  
Modified:
   trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
   trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
   trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h
   trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
Log:
- completed ROWID request for SQLSpecialColumns
- fixed a mem leak bug in SQLColumns

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-27 21:52:40 UTC (rev 406)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-06-27 23:40:37 UTC (rev 407)
@@ -4529,7 +4529,7 @@
         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.
     */
-    getDiagnostic()->setConnectionName( mysql_get_host_info( pMySQL ) ) );
+    getDiagnostic()->setConnectionName( mysql_get_host_info( (MYSQL*)pMySQL ) );
 
     /*!
         \internal ODBC RULE
@@ -4589,7 +4589,7 @@
         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.
     */
-    getDiagnostic()->setConnectionName( mysql_get_host_info( pMySQL ) ) );
+    getDiagnostic()->setConnectionName( mysql_get_host_info( (MYSQL*)pMySQL ) );
 
     /*!
         \internal ODBC RULE

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp	2006-06-27 21:52:40 UTC (rev 406)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp	2006-06-27 23:40:37 UTC (rev 407)
@@ -709,9 +709,21 @@
     pDescriptor->doAppend( SQL_SMALLINT, "DECIMAL_DIGITS", SQL_NULLABLE );
     pDescriptor->doAppend( SQL_SMALLINT, "PSEUDO_COLUMN", SQL_NULLABLE );
 
-    /* do it */
-    nReturn = doAppendSpecialColumnsCatalogs( nIdentifierType, stringCatalogFilter,
stringSchemaFilter, stringTableFilter, nScope, nNullable );
+    /*!
+        \internal ODBC RULE
 
+        SQL_NO_NULLS: Exclude special columns that can have NULL values. Some drivers
cannot support SQL_NO_NULLS, and these 
+        drivers will return an empty result set if SQL_NO_NULLS was specified.
Applications should be prepared for this case 
+        and request SQL_NO_NULLS only if it is absolutely required.
+
+        \internal MYODBC RULE
+
+        We do not support SQL_NO_NULLS as this may lead to the app using an incomplete
set of columns to uniquely identify 
+        the row.
+    */
+    if ( nNullable != SQL_NO_NULLS )
+        nReturn = doAppendSpecialColumnsCatalogs( nIdentifierType, stringCatalogFilter,
stringSchemaFilter, stringTableFilter, nScope, nNullable );
+
     /*!
         \internal ODBC RULE
 
@@ -1639,6 +1651,7 @@
     unsigned int    nFields;
     unsigned int    nField;
     MYSQL_FIELD *   pField;
+    SQLRETURN       nReturn = SQL_SUCCESS;
 
     /*!
         \todo
@@ -1684,9 +1697,12 @@
 
             So we translate MYLSQ_FIELD into a descriptor and then map descriptor into
result row.
         */            
-        SQLRETURN nReturn = doLoadMetaDataField( nField + 1, mysql_fetch_field_direct(
pResult, nField ), &descriptor );
+        nReturn = doLoadMetaDataField( nField + 1, mysql_fetch_field_direct( pResult,
nField ), &descriptor );
         if ( !SQL_SUCCEEDED( nReturn ) )
-            MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Failed to store field descriptor information.") ) );
+        {
+            getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, tr("Failed to store
field descriptor information.") );
+            break;
+        }
 
         /*!
             \todo
@@ -1901,7 +1917,16 @@
 
         if ( bMatch )
         {
-            nReturn = doAppendSpecialColumnsColumns( nIdentifierType, stringCatalog,
stringSchema, stringlistTables[n], nScope, nNullable );
+            switch ( nIdentifierType )
+            {
+                case SQL_BEST_ROWID:
+                    nReturn = doAppendSpecialColumnsRowID( stringCatalog, stringSchema,
stringlistTables[n], nScope, nNullable );
+                    break;
+                case SQL_ROWVER:
+                    nReturn = doAppendSpecialColumnsRowVer( stringCatalog, stringSchema,
stringlistTables[n], nScope, nNullable );
+                    break;
+            }
+
             if ( !SQL_SUCCEEDED( nReturn ) )
                 break;
         }
@@ -1910,12 +1935,121 @@
     MYODBCDbgReturn( nReturn );
 }
 
-SQLRETURN MResultPlus::doAppendSpecialColumnsColumns( SQLSMALLINT nIdentifierType, const
QString &stringCatalog, const QString &stringSchema, const QString
&stringTable, SQLSMALLINT nScope, SQLSMALLINT nNullable )
+SQLRETURN MResultPlus::doAppendSpecialColumnsRowID( const QString &stringCatalog,
const QString &stringSchema, const QString &stringTable, SQLSMALLINT nScope,
SQLSMALLINT nNullable )
 {
+    QString         stringSQL;
+    MYSQL_RES *     pResult = NULL;
+    unsigned int    nFields;
+    unsigned int    nField;
+    MYSQL_FIELD *   pField;
+    SQLRETURN       nReturn = SQL_SUCCESS;
+
+    /*!
+        \internal
+        \todo
+
+        Use given schema.
+    */
+    /*!
+        \internal
+        \note
+
+        Backtick is needed in case space in names BUT it does not work when 
+    */
+    stringSQL = "SELECT * FROM `" + stringCatalog + "`.`" + stringTable + "` LIMIT 0";
+
+    if ( mysql_query( getMySQL(), stringSQL.toUtf8().data() ) )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000,
mysql_errno( getMySQL() ), mysql_error( getMySQL() ) ) );
+
+    pResult = mysql_use_result( getMySQL() );
+    if ( !pResult )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000,
mysql_errno( getMySQL() ), mysql_error( getMySQL() ) ) );
+
+    nFields = mysql_num_fields( pResult );
+    if ( !nFields ) 
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("mysql_num_fields() failed to return number of fields") ) );
+
+    MDescriptorIRD descriptor( getStatement() );
+    descriptor.setCount( nFields, true );
+
+    /*!
+        \todo
+
+        Use given column filter.
+    */
+    for ( nField = 0; nField < nFields; nField++ )
+    {
+        /*!
+            \internal
+            \note
+             
+            This is going to seem a bit crazy bit we need to translate the the
MYSQL_FIELD into a descriptor and then map it into the
+            result row based upon the mapping detailed in the ODBC specification. We also
want to use a single function for all
+            mapping of MYSQL_FIELD into ODBC details to avoid having multiple functions
or code blocks getting out of synch.
+
+            So we translate MYLSQ_FIELD into a descriptor and then map descriptor into
result row.
+        */            
+        nReturn = doLoadMetaDataField( nField + 1, mysql_fetch_field_direct( pResult,
nField ), &descriptor );
+        if ( !SQL_SUCCEEDED( nReturn ) )
+        {
+            getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0, tr("Failed to store
field descriptor information.") );
+            break;
+        }
+
+        MDescriptorRecordIRD *  pDescriptorRecord   =
(MDescriptorRecordIRD*)descriptor.getRecord( nField + 1 );
+        SQLUINTEGER             nColumnSize         = 0;
+        SQLSMALLINT             nDecimalDigits      = 0;
+
+        nReturn = pDescriptorRecord->getColumnSize( &nColumnSize,
&nDecimalDigits );
+        if ( !SQL_SUCCEEDED( nReturn ) )
+            break;
+
+        doAppendSpecialColumns( SQL_SCOPE_SESSION,
+                                pDescriptorRecord->getBaseColumnName(),
+                                pDescriptorRecord->getConciseType(),
+                                pDescriptorRecord->getTypeName(),
+                                (qulonglong)nColumnSize,
+                                (qulonglong)nColumnSize,
+                                nDecimalDigits,
+                                SQL_PC_NOT_PSEUDO );
+    }
+    mysql_free_result( pResult ); 
+
+    MYODBCDbgReturn( nReturn );
+}
+
+SQLRETURN MResultPlus::doAppendSpecialColumnsRowVer( const QString &stringCatalog,
const QString &stringSchema, const QString &stringTable, SQLSMALLINT nScope,
SQLSMALLINT nNullable )
+{
     MYODBCDbgEnter();
 
     SQLRETURN nReturn = SQL_SUCCESS;
 
+
     MYODBCDbgReturn( nReturn );
 }
 
+SQLRETURN MResultPlus::doAppendSpecialColumns( const QVariant &variantScope,
+                                               const QVariant &variantColumnName,
+                                               const QVariant &variantDataType,
+                                               const QVariant &variantTypeName,
+                                               const QVariant &variantColumnSize,
+                                               const QVariant &variantBufferLength,
+                                               const QVariant &variantDecimalDigits,
+                                               const QVariant &variantPseudoColumn )
+{                                      
+    MYODBCDbgEnter();
+
+    doAppend();
+    /* 1 based - setData will make it 0 based */
+    setData( 1, variantScope );
+    setData( 2, variantColumnName );
+    setData( 3, variantDataType );
+    setData( 4, variantTypeName );
+    setData( 5, variantColumnSize );
+    setData( 6, variantBufferLength );
+    setData( 7, variantDecimalDigits );
+    setData( 8, variantPseudoColumn );
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h	2006-06-27 21:52:40 UTC (rev 406)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h	2006-06-27 23:40:37 UTC (rev 407)
@@ -184,7 +184,16 @@
     SQLRETURN doAppendSpecialColumnsCatalogs( SQLSMALLINT nIdentifierType, const QString
&stringCatalogFilter, const QString &stringSchemaFilter, const QString
&stringTableFilter, SQLSMALLINT nScope, SQLSMALLINT nNullable );
     SQLRETURN doAppendSpecialColumnsSchemas( SQLSMALLINT nIdentifierType, const QString
&stringCatalog, const QString &stringSchemaFilter, const QString
&stringTableFilter, SQLSMALLINT nScope, SQLSMALLINT nNullable );
     SQLRETURN doAppendSpecialColumnsTables( SQLSMALLINT nIdentifierType, const QString
&stringCatalog, const QString &stringSchema, const QString
&stringTableFilter, SQLSMALLINT nScope, SQLSMALLINT nNullable );
-    SQLRETURN doAppendSpecialColumnsColumns( SQLSMALLINT nIdentifierType, const QString
&stringCatalog, const QString &stringSchema, const QString &stringTable,
SQLSMALLINT nScope, SQLSMALLINT nNullable );
+    SQLRETURN doAppendSpecialColumnsRowID( const QString &stringCatalog, const
QString &stringSchema, const QString &stringTable, SQLSMALLINT nScope,
SQLSMALLINT nNullable );
+    SQLRETURN doAppendSpecialColumnsRowVer( const QString &stringCatalog, const
QString &stringSchema, const QString &stringTable, SQLSMALLINT nScope,
SQLSMALLINT nNullable );
+    SQLRETURN doAppendSpecialColumns( const QVariant &variantScope,
+                                      const QVariant &variantColumnName,
+                                      const QVariant &variantDataType,
+                                      const QVariant &variantTypeName,
+                                      const QVariant &variantColumnSize,
+                                      const QVariant &variantBufferLength,
+                                      const QVariant &variantDecimalDigits,
+                                      const QVariant &variantPseudoColumn );
 };
 
 #endif

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp	2006-06-27 21:52:40 UTC (rev 406)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp	2006-06-27 23:40:37 UTC (rev 407)
@@ -3231,7 +3231,6 @@
     if ( getMetadataID() == SQL_TRUE && !psCatalog &&
getConnection()->getInfoCatalogName() == "Y" )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
 
-
     /* do it */
     QString stringCatalog;
     QString stringSchema;

Thread
Connector/ODBC 5 commit: r407 - trunk/MYSQLPlus/MYSQLPlusLibpharvey28 Jun