List:Commits« Previous MessageNext Message »
From:pharvey Date:September 3 2006 3:57am
Subject:Connector/ODBC 5 commit: r512 - trunk/SDK/MYSQLPlus/Library
View as plain text  
Modified:
   trunk/SDK/MYSQLPlus/Library/MResult.cpp
   trunk/SDK/MYSQLPlus/Library/MResult.h
Log:
- more work for implementing forward-only, read-only block/noblock cursor support


Modified: trunk/SDK/MYSQLPlus/Library/MResult.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResult.cpp	2006-09-02 06:04:16 UTC (rev 511)
+++ trunk/SDK/MYSQLPlus/Library/MResult.cpp	2006-09-03 03:57:02 UTC (rev 512)
@@ -99,7 +99,10 @@
     Q_ASSERT( pStatement );
 
     nState          = STATE_UNINITIALIZED;
-    bBuffered       = true;
+    bScrollable     = false;
+    nResultSetRow   = 0;
+    nRowSetRow      = 1;
+    nRowSetSize     = 1;
     nRowsAffected   = 0;
 
     /*!
@@ -124,16 +127,82 @@
     MYODBCDbgReturn2();
 }
 
+SQLRETURN MResult::setRowSetRow( SQLUSMALLINT nRowSetRow )
+{
+    MYODBCDbgEnter();
+
+    if ( getState() < STATE_EXECUTED )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
+
+    if ( nRowSetRow < 1 )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY109 ) );
+
+    if ( nRowSetRow > getRowSetSize() )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY107, 0,
tr("Requested row exceeds RowSetSize.") ) );
+
+    if ( nRowSetRow > getRowSetRows() )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY107, 0,
tr("Requested row exceeds RowSetRows.") ) );
+
+    resultGetData.doClear();
+
+    this->nRowSetRow = nRowSetRow;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+SQLRETURN MResult::setRowSetSize( SQLUINTEGER nRowSetSize )
+{
+    MYODBCDbgEnter();
+
+    if ( nRowSetSize < 1 )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("RowSetSize must be > 0.") ) );
+
+    this->nRowSetSize = nRowSetSize;
+    nRowSetRow = 1;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+/*!
+    \brief  Enables/disables scrolling feature of cursor.
+
+            A Scrollable cursor is one which can be moved forward, backward, and 
+            to random locations in the resultset.
+
+            Cursors are forward-only by default but Scrollable can be enabled 
+            anytime before the command is executed.
+
+            Enabling this will cause all the resultset data to be cached in MResult
+            so this should not be enabled unless truely needed.
+*/
+SQLRETURN MResult::setScrollable( BOOLEAN bScrollable )
+{
+    MYODBCDbgEnter();
+
+    if ( getState() >= STATE_EXECUTED )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
+
+    this->bScrollable = bScrollable;
+
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
 MResult::STATE MResult::getState()
 {
     MYODBCDbgEnter();
     MYODBCDbgReturn3( "%d", nState );
 }
 
+qulonglong MResult::getRowsAffected()
+{
+    MYODBCDbgEnter();
 
+    MYODBCDbgReturn3( "%d", nRowsAffected );
+}
+
 /*!
     \internal
-    \brief          Gets a columns data from the current row in the result set.
+    \brief          Gets a columns data from RowSetRow.
 
                     The primary purpose of this method is to support
MStatement::getData() which, in turn, can be used
                     to support SQLGetData().
@@ -161,8 +230,13 @@
 {
     MYODBCDbgEnter();
 
-    /* validate column number */
-    if ( nColumnNumber > getImpRowDesc()->getCount() )
+    if ( getState() < STATE_EXECUTED )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
+
+    if ( !isValidRowSetRow() )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_24000 ) );
+
+    if ( !isValidColumn( nColumnNumber ) )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07009 ) );
 
     if ( resultGetData.isChunkingRequest( nColumnNumber ) )
@@ -373,56 +447,62 @@
     MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000 ) );
 }
 
-qulonglong MResult::getRowsAffected()
+SQLUSMALLINT MResult::getRowSetRow()
 {
     MYODBCDbgEnter();
+    MYODBCDbgReturn3( "%d", nRowSetRow );
+}
 
-    MYODBCDbgReturn3( "%d", nRowsAffected );
+SQLUINTEGER MResult::getRowSetSize()
+{
+    MYODBCDbgEnter();
+    MYODBCDbgReturn3( "%d", nRowSetSize );
 }
 
-BOOLEAN MResult::isBuffered()
+qulonglong MResult::getResultSetRow()
 {
     MYODBCDbgEnter();
-    MYODBCDbgReturn3( "%d", bBuffered );
+    MYODBCDbgReturn3( "%d", nResultSetRow );
 }
 
-BOOLEAN MResult::isValidColumn( uint nColumn )
+BOOLEAN MResult::isValidColumn( SQLUSMALLINT nColumn )
 {
-    BOOLEAN b;
-
     MYODBCDbgEnter();
 
-    b = ( nColumn <= (uint)getImpRowDesc()->getCount() );
+    BOOLEAN b = ( nColumn <= (SQLUSMALLINT)getImpRowDesc()->getCount() );
 
     MYODBCDbgReturn3( "%d", b );
 }
 
-BOOLEAN MResult::setState( STATE nState )
+BOOLEAN MResult::isValidResultSetRow()
 {
     MYODBCDbgEnter();
 
-    this->nState = nState;
+    BOOLEAN b = isValidResultSetRow( getResultSetRow() );
 
-    MYODBCDbgReturn3( "%d", true );
+    MYODBCDbgReturn3( "%d", b );
 }
 
-BOOLEAN MResult::setBuffered( BOOLEAN bBuffered )
+BOOLEAN MResult::isValidResultSetRow( qulonglong nResultSetRow )
 {
     MYODBCDbgEnter();
 
-    /*!
-        \internal MYSQLPlus RULE
+    BOOLEAN b = ( nResultSetRow > 0 && ( nResultSetRow <=
getResultSetRows() ) );
 
-        We only support buffered results.
+    MYODBCDbgReturn3( "%d", b );
+}
 
-        \todo
+BOOLEAN MResult::isBuffered()
+{
+    MYODBCDbgEnter();
+    MYODBCDbgReturn3( "%d", bBuffered );
+}
 
-        We want to support unbuffered results in; MResultRes and MResultStmt.
-    */
-    if ( !bBuffered )
-        MYODBCDbgReturn3( "%d", false );
+BOOLEAN MResult::setState( STATE nState )
+{
+    MYODBCDbgEnter();
 
-    this->bBuffered = bBuffered;
+    this->nState = nState;
 
     MYODBCDbgReturn3( "%d", true );
 }

Modified: trunk/SDK/MYSQLPlus/Library/MResult.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResult.h	2006-09-02 06:04:16 UTC (rev 511)
+++ trunk/SDK/MYSQLPlus/Library/MResult.h	2006-09-03 03:57:02 UTC (rev 512)
@@ -94,7 +94,7 @@
 
             There are two different types of results;
 
-            1. row count    - we only have a row count (ie command was an INSERT or such)
+            1. row count    - we only have a row count (ie command was an UPDATE or such)
             2. resultset    - we have 1-n columns and 0-n rows (ie command was a SELECT
or such)
 
             ResultSet
@@ -126,7 +126,7 @@
             RowSet
             ------
 
-            A RowSet is a cursor but because it may contain more than 1 row - its has its
own
+            A RowSet is a cursor but because it may contain more than 1 row - it has its
own
             cursor (which is always 1 row). The RowSet cursor is called a RowSetRow and
its the
             current row in the RowSet.
 
@@ -161,26 +161,63 @@
         STATE_EXECUTED
     };
 
+    enum CONCURRENCY
+    {
+        CONCURRENCY_READ_ONLY, // default
+        CONCURRENCY_LOCK,
+        CONCURRENCY_ROWVER,
+        CONCURRENCY_VALUES
+    };
+
+    enum CURSOR_SCROLLABLE
+    {
+        CURSOR_SCROLLABLE_NONSCROLLABLE, // default
+        CURSOR_SCROLLABLE_SCROLLABLE
+    };
+
+    enum CURSOR_SENSITIVITY
+    {
+        CURSOR_SENSITIVITY_UNSPECIFIED, // default
+        CURSOR_SENSITIVITY_INSENSITIVE,
+        CURSOR_SENSITIVITY_SENSITIVE
+    };
+
+    enum CURSOR_TYPE
+    {
+        CURSOR_TYPE_FORWARD_ONLY, // default
+        CURSOR_TYPE_STATIC,
+        CURSOR_TYPE_KEYSET_DRIVEN,
+        CURSOR_TYPE_DYNAMIC
+    };
+
+    enum SIMULATE_CURSOR
+    {
+        SIMULATE_CURSOR_NON_UNIQUE,
+        SIMULATE_CURSOR_TRY_UNIQUE, // default
+        SIMULATE_CURSOR_UNIQUE
+    };
+
     MResult( MStatement *pStatement );
     virtual ~MResult();
 
     /* setters */
     virtual SQLRETURN setData( uint nColumn, const QVariant &variantData ) = 0;
-    virtual SQLRETURN setRowSetRow( SQLUSMALLINT nRow ) = 0;                    /*!<
Set position in rowset.                */
+    virtual SQLRETURN setRowSetRow( SQLUSMALLINT nRowSetRow );
     virtual SQLRETURN setRowSetSize( SQLUINTEGER nRowSetSize = 1 );
+    virtual SQLRETURN setScrollable( BOOLEAN bScrollable );
 
     /* getters */
     STATE                   getState();
     qulonglong              getRowsAffected();
-    virtual SQLRETURN       getColumns( uint *pnColumns ) = 0;
+    virtual SQLUSMALLINT    getColumns() = 0;
     virtual SQLRETURN       getData( SQLUSMALLINT nColumn, QVariant &variantData ) =
0;
     virtual SQLRETURN       getData( SQLUSMALLINT nColumn, SQLSMALLINT nTargetType,
SQLPOINTER pTargetValue, SQLINTEGER nBufferLength, SQLINTEGER *pnLength, SQLINTEGER
*pnIndicator );
-    virtual qulonglong      getRowSet() = 0;                            /*!< Row, in
resultset, where rowset begins. \sa getResultSetRow                */
-    virtual SQLUSMALLINT    getRowSetRow() = 0;                         /*!< Current
row in rowset.                                                     */
-    virtual SQLUINTEGER     getRowSetRows() = 0;                        /*!< Number of
rows in rowset (max=getRowSetSize).                              */
-    virtual SQLUINTEGER     getRowSetSize();                            /*!< Max
number of rows in rowset (rowset trunc. if part past resultset).       */
-    virtual qulonglong      getResultSetRow() = 0;                      /*!< Current
row in resultset. \sa getRowSet                                    */
-    virtual SQLRETURN       getResultSetRows( qulonglong *pnRows ) = 0; /*!< Number of
resultset rows.                                                  */
+    virtual SQLUSMALLINT    getRowSetRow();         /*!< Current row in rowset.       
                                             */
+    virtual SQLUINTEGER     getRowSetRows() = 0;    /*!< Number of rows in rowset
(max=getRowSetSize).                              */
+    virtual SQLUINTEGER     getRowSetSize();        /*!< Max number of rows in rowset
(rowset trunc. if part past resultset).       */
+    virtual qulonglong      getResultSetRow();      /*!< Current row in resultset.    
                                             */
+    virtual qulonglong      getResultSetRows() = 0; /*!< Number of resultset rows.    
                                             */
+    virtual BOOLEAN         getScrollable();
 
     /* doers */
     virtual SQLRETURN doPrepare( MCommand *pCommand ) = 0;  /*!< Prepare the given
command.                                 */
@@ -199,11 +236,11 @@
     virtual SQLRETURN doRefresh() = 0;                      /*!< Load/refreshs bound
buffers provided by application.       */
 
     /* isers */
-    virtual BOOLEAN isValidColumn( uint nColumn );
-    virtual BOOLEAN isValidRowSet() = 0;
-    virtual BOOLEAN isValidRowSet( qulonglong nRow ) = 0;
+    virtual BOOLEAN isValidColumn( SQLUSMALLINT nColumn );
+    virtual BOOLEAN isValidResultSetRow();
+    virtual BOOLEAN isValidResultSetRow( qulonglong nResultSetRow );
     virtual BOOLEAN isValidRowSetRow() = 0;
-    virtual BOOLEAN isValidRowSetRow( qulonglong nRow ) = 0;
+    virtual BOOLEAN isValidRowSetRow( SQLUSMALLINT nRowSetRow ) = 0;
     BOOLEAN         isBuffered();
     virtual BOOLEAN isDirty() = 0;
 
@@ -213,7 +250,6 @@
 
     /* setters */
     BOOLEAN setState( STATE nState );
-    virtual BOOLEAN   setBuffered( BOOLEAN bBuffered );
 
     /* getters */
     MYSQL *         getMySQL();
@@ -332,8 +368,31 @@
     SQLRETURN doLoadMetaDataField( unsigned int nField, MYSQL_FIELD *pField,
MDescriptorIRD *pDescriptor );
 
 private:
-    STATE           nState;         /*!< our state                                    
                                                                 */
-    BOOLEAN         bBuffered;      /*!< true causes entire resultset to get pulled to
client at execute (enabling other features) (default=true)       */
+    STATE               nState;         /*!< our state                                
                                                                     */
+
+    /*!
+        \name Statement attributes.
+
+        We duplicate these because; 
+
+        1. we want loose coupling with MStatement
+        2. we may change these due to operation/implemention details (but we do not want
to 
+           change in MStatement)
+    */
+    /*@{*/
+    CONCURENCY          nConcurrency;       /*!< SQL_ATTR_CONCURRENCY           */
+    CURSOR_SCROLLABLE   nCursorScrollable;  /*!< SQL_ATTR_CURSOR_SCROLLABLE     */ 
+    CURSOR_SENSITIVITY  nCursorSensitivity; /*!< SQL_ATTR_CURSOR_SENSITIVITY    */
+    CURSOR_TYPE         nCursorType;        /*!< SQL_ATTR_CURSOR_TYPE           */
+    SQLUINTEGER         nKeySetSize;        /*!< SQL_ATTR_KEYSET_SIZE           */
+    SQLUINTEGER         nMaxLength;         /*!< SQL_ATTR_MAX_LENGTH            */
+    SQLUINTEGER         nMaxRows;           /*!< SQL_ATTR_MAX_ROWS              */
+    SQLUINTEGER         nRowSetSize;        /*!< SQL_ATTR_ROW_ARRAY_SIZE        */
+    SIMULATE_CURSOR     nSimulateCursor;    /*!< SQL_ATTR_SIMULATE_CURSOR       */
+    /*@}*/
+
+    qulonglong      nResultSetRow;  /*!< Current row in resultset. \sa getRowSet      
                             */
+    SQLUSMALLINT    nRowSetRow;     /*!< Current row in rowset.                       
                             */
     qulonglong      nRowsAffected;  /*!< number of rows affected by a non-SELECT
statement (catalog and SHOW statements count as SELECT in this case)   */
 };
 

Thread
Connector/ODBC 5 commit: r512 - trunk/SDK/MYSQLPlus/Librarypharvey3 Sep