Modified:
MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
MYSQLPlus/MYSQLPlusLib/MResultPlus.h
Log:
Modified: MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-02 00:46:50 UTC (rev 309)
+++ MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-02 03:13:45 UTC (rev 310)
@@ -633,65 +633,23 @@
pDescriptor = getImpRowDesc();
pDescriptor->doAppend( SQL_VARCHAR, "TABLE_CAT", SQL_NULLABLE );
pDescriptor->doAppend( SQL_VARCHAR, "TABLE_SCHEM", SQL_NULLABLE );
- pDescriptor->doAppend( SQL_VARCHAR, "TABLE_NAME", SQL_NULLABLE );
- pDescriptor->doAppend( SQL_VARCHAR, "TABLE_TYPE", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "TABLE_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_VARCHAR, "COLUMN_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_SMALLINT, "DATA_TYPE", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_VARCHAR, "TYPE_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_INTEGER, "COLUMN_SIZE", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_INTEGER, "BUFFER_LENGTH", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "DECIMAL_DIGITS", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "NUM_PREC_RADIX", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "NULLABLE", SQL_NO_NULLS, SQL_FALSE );
pDescriptor->doAppend( SQL_VARCHAR, "REMARKS", SQL_NULLABLE );
-++++++++++++
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 1, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "TABLE_CAT", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "COLUMN_DEF", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_SMALLINT, "SQL_DATA_TYPE", SQL_NO_NULLS, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "SQL_DATETIME_SUB", SQL_NULLABLE, SQL_FALSE
);
+ pDescriptor->doAppend( SQL_INTEGER, "CHAR_OCTET_LENGTH", SQL_NULLABLE, SQL_FALSE
);
+ pDescriptor->doAppend( SQL_INTEGER, "ORDINAL_POSITION", SQL_NO_NULLS, SQL_FALSE );
+ pDescriptor->doAppend( SQL_VARCHAR, "IS_NULLABLE", SQL_NULLABLE );
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 2, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "TABLE_SCHEM", SQL_NULLABLE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 3, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "TABLE_NAME", SQL_NO_NULLS );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 4, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "COLUMN_NAME", SQL_NO_NULLS );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 5, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "DATA_TYPE", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 6, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "TYPE_NAME", SQL_NO_NULLS );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 7, MYODBC_C_TRUE );
- MYODBCDesRecIrdInteger( pDesRec, "COLUMN_SIZE", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 8, MYODBC_C_TRUE );
- MYODBCDesRecIrdInteger( pDesRec, "BUFFER_LENGTH", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 9, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "DECIMAL_DIGITS", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 10, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "NUM_PREC_RADIX", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 11, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "NULLABLE", SQL_NO_NULLS, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 12, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "REMARKS", SQL_NULLABLE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 13, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "COLUMN_DEF", SQL_NULLABLE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 14, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "SQL_DATA_TYPE", SQL_NO_NULLS, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 15, MYODBC_C_TRUE );
- MYODBCDesRecIrdSmallInt( pDesRec, "SQL_DATETIME_SUB", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 16, MYODBC_C_TRUE );
- MYODBCDesRecIrdInteger( pDesRec, "CHAR_OCTET_LENGTH", SQL_NULLABLE, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 17, MYODBC_C_TRUE );
- MYODBCDesRecIrdInteger( pDesRec, "ORDINAL_POSITION", SQL_NO_NULLS, SQL_TRUE );
-
- pDesRec = MYODBCDesRecGet( pStm->attr_imp_row_desc, 18, MYODBC_C_TRUE );
- MYODBCDesRecIrdVarChar( pDesRec, "IS_NULLABLE", SQL_NULLABLE );
-++++++++++++
-
/* do it */
nReturn = doAppendColumnsCatalogs( stringCatalog, stringSchema, stringTable,
stringColumn );
@@ -1470,4 +1428,228 @@
MYODBCDbgReturn( nReturn );
}
+SQLRETURN MResultPlus::doAppendColumnsCatalogs( const QString &stringCatalogFilter,
const QString &stringSchemaFilter, const QString &stringTableFilter, const
QString &stringColumnFilter )
+{
+ MYODBCDbgEnter();
+ SQLRETURN nReturn = SQL_SUCCESS;
+
+ /*!
+ \internal MYODBC Rule
+
+ If we have a % we will get all catalogs but if we have a NULL we will only return
the
+ current catalog. This will make things consistent with some other drivers.
+ */
+ if ( stringCatalogFilter.isNull() )
+ {
+ QString stringCatalog = getConnection()->getCurrentCatalog();
+ if ( stringCatalog.isNull() )
+ stringCatalog = "";
+
+ MYODBCDbgReturn( doAppendColumnsSchemas( stringCatalog, stringSchemaFilter,
stringTableFilter, stringColumnFilter ) );
+ }
+
+ QStringList stringlistCatalogs = getCatalogs( "%" );
+
+ BOOLEAN bWildCard = ( getEnvironment()->getODBCVersion() != SQL_OV_ODBC2
&& getStatement()->getMetadataID() == SQL_FALSE );
+ QString stringWildCard = stringCatalogFilter;
+ QRegExp regexWildCard;
+ regexWildCard.setPatternSyntax( QRegExp::Wildcard );
+
+ if ( bWildCard )
+ regexWildCard.setPattern( stringWildCard.replace( '%', '*' ) );
+
+ for ( int n = 0; n < stringlistCatalogs.count(); n++ )
+ {
+ BOOLEAN bMatch;
+
+ if ( stringCatalogFilter.isNull() )
+ bMatch = true;
+ else if ( bWildCard )
+ bMatch = regexWildCard.exactMatch( stringlistCatalogs[n] );
+ else
+ bMatch = stringlistCatalogs[n] == stringCatalogFilter;
+
+ if ( bMatch )
+ {
+ nReturn = doAppendColumnsSchemas( stringlistCatalogs[n], stringSchemaFilter,
stringTableFilter, stringColumnFilter );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ break;
+ }
+ }
+
+ MYODBCDbgReturn( nReturn );
+}
+
+SQLRETURN MResultPlus::doAppendColumnsSchemas( const QString &stringCatalog, const
QString &stringSchemaFilter, const QString &stringTableFilter, const QString
&stringColumnFilter )
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn = SQL_SUCCESS;
+
+ /*!
+ \internal ODBC Rule
+
+ However, a zero-length search pattern+ zero + */
+ QStringList stringlistSchemas = getSchemas( stringCatalog, "%" );
+
+ BOOLEAN bWildCard = ( getStatement()->getMetadataID() == SQL_FALSE );
+ QString stringWildCard = stringSchemaFilter;
+ QRegExp regexWildCard;
+ regexWildCard.setPatternSyntax( QRegExp::Wildcard );
+
+ if ( bWildCard )
+ regexWildCard.setPattern( stringWildCard.replace( '%', '*' ) );
+
+ for ( int n = 0; n < stringlistSchemas.count(); n++ )
+ {
+ BOOLEAN bMatch;
+
+ if ( stringSchemaFilter.isNull() )
+ bMatch = true;
+ else if ( bWildCard )
+ bMatch = regexWildCard.exactMatch( stringlistSchemas[n] );
+ else
+ bMatch = stringlistSchemas[n] == stringSchemaFilter;
+
+ if ( bMatch )
+ {
+ nReturn = doAppendColumnsTables( stringCatalog, stringlistSchemas[n],
stringTableFilter, stringColumnFilter );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ break;
+ }
+ }
+
+ MYODBCDbgReturn( nReturn );
+}
+
+SQLRETURN MResultPlus::doAppendColumnsTables( const QString &stringCatalog, const
QString &stringSchema, const QString &stringTableFilter, const QString
&stringColumnFilter )
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn = SQL_SUCCESS;
+
+ /*!
+ \internal ODBC Rule
+
+ However, a zero-length search pattern+ zero + */
+ QStringList stringlistTables = getTables( stringCatalog, stringSchema, "%" );
+
+ BOOLEAN bWildCard = ( getStatement()->getMetadataID() == SQL_FALSE );
+ QString stringWildCard = stringTableFilter;
+ QRegExp regexWildCard;
+ regexWildCard.setPatternSyntax( QRegExp::Wildcard );
+
+ if ( bWildCard )
+ regexWildCard.setPattern( stringWildCard.replace( '%', '*' ) );
+
+ for ( int n = 0; n < stringlistTables.count(); n++ )
+ {
+ BOOLEAN bMatch;
+
+ if ( stringTableFilter.isNull() )
+ bMatch = true;
+ else if ( bWildCard )
+ bMatch = regexWildCard.exactMatch( stringlistTables[n] );
+ else
+ bMatch = stringlistTables[n] == stringTableFilter;
+
+ if ( bMatch )
+ {
+ nReturn = doAppendColumnsTables( stringCatalog, stringSchema,
stringlistTables[n], stringColumnFilter );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ break;
+ }
+ }
+
+ MYODBCDbgReturn( nReturn );
+}
+
+SQLRETURN MResultPlus::doAppendColumnsColumns( const QString &stringCatalog, const
QString &stringSchema, const QString &stringTable, const QString
&stringColumnFilter )
+{
+ SQLCHAR szSQL[1024];
+ MYSQL_RES * pResult = NULL;
+ MYSQL_FIELD * pField = NULL;
+ MYODBC_DES_REC_PTR pDesRec = NULL;
+ char szAlpha[100];
+ SQLINTEGER nColumn = 1;
+ /*!
+ \todo
+
+ Use given schema.
+ */
+ sprintf( szSQL, "SELECT * FROM %s.%s LIMIT 0", pszCatalog, pszTable );
+
+ if ( mysql_query( pStm->pDbc->pMySQL, szSQL ) )
+ {
+ MYODBCDiaAppend( pStm->hDia, MYODBC_DIA_HY000, mysql_errno(
pStm->pDbc->pMySQL ), (SQLCHAR*)mysql_error( pStm->pDbc->pMySQL ) );
+ MYODBCDbgReturn( SQL_ERROR );
+ }
+
+ pResult = mysql_use_result( pStm->pDbc->pMySQL );
+ if ( !pResult )
+ {
+ MYODBCDiaAppend( pStm->hDia, MYODBC_DIA_HY000, mysql_errno(
pStm->pDbc->pMySQL ), (SQLCHAR*)mysql_error( pStm->pDbc->pMySQL ) );
+ MYODBCDbgReturn( SQL_ERROR );
+ }
+
+ /*!
+ \todo
+
+ Use given column filter.
+ */
+ pDesRec = MYODBCDesRecAlloc( MYODBC_RTTI_DES_IRD );
+ while ( pField = mysql_fetch_field( pResult ) )
+ {
+ /*
+ This is going to seem a bit crazy bit we need to tranlate 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.
+ */
+ MYODBCResStoreMetaDataField( pDesRec, pField );
+
+ /*!
+ \todo
+
+ This needs to be refined to be more accurate. For example;
+ - checks need to be added to see about making some result fields null
+ - pszColumnSize, pszBufferLength, pszDecimalDigits need another look
+ - pszColumnDef
+ */
+ MYODBCDrvAppendColumn( pStm->hRes,
+ MYODBCCStrDup( pszCatalog, SQL_NTS ), /* pszTableCat */
+ MYODBCCStrDup( pszSchema, SQL_NTS ), /* pszTableSchem */
+ MYODBCCStrDup( pDesRec->desc_base_table_name, SQL_NTS
), /* pszTableName */
+ MYODBCCStrDup( pDesRec->desc_base_column_name, SQL_NTS
), /* pszColumnName */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_concise_type, szAlpha, 10 ), SQL_NTS ), /* pszDataType */
+ MYODBCCStrDup( pDesRec->desc_type_name, SQL_NTS ), /*
pszTypeName */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_display_size, szAlpha, 10 ), SQL_NTS ), /* pszColumnSize */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_display_size, szAlpha, 10 ), SQL_NTS ), /* pszBufferLength */
+ MYODBCCStrDup( MYODBCCIntToAlpha( pDesRec->desc_scale,
szAlpha, 10 ), SQL_NTS ), /* pszDecimalDigits */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_num_prec_radix, szAlpha, 10 ), SQL_NTS ), /* pszNumPrecRadix */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_nullable, szAlpha, 10 ), SQL_NTS ), /* pszNullable */
+ NULL, /* pszRemarks */
+ NULL, /* pszColumnDef */
+ MYODBCCStrDup( MYODBCCIntToAlpha( pDesRec->desc_type,
szAlpha, 10 ), SQL_NTS ), /* pszSqlDataType */
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_datetime_interval_code, szAlpha, 10 ), SQL_NTS ), /* pszSqlDateTimeSub
*/
+ MYODBCCStrDup( MYODBCCIntToAlpha(
pDesRec->desc_octet_length, szAlpha, 10 ), SQL_NTS ), /* pszCharOctetLength */
+ MYODBCCStrDup( MYODBCCIntToAlpha( nColumn, szAlpha, 10 ),
SQL_NTS ), /* pszOrdinalPosition */
+ MYODBCCStrDup( ( pDesRec->desc_nullable == SQL_NO_NULLS
? "NO" : "YES" ), SQL_NTS ) /* pszIsNullable */ );
+ nColumn++;
+ MYODBCDesRecClear( pDesRec );
+ }
+ MYODBCCFree( pDesRec );
+ mysql_free_result( pResult );
+
+ return SQL_SUCCESS;
+}
Modified: MYSQLPlus/MYSQLPlusLib/MResultPlus.h
===================================================================
--- MYSQLPlus/MYSQLPlusLib/MResultPlus.h 2006-06-02 00:46:50 UTC (rev 309)
+++ MYSQLPlus/MYSQLPlusLib/MResultPlus.h 2006-06-02 03:13:45 UTC (rev 310)
@@ -157,6 +157,10 @@
SQLRETURN doAppendTablesSchemas( const QString &stringCatalog, const QString
&stringSchemaFilter, const QString &stringTableFilter, const QString
&stringTableType );
SQLRETURN doAppendTablesTables( const QString &stringCatalog, const QString
&stringSchema, const QString &stringTableFilter, const QString
&stringTableType );
+ SQLRETURN doAppendColumnsCatalogs( const QString &stringCatalogFilter, const
QString &stringSchemaFilter, const QString &stringTableFilter, const QString
&stringColumnFilter );
+ SQLRETURN doAppendColumnsSchemas( const QString &stringCatalog, const QString
&stringSchemaFilter, const QString &stringTableFilter, const QString
&stringColumnFilter );
+ SQLRETURN doAppendColumnsTables( const QString &stringCatalog, const QString
&stringSchema, const QString &stringTableFilter, const QString
&stringColumnFilter );
+ SQLRETURN doAppendColumnsColumns( const QString &stringCatalog, const QString
&stringSchema, const QString &stringTable, const QString &stringColumnFilter
);
};
#endif
| Thread |
|---|
| • Connector/ODBC 5 commit: r310 - MYSQLPlus/MYSQLPlusLib | pharvey | 2 Jun |