Modified:
trunk/SDK/MYSQLPlus/Library/MResult.cpp
trunk/SDK/MYSQLPlus/Library/MResult.h
trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
trunk/SDK/MYSQLPlus/Library/MResultPlus.h
trunk/SDK/MYSQLPlus/Library/MResultRes.cpp
trunk/SDK/MYSQLPlus/Library/MResultRes.h
Log:
- changes/additions for block-cursor support
Modified: trunk/SDK/MYSQLPlus/Library/MResult.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResult.cpp 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResult.cpp 2006-09-18 08:22:31 UTC (rev 549)
@@ -1327,7 +1327,7 @@
SQL_NO_DATA - ResultSet is empty.
SQL_ERROR - State < STATE_EXECUTED
*/
-SQLRETURN MResult::doGoto( qulonglong nRow, BOOLEAN bRefresh )
+SQLRETURN MResult::doGoto( qlonglong nRow, BOOLEAN bRefresh )
{
MYODBCDbgEnter();
Modified: trunk/SDK/MYSQLPlus/Library/MResult.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResult.h 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResult.h 2006-09-18 08:22:31 UTC (rev 549)
@@ -332,7 +332,7 @@
virtual SQLRETURN doDelete() = 0; /*!<
Operates on RowSetRow. */
virtual SQLRETURN doExecute() = 0; /*!<
Execute the prepared command. */
virtual SQLRETURN doFirst( BOOLEAN bRefresh = true ); /*!<
Moves cursor/rowset to start of resultset. */
- virtual SQLRETURN doGoto( qulonglong nRow, BOOLEAN bRefresh = true ); /*!<
Moves cursor/rowset relative to first row of resultset. */
+ virtual SQLRETURN doGoto( qlonglong nRow, BOOLEAN bRefresh = true ); /*!<
Moves cursor/rowset relative to first row of resultset. */
virtual SQLRETURN doInsert() = 0; /*!<
Operates on RowSetRow. */
virtual SQLRETURN doLast( BOOLEAN bRefresh = true ); /*!<
Moves cursor/rowset to end of resultset. */
virtual SQLRETURN doNext( BOOLEAN bRefresh = true ); /*!<
Moves cursor/rowset forward by 1 rowset size. */
Modified: trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2006-09-18 08:22:31 UTC (rev 549)
@@ -97,7 +97,7 @@
We do not actually store a bookmark column (we just use row number for that) so
vectorRows[nRow][0] is
the first data cell.
*/
- vectorRows.append( MResultColumns( getImpRowDesc()->getCount() ) );
+ vectorRows.append( MResultColumns( getColumns() ) );
MYODBCDbgReturn( SQL_SUCCESS );
}
Modified: trunk/SDK/MYSQLPlus/Library/MResultPlus.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultPlus.h 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResultPlus.h 2006-09-18 08:22:31 UTC (rev 549)
@@ -95,7 +95,7 @@
*/
/*@{*/
SQLRETURN doFirst_() { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
- SQLRETURN doGoto_( qulonglong ) { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
+ SQLRETURN doGoto_( qlonglong ) { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
SQLRETURN doLast_() { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
SQLRETURN doNext_() { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
SQLRETURN doPrev_() { MYODBCDbgEnter(); MYODBCDbgReturn( SQL_SUCCESS
); }
Modified: trunk/SDK/MYSQLPlus/Library/MResultRes.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultRes.cpp 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResultRes.cpp 2006-09-18 08:22:31 UTC (rev 549)
@@ -446,7 +446,7 @@
/*!
\brief Prepares for a \sa doGoto.
*/
-SQLRETURN MResultRes::doGoto_( qulonglong nRow )
+SQLRETURN MResultRes::doGoto_( qlonglong nRow )
{
MYODBCDbgEnter();
@@ -461,20 +461,47 @@
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY106 ) );
case BUFFERED_MYSQL_PLUS:
- // have we buffered enough for this request?
- while ( !isResultSetRowsKnown() && nRow + getRowSetSize() >
getResultSetRows() )
+ if ( nRow > 0 )
{
- nReturn1 = getRowSetData();
+ /* load more data as needed */
+ while ( !isResultSetRowsKnown() && nRow + getRowSetSize() >
getResultSetRows() )
+ {
+ nReturn1 = getRowSetData();
+ if ( !SQL_SUCCEEDED( nReturn1 ) )
+ break;
+ }
}
+ else if ( nRow < 0 )
+ {
+ /* load all remaining data so we get accurate ResultSetRows */
+ while ( !isResultSetRowsKnown() )
+ {
+ nReturn1 = getRowSetData();
+ if ( !SQL_SUCCEEDED( nReturn1 ) )
+ break;
+ }
+ }
break;
case BUFFERED_MYSQL_CLIENT:
- if ( nRow >= getResultSetRows() )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_01S06 )
);
+ if ( nRow > 0 )
+ {
+ if ( nRow >= getResultSetRows() )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_01S06
) );
- mysql_data_seek( pRes, nRow );
- // load RowSet
- nReturn1 = getRowSetData();
+ mysql_data_seek( pRes, nRow );
+ // load RowSet
+ nReturn1 = getRowSetData();
+ }
+ else if ( nRow < 0 )
+ {
+ if ( getResultSetRows() + nRow < 1 )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_01S06
) );
+
+ mysql_data_seek( pRes, getResultSetRows() + nRow );
+ // load RowSet
+ nReturn1 = getRowSetData();
+ }
break;
default:
@@ -507,10 +534,7 @@
{
nReturn1 = getRowSetData();
if ( !SQL_SUCCEEDED( nReturn1 ) )
- {
- if ( isResultSetRowsKnown() )
- nReturn1 = SQL_SUCCESS;
- }
+ break;
}
break;
@@ -537,36 +561,35 @@
{
MYODBCDbgEnter();
- if ( getState() < STATE_EXECUTED )
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
+ SQLRETURN nReturn1 = SQL_SUCCESS;
- resultGetData.doClear();
-
- if ( mysql_fetch_row( pRes ) )
+ switch ( getBuffered() )
{
- nRow++;
- MYODBCDbgReturn( doRefresh() );
- }
+ case BUFFERED_UNBUFFERED:
+ nReturn1 = getRowSetData();
+ break;
- nRow = 0;
+ case BUFFERED_MYSQL_PLUS:
+ // do we need to load more data into our buffered ResultSet?
+ while ( !isResultSetRowsKnown() && getResultSetRow() +
getRowSetSize() > getResultSetRows() )
+ {
+ nReturn1 = getRowSetData();
+ if ( !SQL_SUCCEEDED( nReturn1 ) )
+ break;
+ }
+ break;
- int nError = mysql_errno( getMySQL() );
- switch ( nError )
- {
- case 0:
- MYODBCDbgReturn( SQL_NO_DATA );
+ case BUFFERED_MYSQL_CLIENT:
+ mysql_data_seek( pRes, 0 );
+ // load RowSet
+ nReturn1 = getRowSetData();
+ break;
- case CR_SERVER_LOST:
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_08S01,
nError, mysql_error( getMySQL() ) ) );
-
- case CR_UNKNOWN_ERROR:
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000,
nError, mysql_error( getMySQL() ) ) );
-
default:
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000,
nError, tr("unknown return code from mysql_fetch_row()") ) );
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Unknown buffer type.") ) );
}
- MYODBCDbgReturn( SQL_ERROR );
+ MYODBCDbgReturn( nReturn1 );
}
/*!
@@ -576,16 +599,31 @@
{
MYODBCDbgEnter();
- /*!
- \internal
- \todo
+ SQLRETURN nReturn1 = SQL_SUCCESS;
- Implement.
+ switch ( getBuffered() )
+ {
+ case BUFFERED_UNBUFFERED:
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY106 ) );
- \sa MResultStmt::doPrev
- */
+ case BUFFERED_MYSQL_PLUS:
+ break;
- MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doPrev() not supported in this context") ) );
+ case BUFFERED_MYSQL_CLIENT:
+ if ( getResultSetRow() > getRowSetSize() )
+ mysql_data_seek( pRes, getResultSetRow() - getRowSetSize() );
+ else
+ mysql_data_seek( pRes, 0 );
+
+ // load RowSet
+ nReturn1 = getRowSetData();
+ break;
+
+ default:
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Unknown buffer type.") ) );
+ }
+
+ MYODBCDbgReturn( nReturn1 );
}
/*!
@@ -610,32 +648,38 @@
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("doSkip() not fully supported when unbuffered resultset") ) );
}
- resultGetData.doClear();
+ SQLRETURN nReturn1 = SQL_SUCCESS;
- if ( isBuffered() )
+ switch ( getBuffered() )
{
- if ( (nRow + nRows) <= 0 || !isValidRow( nRow + nRows ) )
- {
- nRow = 0;
- MYODBCDbgReturn( SQL_NO_DATA );
- }
+ case BUFFERED_UNBUFFERED:
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY106 ) );
- MYODBCDbgReturn( doSeek( nRow + nRows ) );
- }
- else
- {
- SQLRETURN nReturn;
+ case BUFFERED_MYSQL_PLUS:
+ // do we need to load more data into our buffered ResultSet?
+ while ( !isResultSetRowsKnown() && getResultSetRow() +
getRowSetSize() > getResultSetRows() )
+ {
+ nReturn1 = getRowSetData();
+ if ( !SQL_SUCCEEDED( nReturn1 ) )
+ break;
+ }
+ break;
- for ( qlonglong n = 0; n < nRows; n++ )
- {
- nReturn = doNext();
- if ( !SQL_SUCCEEDED( nReturn ) )
- MYODBCDbgReturn( nReturn );
- }
+ case BUFFERED_MYSQL_CLIENT:
+ if ( getResultSetRow() > getRowSetSize() )
+ mysql_data_seek( pRes, getResultSetRow() - getRowSetSize() );
+ else
+ mysql_data_seek( pRes, 0 );
+ // load RowSet
+ nReturn1 = getRowSetData();
+ break;
+
+ default:
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Unknown buffer type.") ) );
}
- MYODBCDbgReturn( SQL_SUCCESS );
+ MYODBCDbgReturn( nReturn1 );
}
/*!
@@ -770,146 +814,67 @@
here is that the cursor in the mysql client or server has been positioned
before
this call.
- This may alter any of the following in MResult but otherwise does not alter
MResult
- cursor state;
+ Also may update ResultSetRows.
- - nResultSetRows - inc if we now know of more rows
- - nRowSetRows - number of rows in RowSet which could be loaded
- - bResultSetRowsKnown - set to True if we have acquired real nResultSetRows
+ \note Does NOT return an error if < RowSetSize rows could be loaded.
+
+ \return SQLRETURN
*/
SQLRETURN MResultSet::getRowSetData()
{
MYODBCDbgEnter();
- SQLRETURN bSuccessWithInfo = false;
+ SQLUSMALLINT nRowSetRow = 0;
+ if ( getRowSetSize() < 1 )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("RowSetSize < 1") ) );
+
switch ( getBuffered() )
{
case BUFFERED_UNBUFFERED:
- /* load next RowSetRows from res - replace listRows */
- {
- nRowSetRows = 0;
- listRows.clear();
- do
- {
- MYSQL_ROW pRow = mysql_fetch_row( pRes );
- if ( pRow )
- {
- nResultSetRows++;
- nRowSetRows++;
- SQLRETURN nReturn = getRowSetRowData( pRow, nRowSetRows );
- switch ( nReturn )
- {
- case SQL_SUCCESS:
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS;
- break;
- case SQL_SUCCESS_WITH_INFO:
- bSuccessWithInfo = true;
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS_WITH_INFO;
- break;
- default:
- vectorRows[nRow].nStatus = SQL_ROW_ERROR;
- getDiagnostic()->setCursorRowCount( nRows );
- getDiagnostic()->setRowCount( nRows );
- MYODBCDbgReturn( nReturn );
- }
- }
- else
- {
- bResultSetRowsKnown = true;
- // set remaining RowSet rows...
- do
- {
- vectorRows[nRow].nStatus = SQL_ROW_NOROW;
- nRowSetRows++;
- }
- while ( nRowSetRows < nRowSetSize )
- }
- }
- while ( nRowSetRows < nRowSetSize )
- }
- break;
case BUFFERED_MYSQL_CLIENT:
- /* load next RowSetRows from res - replace listRows */
+ /* load next RowSetRows from res - replace RowSet */
{
- nRowSetRows = 0;
listRows.clear();
- do
+ while ( nRowSetRow < getRowSetSize() )
{
MYSQL_ROW pRow = mysql_fetch_row( pRes );
if ( pRow )
{
- nRowSetRows++;
- SQLRETURN nReturn = getRowSetRowData( pRow, nRowSetRows );
- switch ( nReturn )
- {
- case SQL_SUCCESS:
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS;
- break;
- case SQL_SUCCESS_WITH_INFO:
- bSuccessWithInfo = true;
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS_WITH_INFO;
- break;
- default:
- vectorRows[nRow].nStatus = SQL_ROW_ERROR;
- MYODBCDbgReturn( nReturn );
- }
+ vectorStatus[nRowSetRow] = getRowSetRowData( pRow, nRowSetRow );
+ nRowSetRow++;
}
else
{
- // set remaining RowSet rows...
- do
- {
- vectorRows[nRow].nStatus = SQL_ROW_NOROW;
- nRowSetRows++;
- }
- while ( nRowSetRows < nRowSetSize )
+ if ( getBuffered() == BUFFERED_UNBUFFERED )
+ setResultSetRows( getResultSetRows() + nRowSetRow, true );
+ MYODBCDbgReturn( SQL_SUCCESS );
}
}
- while ( nRowSetRows < nRowSetSize )
+ if ( getBuffered() == BUFFERED_UNBUFFERED )
+ setResultSetRows( getResultSetRows() + nRowSetRow );
}
break;
+
case BUFFERED_MYSQL_PLUS:
- /* load next RoweSetRows from res - append to listRows */
+ /* load next RoweSetRows from res - append to ResultSet */
{
- nRowSetRows = 0;
- do
+ while ( nRowSetRow < getRowSetSize() )
{
MYSQL_ROW pRow = mysql_fetch_row( pRes );
if ( pRow )
{
- nResultSetRows++;
- nRowSetRows++;
- listRows.append( QVector<QVariant>( getColumns() ) );
- SQLRETURN nReturn = getRowSetRowData( pRow, nResultSetRows );
- switch ( nReturn )
- {
- case SQL_SUCCESS:
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS;
- break;
- case SQL_SUCCESS_WITH_INFO:
- bSuccessWithInfo = true;
- vectorRows[nRow].nStatus = SQL_ROW_SUCCESS_WITH_INFO;
- break;
- default:
- vectorRows[nRow].nStatus = SQL_ROW_ERROR;
- MYODBCDbgReturn( nReturn );
- }
+ vectorRows.append( MResultColumns( getColumns() ) );
+ vectorStatus[nRowSetRow] = getRowSetRowData( pRow,
vectorRows.count() - 1 );
+ nRowSetRow++;
}
else
{
- /* at this point we have buffered entire ResultSet in MYSQLPlus
*/
- bResultSetRowsKnown = true;
- // set remaining RowSet rows...
- do
- {
- vectorRows[nRow].nStatus = SQL_ROW_NOROW;
- nRowSetRows++;
- }
- while ( nRowSetRows < nRowSetSize )
+ setResultSetRows( getResultSetRows() + nRowSetRow, true );
+ MYODBCDbgReturn( SQL_SUCCESS );
}
}
- while ( nRowSetRows < nRowSetSize )
+ setResultSetRows( getResultSetRows() + nRowSetRow );
}
break;
@@ -917,13 +882,30 @@
MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Invalid buffer type.") ) );
}
- if ( bSuccessWithInfo )
- MYODBCDbgReturn( SQL_SUCCESS_WITH_INFO );
-
MYODBCDbgReturn( SQL_SUCCESS );
}
-SQLRETURN MResultSet::getRowSetRowData( MYSQL_ROW pRow, qulonglong nRow )
+/*!
+ \brief Loads a row.
+
+ Loads a row of data. The data is generalized as it is put into our data
+ conversion hub - QVariant.
+
+ \param pRow A reference to MYSQL_ROW in MYSQL_RES where we will get our data.
+ \param nRow 0-based index into vectorRows where we should load the data.
+
+ \return SQLUSMALLINT
+
+ \retval SQL_ROW_SUCCESS The row was successfully fetched.
+ \retval SQL_ROW_SUCCESS_WITH_INFO The row was successfully fetched. However, a
warning was returned about the row.
+ \retval SQL_ROW_ERROR An error occurred while fetching the row.
+ \retval SQL_ROW_ADDED The row was inserted by SQLBulkOperations().
If the row is fetched again, or is refreshed by SQLSetPos() its status is
SQL_ROW_SUCCESS.
+ This value is not set by SQLFetch() or
SQLFetchScroll().
+ \retval SQL_ROW_UPDATED The row was successfully fetched and has
changed since it was last fetched from this result set. If the row is fetched again from
this result set, or is refreshed by SQLSetPos(), the status changes to the row's new
status.
+ \retval SQL_ROW_DELETED The row has been deleted since it was last
fetched from this result set.
+ \retval SQL_ROW_NOROW The rowset overlapped the end of the result
set and no row was returned that corresponded to this element of the row status array.
+*/
+SQLUSMALLINT MResultSet::getRowSetRowData( MYSQL_ROW pRow, qulonglong nRow /* 0-based */
)
{
MYODBCDbgEnter();
@@ -939,7 +921,7 @@
switch ( pField->type )
{
case MYSQL_TYPE_NULL:
- vectorRows[nRow].vectorColumns[nColumn].clear();
+ vectorRows[nRow][nColumn].clear();
break;
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_TINY:
@@ -962,24 +944,27 @@
case MYSQL_TYPE_SET:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_GEOMETRY:
- vectorRows[nRow].vectorColumns[nColumn].setValue( QString( (const
char *)pRow[nColumn] ) );
+ vectorRows[nRow][nColumn].setValue( QString( (const char
*)pRow[nColumn] ) );
break;
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_TINY_BLOB:
case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_MEDIUM_BLOB:
case MYSQL_TYPE_LONG_BLOB:
- vectorRows[nRow].vectorColumns[nColumn].setValue( QByteArray( (const
char *)pRow[nColumn], pField->max_length ) );
+ vectorRows[nRow][nColumn].setValue( QByteArray( (const char
*)pRow[nColumn], pField->max_length ) );
break;
default:
- MYODBCDbgReturn( getDiagnostic()->doAppend(
MDiagnostic::DIA_HY000, 0, tr("Invalid column data type.") ) );
+ {
+ getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Invalid column data type.") );
+ MYODBCDbgReturn( SQL_ROW_ERROR );
+ }
}
}
else
- vectorRows[nRow].vectorColumns[nColumn].clear();
+ vectorRows[nRow][nColumn].clear();
}
- MYODBCDbgReturn( SQL_SUCCESS );
+ MYODBCDbgReturn( SQL_ROW_SUCCESS );
}
/*!
Modified: trunk/SDK/MYSQLPlus/Library/MResultRes.h
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultRes.h 2006-09-18 06:55:48 UTC (rev 548)
+++ trunk/SDK/MYSQLPlus/Library/MResultRes.h 2006-09-18 08:22:31 UTC (rev 549)
@@ -68,7 +68,7 @@
*/
/*@{*/
SQLRETURN doFirst_();
- SQLRETURN doGoto_( qulonglong nRow );
+ SQLRETURN doGoto_( qlonglong nRow );
SQLRETURN doLast_();
SQLRETURN doNext_();
SQLRETURN doPrev_();
@@ -84,8 +84,8 @@
/* setters */
/* getters */
- SQLRETURN getRowSetData();
- SQLRETURN getRowSetRowData( MYSQL_ROW pRow, qulonglong nRow );
+ SQLRETURN getRowSetData();
+ SQLUSMALLINT getRowSetRowData( MYSQL_ROW pRow, qulonglong nRow );
/* doers */
SQLRETURN doLoadMetaData(); /* load resultset meta data (IRD)
*/
| Thread |
|---|
| • Connector/ODBC 5 commit: r549 - trunk/SDK/MYSQLPlus/Library | pharvey | 18 Sep |