List:Commits« Previous MessageNext Message »
From:pharvey Date:September 6 2006 8:51pm
Subject:Connector/ODBC 5 commit: r529 - trunk/SDK/MYSQLPlus/Library
View as plain text  
Modified:
   trunk/SDK/MYSQLPlus/Library/MResult.cpp
   trunk/SDK/MYSQLPlus/Library/MResult.h
   trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
   trunk/SDK/MYSQLPlus/Library/MResultRes.cpp
   trunk/SDK/MYSQLPlus/Library/MResultRes.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-06 16:17:26 UTC (rev 528)
+++ trunk/SDK/MYSQLPlus/Library/MResult.cpp	2006-09-06 20:51:40 UTC (rev 529)
@@ -108,6 +108,7 @@
     Q_ASSERT( pStatement );
 
     bResultSetRowsKnown = false;
+    nBuffered           = BUFFERED_UNBUFFERED;              // no ResultSet buffering 
     nConcurrency        = CONCURRENCY_READ_ONLY;            // ReadOnly ResultSet
     nCursorScrollable   = CURSOR_SCROLLABLE_NONSCROLLABLE;  // doNext is only viable
cursor operation
     nCursorSensitivity  = CURSOR_SENSITIVITY_UNSPECIFIED;   // we do not share changes to
ResultSet enthusiastically
@@ -449,6 +450,12 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
+BUFFERED MResult::getBuffered()
+{
+    MYODBCDbgEnter();
+    MYODBCDbgReturn3( "%d", bBuffered );
+}
+
 /*! 
     \brief  Used to get the number of columns in the result-set.
                 
@@ -1494,7 +1501,18 @@
     MYODBCDbgReturn( SQL_NO_DATA );
 }
 
+SQLRETURN MResult::setBuffered( BUFFERED bBuffered )
+{
+    MYODBCDbgEnter();
 
+    if ( getState() >= STATE_PREPARED )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
+
+    this->bBuffered = bBuffered;
+
+    MYODBCDbgReturn( SQL_SUCCCESS );
+}
+
 /*!
     \brief      Gets data based upon the type information in the data source.
 

Modified: trunk/SDK/MYSQLPlus/Library/MResult.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResult.h	2006-09-06 16:17:26 UTC (rev 528)
+++ trunk/SDK/MYSQLPlus/Library/MResult.h	2006-09-06 20:51:40 UTC (rev 529)
@@ -173,6 +173,13 @@
         STATE_EXECUTED
     };
 
+    enum BUFFERED
+    {
+        BUFFERED_MYSQL_CLIENT,
+        BUFFERED_MYSQL_PLUS,
+        BUFFERED_UNBUFFERED // default
+    };
+
     enum CONCURRENCY
     {
         CONCURRENCY_READ_ONLY, // default
@@ -226,6 +233,7 @@
     virtual SQLRETURN setSimulateCursor( SIMULATE_CURSOR nSimulateCursor =
SIMULATE_CURSOR_TRY_UNIQUE );
 
     /* getters */
+    virtual BUFFERED            getBuffered();
     virtual SQLUSMALLINT        getColumns();
     virtual CONCURENCY          getConcurrency();
     virtual CURSOR_SCROLLABLE   getCursorScrollable();
@@ -302,8 +310,9 @@
     /*@}*/
 
     /* setters */
+    virtual SQLRETURN   setAfterEnd();
     virtual SQLRETURN   setBeforeStart();
-    virtual SQLRETURN   setAfterEnd();
+    virtual SQLRETURN   setBuffered( BUFFERED bBuffered = BUFFERED_UNBUFFERED );
     SQLRETURN           setGetDataDefault(); // support for getData: this is called when
target C type is SQL_C_DEFAULT  (derive type from IRD)
 
     /* getters */
@@ -427,6 +436,7 @@
         an overly complicated interface to them via derived classes. This is an
exception.
     */
 
+    BUFFERE     nBuffered;      /*!< where is ResultSet buffered - if at all    */
 
 };
 

Modified: trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp	2006-09-06 16:17:26 UTC (rev 528)
+++ trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp	2006-09-06 20:51:40 UTC (rev 529)
@@ -8,8 +8,8 @@
     setObjectName( "MResultPlus" ); // we avoid Q_OBJECT by avoiding className
 
     stringlistTableTypesPossible << "SYSTEM TABLE" << "TABLE";
-    nResultSetRow = 0;
     setState( STATE_INITIALIZED );
+    setBuffered( BUFFERED_MYSQL_PLUS );
 
     MYODBCDbgReturn2();
 }
@@ -1322,6 +1322,21 @@
     MYODBCDbgReturn( SQL_SUCCESS );
 }
 
+/*!
+    \brief  Downgrades cursor if it exceeds our abilities.
+
+            The caller can request certian cursor support before we enter the 
+            prepare state. However; we may find, after doing the prepare or after 
+            doing the execute, that we can not support it. In such a case we need 
+            to downgrade the cursor.
+
+            For example; MStatement may want certian cursor characteristics but 
+            we can not provide it. In such a case we downgrade the cursor here. When
+            we are done MStatement still knows what it wants next time (either
+            the default or what the app has requested).
+
+    \return SQLRETURN
+*/
 SQLRETURN MResultPlus::doApplyCursorRestrictions()
 {
     MYODBCDbgEnter();

Modified: trunk/SDK/MYSQLPlus/Library/MResultRes.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultRes.cpp	2006-09-06 16:17:26 UTC (rev 528)
+++ trunk/SDK/MYSQLPlus/Library/MResultRes.cpp	2006-09-06 20:51:40 UTC (rev 529)
@@ -12,17 +12,8 @@
 
     setObjectName( "MResultRes" ); // we avoid Q_OBJECT by avoiding className
 
-    setState( STATE_UNINITIALIZED );
-    pRes = NULL;
-
-    /*!
-        \internal
-        \todo
-
-        Provide buffered/unbuffered based upon pStatement->getCursorType(). For now we
always use 
-        buffered as it provides the most functionality (although less optimization).
-    */
-
+    pRes        = NULL;
+    pCommand    = NULL;
     setState( STATE_INITIALIZED );
 
     MYODBCDbgReturn2();
@@ -69,69 +60,6 @@
 }
 
 /*! 
-    \brief  Makes nRow the current row of the result-set.
-                
-            This is used to set the current row to any valid row position. If the
-            row is not valid - the current row will be before the 1st row and
-            SQL_NO_DATA will be returned. 
-            
-            The row data will be refreshed and any bound columns will be updated.
-
-    \param  nRow    The desired row in the result-set. This is 1-based however;
-                    0 can be used to make the current row - the row before the 1st 
-                    row.
-
-    \return SQLRETURN
-    
-    \sa     getRow
-            getRows
-            doNext
-            doPrev
-            doFirst
-            doLast
-            doSkip
-*/
-SQLRETURN MResultRes::setRow( qulonglong nRow )
-{
-    MYODBCDbgEnter();
-
-    if ( getState() < STATE_EXECUTED )
-        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
-
-    if ( nRow == this->nRow )
-        MYODBCDbgReturn( SQL_SUCCESS );
-
-    resultGetData.doClear();
-
-    if ( !isBuffered() )
-    {
-        if ( nRow < this->nRow )
-            MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("setRow() not fully supported for unbuffered resultset") ) );
-
-        MYODBCDbgReturn( doSkip( this->nRow - nRow ) );
-    }
-
-    if ( nRow < this->nRow )
-    {
-        if ( getStatement()->getCursorType() == SQL_CURSOR_FORWARD_ONLY )
-            MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("setRow() not supported when SQL_CURSOR_FORWARD_ONLY") ) );
-    }
-
-    if ( nRow == 0 )
-    {
-        this->nRow = 0;
-        MYODBCDbgReturn( SQL_SUCCESS );
-    }
-    else if ( !isValidRow( nRow ) )
-    {
-        this->nRow = 0;
-        MYODBCDbgReturn( SQL_NO_DATA );
-    }
-
-    MYODBCDbgReturn( doSeek( nRow ) );
-}
-
-/*! 
     \brief  Use this to get a column value.
 
             This will get the value of a cell in the result-set - for the current row.
@@ -141,7 +69,7 @@
 
             Basically; we use QVariant as the hub in a spoke & hub solution to data
conversion.
 
-    \param  pnColumns   Pointer to be used to return the number of columns.
+    \param  nColumn     Desired column.
     \param  variantData The column value is return here.
 
     \return SQLRETURN
@@ -157,13 +85,25 @@
     if ( getState() < STATE_EXECUTED )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
 
-    if ( !isValidRow() )
+    if ( !isValidRowSetRow() )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Invalid row.") ) );
 
     if ( !isValidColumn( nColumn ) )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Invalid column.") ) );
 
+    /*!
+        \internal MYSQLPlus RULE
+
+        Read-only resultsets use row number as bookmark. This only works for resultsets
+        where number of rows does not exceed capacity of qulonglong.
+    */
     if ( nColumn == 0 )
+        variantData = getResultSetRow() - 1 + getRowSetRow() - 1;
+    else
+        variantData = listResults[ getResultSetRow() - 1 + getRowSetRow() - 1 ][ nColumn
- 1 ];
+
++++++++++
+    if ( nColumn == 0 )
     {
         /*!
             \internal
@@ -880,6 +820,54 @@
     MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doCommit() not supported in this context") ) );
 }
 
+/*!
+    \brief  Downgrades cursor if it exceeds our abilities.
+
+            The caller can request certian cursor support before we enter the 
+            prepare state. However; we may find, after doing the prepare or after 
+            doing the execute, that we can not support it. In such a case we need 
+            to downgrade the cursor.
+
+            For example; MStatement may want certian cursor characteristics but 
+            we can not provide it. In such a case we downgrade the cursor here. When
+            we are done MStatement still knows what it wants next time (either
+            the default or what the app has requested).
+
+    \return SQLRETURN
+*/
+SQLRETURN MResultRes::doApplyCursorRestrictions()
+{
+    MYODBCDbgEnter();
+
+    BOOLEAN b = false;
+
+    /*!
+        \internal 
+        \todo
+
+        We can only support; CONCURRENCY_READ_ONLY & CURSOR_TYPE_FORWARD_ONLY at this
time. We
+        need to expand on this.
+    */
+    if ( getConcurrency() != CONCURRENCY_READ_ONLY )
+    {
+        b = true;
+        setConcurrency( CONCURRENCY_READ_ONLY );
+    }
+
+    if ( getCursorType() != CURSOR_TYPE_FORWARD_ONLY )
+    {
+        b = true;
+        setCursorType( CURSOR_TYPE_FORWARD_ONLY );
+    }
+
+    setBuffered( BUFFERED_UNBUFFERED );
+
+    if ( b )
+        MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_01S02 ) );
+    
+    MYODBCDbgReturn( SQL_SUCCESS );
+}
+
 /*! 
     \brief  Set the state.
 
@@ -914,13 +902,14 @@
             getImpRowDesc()->doClear();
             pCommand = NULL;
             setState(STATE_INITIALIZED );
+            setBuffered();
             break;
 
         case STATE_EXECUTED:
             if ( pRes )
                 mysql_free_result( pRes );
             pRes = NULL;
-            nResultSetRows = 0;
+            listRows.clear();
             setResultSetRowsKnown( false );
             setBeforeStart();
             setRowsAffected( 0 );

Modified: trunk/SDK/MYSQLPlus/Library/MResultRes.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultRes.h	2006-09-06 16:17:26 UTC (rev 528)
+++ trunk/SDK/MYSQLPlus/Library/MResultRes.h	2006-09-06 20:51:40 UTC (rev 529)
@@ -48,6 +48,7 @@
 protected:
 
     /* doers */
+    SQLRETURN doApplyCursorRestrictions()
     SQLRETURN doStateRollBack( STATE nState );
 
 private:

Thread
Connector/ODBC 5 commit: r529 - trunk/SDK/MYSQLPlus/Librarypharvey6 Sep