List:Commits« Previous MessageNext Message »
From:pharvey Date:January 16 2006 4:24am
Subject:Connector/ODBC 5 commit: r40 - in MYODBCRes: MYODBCResLib MYODBCResTest include
View as plain text  
Modified:
   MYODBCRes/MYODBCResLib/MYODBCRes.cpp
   MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp
   MYODBCRes/MYODBCResTest/MYODBCResTest.cpp
   MYODBCRes/include/MYODBCRes.h
   MYODBCRes/include/MYODBCResDriver.h
Log:
UNICODE:
- expanded unit test for MYODBCResDriver (driver generated resultsets)
- next; work on MYODBCResServer (server prepared statements)


Modified: MYODBCRes/MYODBCResLib/MYODBCRes.cpp
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCRes.cpp	2006-01-15 16:55:50 UTC (rev 39)
+++ MYODBCRes/MYODBCResLib/MYODBCRes.cpp	2006-01-16 04:24:28 UTC (rev 40)
@@ -82,16 +82,5 @@
     MYODBCDbgReturn3( "%d", b );
 }
 
-bool MYODBCRes::isValidRow()
-{
-    bool b;
 
-    MYODBCDbgEnter();
 
-    b = !isBOS() && !isEOS();
-
-    MYODBCDbgReturn3( "%d", b );
-}
-
-
-

Modified: MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp
===================================================================
--- MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp	2006-01-15 16:55:50 UTC (rev 39)
+++ MYODBCRes/MYODBCResLib/MYODBCResDriver.cpp	2006-01-16 04:24:28 UTC (rev 40)
@@ -23,13 +23,15 @@
 
     Q_ASSERT( !isValidRow() );
     Q_ASSERT( !isValidColumn( nColumn ) );
+    // can not write this column (and it does not really exist anyway as bookmark is row
num)
+    Q_ASSERT( nColumn == 0 ); 
 
-    listResults[ nRow - 1 ][ nColumn ] = variantData;
+    listResults[ nRow - 1 ].replace( nColumn - 1, variantData );
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
-SQLRETURN MYODBCResDriver::setRow( my_ulonglong nRow )
+SQLRETURN MYODBCResDriver::setRow( qulonglong nRow )
 {
     MYODBCDbgEnter();
 
@@ -58,12 +60,15 @@
     Q_ASSERT( !isValidRow() );
     Q_ASSERT( !isValidColumn( nColumn ) );
 
-    variantData = listResults.at( nRow - 1 ).at( nColumn );
+    if ( nColumn == 0 )
+        variantData = nRow; // bookmark is row num - obvious limitations apply
+    else
+        variantData = listResults[ nRow - 1 ][ nColumn - 1 ];
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
-SQLRETURN MYODBCResDriver::getRow( my_ulonglong *pnRow )
+SQLRETURN MYODBCResDriver::getRow( qulonglong *pnRow )
 {
     MYODBCDbgEnter();
 
@@ -74,7 +79,7 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
-SQLRETURN MYODBCResDriver::getRows( my_ulonglong *pnRows )
+SQLRETURN MYODBCResDriver::getRows( qulonglong *pnRows )
 {
     MYODBCDbgEnter();
 
@@ -89,7 +94,9 @@
 {
     MYODBCDbgEnter();
 
-    listResults.append( QVector<QVariant>( pdesIRD->getCount() ) );
+    /* allocate row - no bookmark column allocated */
+    listResults.append( QVector<QVariant>( pdesIRD->getCount() - 1 ) );
+    nRow = listResults.count();
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
@@ -124,6 +131,7 @@
         nRow = 0;
         MYODBCDbgReturn( SQL_NO_DATA );
     }
+
     nRow = 1;
 
     MYODBCDbgReturn( SQL_SUCCESS );
@@ -133,7 +141,13 @@
 {
     MYODBCDbgEnter();
 
-    listResults.insert( nRow, QVector<QVariant>( pdesIRD->getCount() ) );
+    if ( nRow == 0 )
+    {
+        listResults.insert( nRow, QVector<QVariant>( pdesIRD->getCount() - 1 )
);
+        doFirst();
+    }
+    else
+        listResults.insert( nRow - 1, QVector<QVariant>( pdesIRD->getCount() - 1
) );
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
@@ -143,6 +157,8 @@
     MYODBCDbgEnter();
 
     nRow = listResults.count();
+    if ( !isValidRow() )
+        MYODBCDbgReturn( SQL_NO_DATA );
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
@@ -151,14 +167,11 @@
 {
     MYODBCDbgEnter();
 
-    /* wrap to beginning */
-    if ( isEOS() )
-        doBOS();
+    if ( !isValidRow() )
+        MYODBCDbgReturn( doFirst() );
 
-    /* next */
     nRow++;
-
-    if ( isEOS() )
+    if ( !isValidRow() )
         MYODBCDbgReturn( SQL_NO_DATA );
 
     MYODBCDbgReturn( SQL_SUCCESS );
@@ -168,20 +181,17 @@
 {
     MYODBCDbgEnter();
 
-    /* wrap to end */
-    if ( isBOS() )
-        doEOS();
+    if ( !isValidRow() )
+        MYODBCDbgReturn( doLast() );
 
-    /* prev */
     nRow--;
-
-    if ( isBOS() )
+    if ( !isValidRow() )
         MYODBCDbgReturn( SQL_NO_DATA );
 
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
-SQLRETURN MYODBCResDriver::doSkip( my_ulonglong nRows )
+SQLRETURN MYODBCResDriver::doSkip( qlonglong nRows )
 {
     MYODBCDbgEnter();
 
@@ -189,10 +199,7 @@
 
     if ( !isValidRow( nRow + nRows ) )
     {
-        if ( nRows > 0 )
-            doEOS();
-        else
-            doBOS();
+        nRow = 0;
         MYODBCDbgReturn( SQL_NO_DATA );
     }
 
@@ -201,56 +208,27 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
-bool MYODBCResDriver::isValidRow( my_ulonglong nRow )
+bool MYODBCResDriver::isValidRow()
 {
     bool b;
 
     MYODBCDbgEnter();
 
-    b = ( nRow > 0 && nRow <= listResults.count() );
+    b = isValidRow( nRow );
 
     MYODBCDbgReturn3( "%d", b );
 }
 
-bool MYODBCResDriver::isBOS()
+bool MYODBCResDriver::isValidRow( qulonglong nRow )
 {
     bool b;
 
     MYODBCDbgEnter();
 
-    b = ( nRow < 1  );
+    b = ( nRow > 0 && nRow <= listResults.count() );
 
     MYODBCDbgReturn3( "%d", b );
 }
 
-bool MYODBCResDriver::isEOS()
-{
-    bool b;
 
-    MYODBCDbgEnter();
 
-    b = ( nRow > listResults.count() );
-
-    MYODBCDbgReturn3( "%d", b );
-}
-
-
-void MYODBCResDriver::doBOS()
-{
-    MYODBCDbgEnter();
-
-    nRow = 0;
-
-    MYODBCDbgReturn2();
-}
-
-void MYODBCResDriver::doEOS()
-{
-    MYODBCDbgEnter();
-
-    nRow = listResults.count() + 1;
-
-    MYODBCDbgReturn2();
-}
-
-

Modified: MYODBCRes/MYODBCResTest/MYODBCResTest.cpp
===================================================================
--- MYODBCRes/MYODBCResTest/MYODBCResTest.cpp	2006-01-15 16:55:50 UTC (rev 39)
+++ MYODBCRes/MYODBCResTest/MYODBCResTest.cpp	2006-01-16 04:24:28 UTC (rev 40)
@@ -45,15 +45,148 @@
     fileDebugOut.close();
 }
 
+/* imitates a SQLStatistics call */
 void MYODBCResTest::driver()
 {
-    MYODBCDia *         pdia        = new MYODBCDia();
-    MYODBCDesIRD *      pdesIRD     = new MYODBCDesIRD( (SQLHANDLE)1 );
-    MYODBCResDriver *   presDriver  = new MYODBCResDriver( pdia, pdesIRD, (MYSQL *)1 );
+    MYODBCDia *     pdia        = new MYODBCDia();
+    MYODBCDes *     pdes        = new MYODBCDesIRD( (SQLHANDLE)1 );
+    MYODBCRes *     pres        = new MYODBCResDriver( pdia, pdes, (MYSQL *)1 );
+    uint            nColumns    = 0;
+    qulonglong      nRows       = 0;
+    qulonglong      nRow        = 0;
+    QVariant        variantData;
 
+    /* its a driver resultset so we must set the IRD manually */
+    pdes->setCount( 13 );
+    pdes->setName( 0, "bookmark" );
+    pdes->setType( 0, SQL_INTEGER );
+    pdes->setName( 1, "TABLE_CAT" );
+    pdes->setType( 1, SQL_VARCHAR );
+    pdes->setName( 2, "TABLE_SCHEM" );
+    pdes->setType( 2, SQL_VARCHAR );
+    pdes->setName( 3, "TABLE_NAME" );
+    pdes->setType( 3, SQL_VARCHAR );
+    pdes->setName( 4, "NON_UNIQUE" );
+    pdes->setType( 4, SQL_SMALLINT );
+    pdes->setName( 5, "INDEX_QUALIFIER" );
+    pdes->setType( 5, SQL_VARCHAR );
+    pdes->setName( 6, "INDEX_NAME" );
+    pdes->setType( 6, SQL_VARCHAR );
+    pdes->setName( 7, "TYPE" );
+    pdes->setType( 7, SQL_SMALLINT );
+    pdes->setName( 8, "ORDINAL_POSITION" );
+    pdes->setType( 8, SQL_SMALLINT );
+    pdes->setName( 9, "COLUMN_NAME" );
+    pdes->setType( 9, SQL_VARCHAR );
+    pdes->setName( 10, "ASC_OR_DESC" );
+    pdes->setType( 10, SQL_CHAR );
+    pdes->setName( 11, "CARDINALITY" );
+    pdes->setType( 11, SQL_INTEGER );
+    pdes->setName( 12, "PAGES" );
+    pdes->setType( 12, SQL_INTEGER );
+    pdes->setName( 13, "FILTER_CONDITION" );
+    pdes->setType( 13, SQL_VARCHAR );
 
-    delete presDriver;
-    delete pdesIRD;
+    pres->getColumns( &nColumns );
+    QCOMPARE( (int)nColumns, 13 );
+
+    /* append some records */
+    QCOMPARE( pres->isValidRow(), false );
+    pres->doAppend();
+    QCOMPARE( pres->isValidRow(), true );
+
+    pres->setData( 1, "1" );
+    pres->setData( 2, "MyTableSchem" );
+    pres->setData( 3, "MyTableName" );
+    pres->setData( 4, SQL_TRUE );
+    pres->setData( 9, "MyColumnName" );
+    pres->getRow( &nRow );
+    QCOMPARE( (int)nRow, 1 );
+
+    pres->doAppend();
+    pres->setData( 1, "2" );
+    pres->setData( 2, "MyTableSchem" );
+    pres->setData( 3, "MyTableName" );
+    pres->setData( 4, SQL_FALSE );
+    pres->setData( 9, "MyColumnName" );
+    pres->getRow( &nRow );
+    QCOMPARE( (int)nRow, 2 );
+
+    pres->doAppend();
+    pres->setData( 1, "3" );
+    pres->setData( 2, "MyTableSchem" );
+    pres->setData( 3, "MyTableName" );
+    pres->setData( 4, SQL_TRUE );
+    pres->setData( 9, "MyColumnName" );
+    pres->getRow( &nRow );
+    QCOMPARE( (int)nRow, 3 );
+    pres->getRows( &nRows );
+    QCOMPARE( (int)nRows, 3 );
+
+    /* doFirst(), doNext() */
+    pres->doFirst();
+    pres->getData( 1, variantData );
+    QCOMPARE( 1, variantData.toInt() );
+
+    pres->doNext();
+    pres->getData( 1, variantData );
+    QCOMPARE( 2, variantData.toInt() );
+
+    pres->doNext();
+    pres->getData( 1, variantData );
+    QCOMPARE( 3, variantData.toInt() );
+    QCOMPARE( pres->isValidRow(), true );
+
+    pres->doNext();
+    QCOMPARE( pres->isValidRow(), false );
+
+    pres->doNext();
+    pres->getData( 1, variantData );
+    QCOMPARE( 1, variantData.toInt() );
+
+    /* doLast(), doPrev() */
+    pres->doLast();
+    pres->getData( 1, variantData );
+    QCOMPARE( 3, variantData.toInt() );
+
+    pres->doPrev();
+    pres->getData( 1, variantData );
+    QCOMPARE( 2, variantData.toInt() );
+
+    pres->doPrev();
+    pres->getData( 1, variantData );
+    QCOMPARE( 1, variantData.toInt() );
+    QCOMPARE( pres->isValidRow(), true );
+
+    pres->doPrev();
+    QCOMPARE( pres->isValidRow(), false );
+
+    pres->doPrev();
+    pres->getData( 1, variantData );
+    QCOMPARE( 3, variantData.toInt() );
+
+    /* doSkip() */
+    pres->doFirst();
+    pres->doSkip( 2 );
+    pres->getData( 1, variantData );
+    pres->getRow( &nRow );
+    QCOMPARE( (int)nRow, 3 );
+    QCOMPARE( 3, variantData.toInt() );
+
+    pres->doSkip( 1 );
+    QCOMPARE( pres->isValidRow(), false );
+
+    pres->doLast();
+    pres->doSkip( -2 );
+    pres->getData( 1, variantData );
+    QCOMPARE( 1, variantData.toInt() );
+
+    pres->doSkip( -1 );
+    QCOMPARE( pres->isValidRow(), false );
+
+    /* fini */
+    delete pres;
+    delete pdes;
     delete pdia;
 }
 

Modified: MYODBCRes/include/MYODBCRes.h
===================================================================
--- MYODBCRes/include/MYODBCRes.h	2006-01-15 16:55:50 UTC (rev 39)
+++ MYODBCRes/include/MYODBCRes.h	2006-01-16 04:24:28 UTC (rev 40)
@@ -31,12 +31,12 @@
     virtual ~MYODBCRes();
 
     virtual SQLRETURN setData( uint nColumn, const QVariant &variantData ) = 0;
-    virtual SQLRETURN setRow( my_ulonglong nRow ) = 0;
+    virtual SQLRETURN setRow( qulonglong nRow ) = 0;
 
     virtual SQLRETURN   getColumns( uint *pnColumns ) = 0;
     virtual SQLRETURN   getData( uint nColumn, QVariant &variantData ) = 0;
-    virtual SQLRETURN   getRow( my_ulonglong *pnRow ) = 0;
-    virtual SQLRETURN   getRows( my_ulonglong *pnRows ) = 0;
+    virtual SQLRETURN   getRow( qulonglong *pnRow ) = 0;
+    virtual SQLRETURN   getRows( qulonglong *pnRows ) = 0;
     virtual MYODBCDes * getDesIRD();
 
     virtual SQLRETURN doAppend() = 0;
@@ -47,13 +47,11 @@
     virtual SQLRETURN doLast() = 0;
     virtual SQLRETURN doNext() = 0;
     virtual SQLRETURN doPrev() = 0;
-    virtual SQLRETURN doSkip( my_ulonglong nRows ) = 0;
+    virtual SQLRETURN doSkip( qlonglong nRows ) = 0;
 
     virtual bool isValidColumn( uint nColumn );
-    virtual bool isValidRow( my_ulonglong nRow ) = 0;
-    virtual bool isValidRow();
-    virtual bool isBOS() = 0;
-    virtual bool isEOS() = 0;
+    virtual bool isValidRow() = 0;
+    virtual bool isValidRow( qulonglong nRow ) = 0;
 
 protected:
     MYSQL *     pmysql;     /*!< parent of MYSQL_RES or MYSQL_STMT  */

Modified: MYODBCRes/include/MYODBCResDriver.h
===================================================================
--- MYODBCRes/include/MYODBCResDriver.h	2006-01-15 16:55:50 UTC (rev 39)
+++ MYODBCRes/include/MYODBCResDriver.h	2006-01-16 04:24:28 UTC (rev 40)
@@ -10,12 +10,12 @@
     virtual ~MYODBCResDriver();
 
     virtual SQLRETURN setData( uint nColumn, const QVariant &variantData );
-    virtual SQLRETURN setRow( my_ulonglong nRow );
+    virtual SQLRETURN setRow( qulonglong nRow );
 
     virtual SQLRETURN getColumns( uint *pnColumns );
     virtual SQLRETURN getData( uint nColumn, QVariant &variantData );
-    virtual SQLRETURN getRow( my_ulonglong *pnRow );
-    virtual SQLRETURN getRows( my_ulonglong *pnRows );
+    virtual SQLRETURN getRow( qulonglong *pnRow );
+    virtual SQLRETURN getRows( qulonglong *pnRows );
 
     virtual SQLRETURN doAppend();
     virtual SQLRETURN doClear();
@@ -25,19 +25,15 @@
     virtual SQLRETURN doLast();
     virtual SQLRETURN doNext();
     virtual SQLRETURN doPrev();
-    virtual SQLRETURN doSkip( my_ulonglong nRows );
+    virtual SQLRETURN doSkip( qlonglong nRows );
 
-    virtual bool isValidRow( my_ulonglong nRow );
-    virtual bool isBOS();
-    virtual bool isEOS();
+    virtual bool isValidRow();
+    virtual bool isValidRow( qulonglong nRow );
 
 protected:
-    void doBOS();
-    void doEOS();
-
     /* Our result set is a list of rows. Each row is a vector of column data. Column data
is a QVariant. */
     QList<QVector<QVariant>> listResults;
-    my_ulonglong nRow; /* 1 -based (0 as BOS) */
+    qulonglong nRow; /* 1 -based (0 as BOS) */
 };
 
 #endif

Thread
Connector/ODBC 5 commit: r40 - in MYODBCRes: MYODBCResLib MYODBCResTest includepharvey16 Jan