Modified:
trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h
trunk/MYSQLPlus/MYSQLPlusLib/MResultStmt.h
trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
trunk/MYSQLPlus/include/MStatement.h
Log:
some more work integrating MCommands/MCommand
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp 2006-07-13 23:17:46 UTC (rev 440)
@@ -422,6 +422,39 @@
MYODBCDbgReturn3( "%d", false );
}
+BOOLEAN MCommand::isServerSidePreparePossible()
+{
+ MYODBCDbgEnter();
+
+ /*!
+ \note
+
+ We are conservative in our estimation of whether or not we can
+ support this command in a server side prepared statement. Eeven still
+ we may get it wrong at times as some feature within a command type
+ may not be supported.
+ */
+ switch ( nCommandType )
+ {
+ case COMMAND_TYPE_SELECT:
+ case COMMAND_TYPE_UPDATE:
+ case COMMAND_TYPE_DELETE:
+ case COMMAND_TYPE_INSERT:
+ MYODBCDbgReturn3( "%d", true );
+ case COMMAND_TYPE_CALL:
+ case COMMAND_TYPE_CREATE:
+ case COMMAND_TYPE_GRANT:
+ case COMMAND_TYPE_SELECT_INTO:
+ case COMMAND_TYPE_SET:
+ case COMMAND_TYPE_SHOW:
+ case COMMAND_TYPE_NULL:
+ case COMMAND_TYPE_UNKNOWN:
+ break;
+ }
+
+ MYODBCDbgReturn3( "%d", false );
+}
+
MCommand MCommand::operator=( MCommand rval )
{
pConnection = rval.pConnection;
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h 2006-07-13 23:17:46 UTC (rev 440)
@@ -70,6 +70,7 @@
BOOLEAN isTransactionPossible();
BOOLEAN isResultSetPossible();
BOOLEAN isDataModificationPossible();
+ BOOLEAN isServerSidePreparePossible();
MCommand operator=( MCommand rval );
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp 2006-07-13 23:17:46 UTC (rev 440)
@@ -13,8 +13,9 @@
MYODBCDbgEnter();
Q_ASSERT( !pConnection );
- this->pConnection = pConnection;
- pStatement = NULL;
+ this->pConnection = pConnection;
+ pStatement = NULL;
+ nCurrent = 0;
MYODBCDbgReturn2();
}
@@ -24,8 +25,9 @@
MYODBCDbgEnter();
Q_ASSERT( !pStatement );
- this->pStatement = pStatement;
- pConnection = pStatement->getConnection();
+ this->pStatement = pStatement;
+ pConnection = pStatement->getConnection();
+ nCurrent = 0;
MYODBCDbgReturn2();
}
@@ -128,6 +130,22 @@
MYODBCDbgReturn( nReturn );
}
+BOOLEAN MCommands::setCurrent( int nCurrent )
+{
+ MYODBCDbgEnter();
+
+ /*!
+ \internal
+ \note
+
+ We do not bother to validate because commands can be added/removed
+ without us knowing anyway.
+ */
+ this->nCurrent = nCurrent;
+
+ MYODBCDbgReturn3( "%d", true );
+}
+
/*!
\internal
\brief Simply returns the command string provided earlier with setCommands - if
any.
@@ -200,6 +218,13 @@
MYODBCDbgReturn3( "%p", listParameterMarkers );
}
+int MCommands::getCurrent()
+{
+ MYODBCDbgEnter();
+
+ MYODBCDbgReturn3( "%d", nCurrent );
+}
+
/*!
\internal
\brief Used to determine if command is going to honour any transaction it may be a
party to.
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h 2006-07-13 23:17:46 UTC (rev 440)
@@ -41,12 +41,14 @@
MCommands( MStatement *pStatement );
/* setters */
- SQLRETURN setCommands( const QString &stringCommands ); // this can include ODBC
specifics not supported by server
+ SQLRETURN setCommands( const QString &stringCommands ); // this can include
ODBC specifics not supported by server
+ BOOLEAN setCurrent( int nCurrent ); // set current command (0 based)
/* getters */
QString getCommands(); // simply returns the text provided to
setCommands()
QString getCommandsNative(); // version of text which has any ODBC specifics
switched to server friendly syntax etc (prepared)
QList<int> getParameterMarkers(); // list of index pos into native commands
string where we can find parameter marker ( '?' )
+ int getCurrent(); // return current
/* doers */
@@ -65,6 +67,7 @@
MConnection * pConnection; /*!< connection we are supporting
*/
MStatement * pStatement; /*!< statement we are supporting (null
if we just supporting the connection) */
QString stringCommands; /*!< commands string as provided to
setCommands() */
+ int nCurrent; /*!< current comnmand
*/
};
#endif
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultStmt.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultStmt.h 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultStmt.h 2006-07-13 23:17:46 UTC (rev 440)
@@ -31,6 +31,7 @@
our possible use of mysql_stmt_bind_result().
- There may be limitations due to incomplete implementation of MYSQL_STMT
based
functionality on the server. For example some SQL is not supported at this
time.
+ - Batched (multiple commands in a single statement string) is not supported.
The following are considerations with regard to unbuffered result-sets;
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-07-13 23:17:46 UTC (rev 440)
@@ -2909,6 +2909,28 @@
MYODBCDbgReturn( SQL_ERROR );
}
+/*!
+ \brief Prepare the statement text.
+
+ A prepare is done in several phases as follows;
+
+ 1. We get the statement text into MCommands. The primary thing this does is;
+ - breaks the statement text into the individual commands (in case where
there are more than 1)
+ - gets parameter marker positions (if any)
+ - translates ODBC specific syntax (if any) to server friendly syntax
+ - provides some feature information about command(s)
+ 2. We get a MResult based object to prepare further. This may mean doing
nothing (such
+ as with catalog calls (MResultPlus)) or it may mean initiating a
server-side
+ prepare and getting result metadata (as with MResultStmt).
+ 3. In the case of MResultStmt - we will also request a server-side prepare.
This will
+ do a complete syntax check etc.
+
+ \sa doPrepareCurrent
+ MResult
+ MResultPlus
+ MResultStmt
+ MResultRes
+*/
SQLRETURN MStatement::doPrepare( SQLWCHAR *psStatementText, SQLINTEGER nLength1 )
{
MYODBCDbgEnter();
@@ -2984,6 +3006,21 @@
if ( getState() > STATE_S1 )
doStateRollBack( STATE_S1 );
+ /* get our statement text into a friendly QString */
+ QString stringStatementText;
+
+ /* get our statement text into an MCommand (preprocess it) */
+ pCommands = new MCommands( this );
+
+ SQLRETURN nReturn = pCommands->setCommands( stringStatementText );
+ if ( !SQL_SUCCEEDED( nReturn ) )
+ {
+ delete pCommands;
+ pCommands = NULL;
+ }
+
+ MCommand command = pCommands->
+
/* what flavour of resultset do we want? */
switch ( getConnection()->getStatementType() )
{
@@ -3003,6 +3040,10 @@
- resultset characteristics expected (if possible)
*/
getDiagnostic()->doAppend( MDiagnostic::DIA_01000, 0,
tr("STATEMENT_DYNAMIC is same as STATEMENT_RES at this time") );
+ isServerSidePreparePossible()
+ if ( pCommands->at( getCurrent() ).)
+ {
+ }
case MConnection::STATEMENT_RES:
pResult = new MResultRes( this );
@@ -5177,15 +5218,22 @@
case STATE_S2:
case STATE_S3:
setImplicitPrepare( false );
+ /* cleanup resultset (we always have one here) */
Q_ASSERT( !pResult );
delete pResult;
pResult = NULL;
+ /* cleanup commands (catalog calls do not have one) */
+ if ( pCommands )
+ {
+ delete pCommands;
+ pCommands = NULL;
+ }
+ /* go to pre-prepared state */
setState( STATE_S1 );
break;
case STATE_S4:
case STATE_S5:
-
case STATE_S6:
case STATE_S7:
case STATE_S8:
@@ -5193,23 +5241,22 @@
case STATE_S10:
case STATE_S11:
case STATE_S12:
- pResult->doStateRollBack( MResult::STATE_PREPARED );
- switch ( pResult->getStatementType() )
{
- case MResult::STATEMENT_TYPE_UPDATE:
- case MResult::STATEMENT_TYPE_DELETE:
- case MResult::STATEMENT_TYPE_INSERT:
- setState( STATE_S2 );
- break;
- case MResult::STATEMENT_TYPE_NULL:
- getDiagnostic()->doAppend( MDiagnostic::DIA_01000, 0,
tr("STATEMENT_TYPE_NULL should not happen here") );
- case MResult::STATEMENT_TYPE_MULTI:
- case MResult::STATEMENT_TYPE_SELECT:
- case MResult::STATEMENT_TYPE_SHOW:
- case MResult::STATEMENT_TYPE_PLUS:
- case MResult::STATEMENT_TYPE_OTHER:
- setState( STATE_S3 );
- break;
+ int nState = STATE_S2; // we will not have a resultset
+
+ /* rollback result to prepared state */
+ pResult->doStateRollBack( MResult::STATE_PREPARED );
+
+ /* are we a catalog function? */
+ if ( !pCommands )
+ nState = STATE_S3; // we will have a resultset
+ else
+ {
+ MCommand c = pCommands->at( getCurrent() );
+ if ( c.isResultSetPossible() )
+ nState = STATE_S3; // we will have a resultset
+ }
+ setState( nState );
}
break;
@@ -5247,3 +5294,19 @@
MYODBCDbgReturn( SQL_SUCCESS );
}
+/*!
+ \brief Prepares the current command in pCommands.
+
+ This does the second part of the prepare - it requests the resultset to
+ do its prepare.
+*/
+SQLRETURN MStatement::doPrepareCurrent()
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn;
+
+ MYODBCDbgReturn( nReturn );
+}
+
+
Modified: trunk/MYSQLPlus/include/MStatement.h
===================================================================
--- trunk/MYSQLPlus/include/MStatement.h 2006-07-13 18:50:48 UTC (rev 439)
+++ trunk/MYSQLPlus/include/MStatement.h 2006-07-13 23:17:46 UTC (rev 440)
@@ -74,7 +74,7 @@
SQLRETURN doNumParams( SQLSMALLINT *pnParameterCount );
SQLRETURN doNumResultCols( SQLSMALLINT *pnColumnCountPtr );
SQLRETURN doParamData( SQLPOINTER *ppValuePtrPtr );
- virtual SQLRETURN doPrepare( SQLWCHAR *psStatementText, SQLINTEGER nLength1 );
+ SQLRETURN doPrepare( SQLWCHAR *psStatementText, SQLINTEGER nLength1 );
SQLRETURN doPrimaryKeys( SQLWCHAR *psCatalogName, SQLSMALLINT nNameLength1, SQLWCHAR
*psSchemaName, SQLSMALLINT nNameLength2, SQLWCHAR *psTableName, SQLSMALLINT nNameLength3
);
SQLRETURN doProcedureColumns( SQLWCHAR *psCatalogName, SQLSMALLINT nNameLength1,
SQLWCHAR *psSchemaName, SQLSMALLINT nNameLength2, SQLWCHAR *psProcName, SQLSMALLINT
nNameLength3, SQLWCHAR *psColumnName, SQLSMALLINT nNameLength4 );
SQLRETURN doProcedures( SQLWCHAR *psCatalogName, SQLSMALLINT nNameLength1, SQLWCHAR
*psSchemaName, SQLSMALLINT nNameLength2, SQLWCHAR *psProcName, SQLSMALLINT nNameLength3
);
@@ -171,6 +171,7 @@
/* doers */
SQLRETURN doStateRollBack( STATE nState );
SQLRETURN doIdentifierArgumentMakeNice( QString stringIA );
+ SQLRETURN doPrepareCurrent();
private:
STATE nState; /*!< our current state
*/
| Thread |
|---|
| • Connector/ODBC 5 commit: r440 - in trunk/MYSQLPlus: MYSQLPlusLib include | pharvey | 14 Jul |