Modified:
trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h
trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
Log:
more work on SQLForeignKeys
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-28 11:16:10 UTC (rev 412)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.cpp 2006-06-28 12:07:39 UTC (rev 413)
@@ -687,6 +687,67 @@
MYODBCDbgReturn( nReturn );
}
+SQLRETURN MResultPlus::doForeignKeys( const QString &stringPKCatalog, const QString
&stringPKSchema, const QString &stringPKTable, const QString
&stringFKCatalog, const QString &stringFKSchema, const QString &stringFKTable
)
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn;
+
+ /* create empty resultset */
+ MDescriptor *pDescriptor;
+
+ doClear();
+ getDiagnostic()->setRowCount( 0 );
+
+ pDescriptor = getImpRowDesc();
+ pDescriptor->doAppend( SQL_VARCHAR, "PKTABLE_CAT", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "PKTABLE_SCHEM", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "PKTABLE_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_VARCHAR, "PKCOLUMN_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_VARCHAR, "FKTABLE_CAT", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "FKTABLE_SCHEM", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "FKTABLE_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_VARCHAR, "FKCOLUMN_NAME", SQL_NO_NULLS );
+ pDescriptor->doAppend( SQL_SMALLINT, "KEY_SEQ", SQL_NO_NULLS, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "UPDATE_RULE", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_SMALLINT, "DELETE_RULE", SQL_NULLABLE, SQL_FALSE );
+ pDescriptor->doAppend( SQL_VARCHAR, "FK_NAME", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_VARCHAR, "PK_NAME", SQL_NULLABLE );
+ pDescriptor->doAppend( SQL_SMALLINT, "DEFERRABILITY", SQL_NULLABLE, SQL_FALSE );
+
+ /* do it */
+
+
+
+
+ /*!
+ \internal ODBC RULE
+
+ When SQLExecute, SQLExecDirect, SQLBulkOperations, SQLSetPos, or SQLMoreResults
is called, the SQL_DIAG_ROW_COUNT
+ field of the diagnostic data structure is set to the row count, and the row count
is cached in an implementation-dependent
+ way. SQLRowCount returns the cached row count value. The cached row count value
is valid until the statement handle is set
+ back to the prepared or allocated state, the statement is reexecuted, or
SQLCloseCursor is called. Note that if a function
+ has been called since the SQL_DIAG_ROW_COUNT field was set, the value returned by
SQLRowCount might be different from the
+ value in the SQL_DIAG_ROW_COUNT field because the SQL_DIAG_ROW_COUNT field is
reset to 0 by any function call.
+
+ \internal MYODBC RULE
+
+ Wet set SQL_DIAG_ROW_COUNT when any result set is requested - for example we also
set SQL_DIAG_ROW_COUNT for catalog
+ functions.
+ */
+ qulonglong nRows = -1;
+ if ( !SQL_SUCCEEDED( getRows( &nRows ) ) )
+ getDiagnostic()->setRowCount( -1 );
+ else
+ getDiagnostic()->setRowCount( nRows );
+
+ /* we should be at last record so next will make us eof and a subsequent next will be
first record */
+ setState( STATE_EXECUTED );
+ doNext();
+
+ MYODBCDbgReturn( nReturn );
+}
+
SQLRETURN MResultPlus::doPrimaryKeys( const QString &stringCatalog, const QString
&stringSchema, const QString &stringTable )
{
MYODBCDbgEnter();
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h 2006-06-28 11:16:10 UTC (rev 412)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultPlus.h 2006-06-28 12:07:39 UTC (rev 413)
@@ -70,10 +70,11 @@
SQLRETURN doSkip( qlonglong nRows );
SQLRETURN doCommit();
- SQLRETURN doTables( const QString &stringCatalogFilter, const QString
&stringSchemaFilter, const QString &stringTableFilter, const QString
&stringTableTypeFilter );
SQLRETURN doColumns( const QString &stringCatalogFilter, const QString
&stringSchemaFilter, const QString &stringTableFilter, const QString
&stringColumnFilter );
+ SQLRETURN doForeignKeys( const QString &stringPKCatalog, const QString
&stringPKSchema, const QString &stringPKTable, const QString
&stringFKCatalog, const QString &stringFKSchema, const QString &stringFKTable
);
SQLRETURN doPrimaryKeys( const QString &stringCatalog, const QString
&stringSchema, const QString &stringTable );
SQLRETURN doSpecialColumns( SQLSMALLINT nIdentifierType, const QString
&stringCatalog, const QString &stringSchema, const QString &stringTable,
SQLSMALLINT nScope, SQLSMALLINT nNullable );
+ SQLRETURN doTables( const QString &stringCatalogFilter, const QString
&stringSchemaFilter, const QString &stringTableFilter, const QString
&stringTableTypeFilter );
/* isers */
BOOLEAN isValidRow();
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-06-28 11:16:10 UTC (rev 412)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-06-28 12:07:39 UTC (rev 413)
@@ -2536,7 +2536,114 @@
if ( psFKTable && nLength6 != 0 )
stringFKTable = QString::fromUtf16( psFKTable, ( nLength6 == SQL_NTS ? -1 :
nLength6 ) );
- MYODBCDbgReturn( SQL_SUCCESS );
+ if ( getMetadataID() == SQL_TRUE )
+ {
+ SQLRETURN nReturn;
+
+ /*!
+ \internal ODBC RULE
+
+ The SQL_ATTR_METADATA_ID statement attribute was set to SQL_TRUE, the
FKCatalogName or
+ PKCatalogName argument was a null pointer, and the SQL_CATALOG_NAME InfoType
returns that
+ catalog names are supported.
+ */
+ if ( getConnection()->getInfoCatalogName() == "Y" && (!psPKCatalog ||
!psFKCatalog) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
+
+ /*!
+ \internal ODBC RULE
+
+ If a string in an identifier argument is quoted, the driver removes leading
and trailing blanks and treats
+ literally the string within the quotation marks. If the string is not quoted,
the driver removes trailing
+ blanks and folds the string to uppercase.
+ */
+ nReturn = doIdentifierArgumentMakeNice( stringPKCatalog );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringPKSchema );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringPKTable );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringFKCatalog );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringFKSchema );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ nReturn = doIdentifierArgumentMakeNice( stringFKTable );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ }
+ else
+ {
+ }
+
+ /*!
+ \internal ODBC RULE (DM)
+
+ The arguments PKTableName and FKTableName were both null pointers.
+
+ \note
+
+ We assume an empty string is as bad as a null.
+ */
+ if ( stringPKTable.isEmpty() && stringFKTable.isEmpty() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY009 ) );
+
+ /*!
+ \internal ODBC RULE
+
+ A catalog was specified, and the driver or data source does not support catalogs.
+
+ \internal MYODBC RULE
+
+ We can continue if value is; NULL or "".
+ */
+ if ( getConnection()->getInfoCatalogUsage() == 0 &&
(!stringPKCatalog.isEmpty() || !stringFKCatalog.isEmpty()) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HYC00 ) );
+
+ /*!
+ \internal ODBC RULE
+
+ A schema was specified, and the driver or data source does not support schema.
+
+ \internal MYODBC RULE
+
+ We can continue if value is; NULL or "".
+ */
+ if ( getConnection()->getInfoSchemaUsage() == 0 &&
(!stringPKSchema.isEmpty() || !stringFKSchema.isEmpty()) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HYC00 ) );
+
+ /*!
+ \internal MYODBC RULE
+
+ We undo any prepare - no worries.
+ */
+ SQLRETURN nReturn;
+ if ( getState() > STATE_S1 )
+ {
+ nReturn = doStateRollBack( STATE_S1 );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ MYODBCDbgReturn( nReturn );
+ }
+
+ /* generate result */
+ MResultPlus *pResult = new MResultPlus( this );
+
+ nReturn = pResult->doForeignKeys( stringPKCatalog, stringPKSchema, stringPKTable,
stringFKCatalog, stringFKSchema, stringFKTable );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ {
+ delete pResult;
+ MYODBCDbgReturn( nReturn );
+ }
+
+ setImplicitPrepare( true );
+ this->pResult = pResult;
+ setState( STATE_S5 );
+
+ MYODBCDbgReturn( nReturn );
}
SQLRETURN MStatement::doFreeStmt( SQLUSMALLINT nOption )
@@ -4830,7 +4937,7 @@
stringIA = stringIA.trimmed();
if ( stringIA.isEmpty() )
- MYODBCDbgReturn3( "%d", true );
+ MYODBCDbgReturn( SQL_SUCCESS );
if ( stringQuotes.contains( stringIA.at( 0 ) ) )
{
| Thread |
|---|
| • Connector/ODBC 5 commit: r413 - trunk/MYSQLPlus/MYSQLPlusLib | pharvey | 28 Jun |