Modified:
trunk/MYSQLPlus/MYSQLPlusTest/MYSQLPlusTest.cpp
Log:
- added test for SQLMoreResults/doMoreResults
Modified: trunk/MYSQLPlus/MYSQLPlusTest/MYSQLPlusTest.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusTest/MYSQLPlusTest.cpp 2006-08-06 19:28:13 UTC (rev 474)
+++ trunk/MYSQLPlus/MYSQLPlusTest/MYSQLPlusTest.cpp 2006-08-07 05:55:01 UTC (rev 475)
@@ -31,6 +31,7 @@
void doSelect();
void doBindParameter();
void doBindParameterVerify();
+ void doMoreResults();
void doDisconnect();
};
@@ -384,6 +385,148 @@
QCOMPARE( nRows, (SQLINTEGER)3 );
}
+void MYSQLPlusTest::doMoreResults()
+{
+ MStatement statement( pConnection );
+ SQLRETURN nReturn;
+ SQLRETURN nMoreResults;
+ SQLINTEGER nRowCount = 0;
+ SQLSMALLINT nNumResultCols = 0;
+
+ SQLINTEGER nCount = 0;
+ SQLCHAR szName[100];
+ SQLCHAR szCreated[100];
+ SQLINTEGER nStrLenOrIndCount = 0;
+ SQLINTEGER nStrLenOrIndName = 0;
+ SQLINTEGER nStrLenOrIndCreated = 0;
+
+ /* vcName for WHERE in 1st SELECT */
+ nReturn = statement.doBindParameter( 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 100,
0, szName, sizeof(szName), &nStrLenOrIndName );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* dCreated for SET in UPDATE */
+ nReturn = statement.doBindParameter( 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 100,
0, szCreated, 0, &nStrLenOrIndCreated );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* vcName for WHERE in UPDATE */
+ nReturn = statement.doBindParameter( 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 100,
0, szName, sizeof(szName), &nStrLenOrIndName );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* vcName for WHERE in 2nd SELECT */
+ nReturn = statement.doBindParameter( 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 100,
0, szName, sizeof(szName), &nStrLenOrIndName );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* batched commands: SELECT, UPDATE, and SELECT (2 SELECTs compared to verify UPDATE)
*/
+ nReturn = statement.doPrepare( TEXT("SELECT COUNT(*) FROM tbMyODBCTest WHERE vcName =
?;UPDATE tbMyODBCTest SET dCreated = ? WHERE vcName = ?;SELECT dCreated FROM tbMyODBCTest
WHERE vcName = ?;"), SQL_NTS );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* provide parameter values */
+ strcpy( (char*)szName, "name1" );
+ sprintf( (char*)szCreated, "2006-11-24 18:30:00" );
+
+ /* initial execute (the 1st SELECT) */
+ nReturn = statement.doExecute();
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+
+ /* we should have 1 row and 1 col with value = 1 */
+ nReturn = statement.getDiagField( 0, SQL_DIAG_CURSOR_ROW_COUNT, &nRowCount, 0,
NULL );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nRowCount == 1 );
+
+ nReturn = statement.doNumResultCols( &nNumResultCols );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nNumResultCols == 1 );
+
+ nReturn = statement.getData( 1, SQL_C_LONG, &nCount, 0, &nStrLenOrIndCount );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nCount == 1 );
+ QVERIFY( nStrLenOrIndCount == 0 );
+
+ /* do more */
+ int nResultCount = 1;
+ while ( 1 )
+ {
+ nMoreResults = statement.doMoreResults();
+ if ( nMoreResults == SQL_SUCCESS )
+ {
+ nResultCount++;
+ if ( nResultCount == 2 )
+ {
+ /* we should have; no resultset, affected rows = 1 */
+ nReturn = statement.doNumResultCols( &nNumResultCols );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nNumResultCols == 0 );
+
+ nReturn = statement.doRowCount( &nRowCount );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nRowCount == 1 );
+
+ nReturn = statement.getDiagField( 0, SQL_DIAG_ROW_COUNT, &nRowCount,
0, NULL );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nRowCount == 1 );
+ }
+ else if ( nResultCount == 3 )
+ {
+ /* we should have; 1 row and 1 col with value = revised date */
+ SQLCHAR szCreatedResult[100];
+ SQLINTEGER nStrLenOrIndCreatedResult = 0;
+
+ nReturn = statement.getDiagField( 0, SQL_DIAG_CURSOR_ROW_COUNT,
&nRowCount, 0, NULL );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nRowCount == 1 );
+
+ nReturn = statement.doNumResultCols( &nNumResultCols );
+ if ( nReturn != SQL_SUCCESS )
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nNumResultCols == 1 );
+
+ *szCreatedResult = '\0';
+ nReturn = statement.getData( 1, SQL_C_CHAR, &szCreatedResult, 100,
&nStrLenOrIndCreatedResult );
+ QCOMPARE( nReturn, (SQLRETURN)SQL_SUCCESS );
+ QVERIFY( nStrLenOrIndCreatedResult == 0 );
+ QVERIFY( strcmp( (const char*)szCreatedResult, (const char*)szCreated )
== 0 );
+ }
+ }
+ else if ( nMoreResults == SQL_NO_DATA )
+ break;
+ else
+ {
+ textstreamStdOut << endl << endl <<
statement.getDiagnostics().join( "\n" ) << endl << endl;
+ QCOMPARE( nMoreResults, (SQLRETURN)SQL_SUCCESS );
+ }
+ }
+
+ /* we should have processed exactly 3 commands/results */
+ QVERIFY( nResultCount == 3 );
+}
+
/*!
\brief Disconnect our shared MConnection.
*/
| Thread |
|---|
| • Connector/ODBC 5 commit: r475 - trunk/MYSQLPlus/MYSQLPlusTest | pharvey | 7 Aug |