List:Commits« Previous MessageNext Message »
From:pharvey Date:July 16 2006 9:41pm
Subject:Connector/ODBC 5 commit: r444 - in trunk/MYSQLPlus: MYSQLPlusLib include
View as plain text  
Modified:
   trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
   trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
   trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
   trunk/MYSQLPlus/MYSQLPlusLib/MResultRes.cpp
   trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
   trunk/MYSQLPlus/include/MStatement.h
Log:


Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp	2006-07-16 21:41:21 UTC (rev 444)
@@ -14,11 +14,10 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( !pConnection );
-    this->pConnection = pConnection;
-    pStatement = NULL;
+    this->pConnection   = pConnection;
+    pStatement          = NULL;
+    nType               = COMMAND_TYPE_NULL;
 
-    nCommandType = COMMAND_TYPE_NULL;
-
     MYODBCDbgReturn2();
 }
 
@@ -27,11 +26,10 @@
     MYODBCDbgEnter();
 
     Q_ASSERT( !pStatement );
-    this->pStatement = pStatement;
-    pConnection = pStatement->getConnection();
+    this->pStatement    = pStatement;
+    pConnection         = pStatement->getConnection();
+    nType               = COMMAND_TYPE_NULL;
 
-    nCommandType = COMMAND_TYPE_NULL;
-
     MYODBCDbgReturn2();
 }
 
@@ -48,7 +46,7 @@
 
     pConnection     = NULL;
     pStatement      = NULL;
-    nCommandType    = COMMAND_TYPE_NULL;
+    nType           = COMMAND_TYPE_NULL;
 
     MYODBCDbgReturn2();
 }
@@ -105,11 +103,8 @@
     int         nCharsSkipped = 0;
 
     /* clear any existing processing */
-    nCommandType = COMMAND_TYPE_NULL;
-    listParameterMarkers.clear();
-    this->stringCommand.clear();
-    stringCommandNative.clear();
-
+    doClear();
+    
     /* for each char in stringCommand */
     for ( int nChar = 0; nChar < stringCommand.length(); nChar++ )
     {
@@ -187,25 +182,25 @@
         - support for more keywords/types
     */
     if ( this->stringCommand.startsWith( "SELECT " ) )
-        nCommandType = COMMAND_TYPE_SELECT;
+        nType = COMMAND_TYPE_SELECT;
     else if ( this->stringCommand.startsWith( "SHOW " ) )
-        nCommandType = COMMAND_TYPE_SHOW;
+        nType = COMMAND_TYPE_SHOW;
     else if ( this->stringCommand.startsWith( "UPDATE " ) )
-        nCommandType = COMMAND_TYPE_UPDATE;
+        nType = COMMAND_TYPE_UPDATE;
     else if ( this->stringCommand.startsWith( "DELETE " ) )
-        nCommandType = COMMAND_TYPE_DELETE;
+        nType = COMMAND_TYPE_DELETE;
     else if ( this->stringCommand.startsWith( "INSERT " ) )
-        nCommandType = COMMAND_TYPE_INSERT;
+        nType = COMMAND_TYPE_INSERT;
     else if ( this->stringCommand.startsWith( "CALL " ) )
-        nCommandType = COMMAND_TYPE_CALL;
+        nType = COMMAND_TYPE_CALL;
     else if ( this->stringCommand.startsWith( "CREATE " ) )
-        nCommandType = COMMAND_TYPE_CREATE;
+        nType = COMMAND_TYPE_CREATE;
     else if ( this->stringCommand.startsWith( "GRANT " ) )
-        nCommandType = COMMAND_TYPE_GRANT;
+        nType = COMMAND_TYPE_GRANT;
     else if ( this->stringCommand.startsWith( "SET " ) )
-        nCommandType = COMMAND_TYPE_SET;
+        nType = COMMAND_TYPE_SET;
     else
-        nCommandType = COMMAND_TYPE_UNKNOWN;
+        nType = COMMAND_TYPE_UNKNOWN;
 
     MYODBCDbgReturn( nReturn );
 }
@@ -231,20 +226,25 @@
 
     \return QString
 */
-QString MCommand::getCommandNative()
+QString MCommand::getNative()
 {
     MYODBCDbgEnter();
 
-    MYODBCDbgReturn3( "%s", stringCommandNative );
+    MYODBCDbgReturn3( "%s", stringNative );
 }
 
 /*!
     \brief  Gets a list of parameter marker positions.
 
-            This can be used to replace the parameter markers in getCommandNative() with 
-            parameter data.
+            This can be used to replace the parameter markers in getNative() with 
+            parameter data or to simply determine how many (if any) parameter 
+            markers were found.
 
     \return QList<int>
+
+    \sa     getNative
+            getSegments
+            getParameterMarkerCount
 */
 QList<int> MCommand::getParameterMarkers()
 {
@@ -253,16 +253,71 @@
     MYODBCDbgReturn3( "%p", listParameterMarkers );
 }
 
+int MCommand::getParameterMarkerCount()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%d", listParameterMarkers.count() );
+}
+
+/*!
+    \brief  Get command segments.
+
+            Use this to get the command segments. A command segment is the command text
between any parameter markers.
+            or at the beginning/end of the command. A command lacking any parameter
markers will have 1 segment and the
+            segment will contain the entire command text.
+
+            Any parameter markers are NOT included in the segments.
+
+            Command segments can be a useful means to build a complete command (using any
parameter data) to send to 
+            the server.
+
+            It can be assumed that;
+
+            - the existence of 1 segement means there are no parameter markers 
+            - the existence of 2 segments means there was 1 parameter marker
+            - and so on
+
+    \return QStringList List of command segments.
+
+    \sa     getNative
+            getParameterMarkers
+            getParameterMarkerCount
+*/
+QStringList MCommand::getSegments()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%p", stringlistSegments );
+}
+
+/*!
+    \brief  Get general type of command.
+
+            Use this to get the general type of the command. The general type of the
command is largely determined by,
+            and limited by, the first keyword in the command but may be, in some
instances, qualified by other facts
+            in the command.
+
+    \return COMMAND_TYPE    The command type.
+*/
+COMMAND_TYPE MCommand::getType()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%d", nType );
+}
+
 void MCommand::doClear()
 {
     MYODBCDbgEnter();
 
-    pConnection     = NULL;
-    pStatement      = NULL;
-    nCommandType    = COMMAND_TYPE_NULL;
+    pConnection = NULL;
+    pStatement  = NULL;
+    nType       = COMMAND_TYPE_NULL;
     stringCommand.clear();
-    stringCommandNative.clear();
+    stringNative.clear();
     listParameterMarkers.clear();
+    stringlistSegments.clear();
 
     MYODBCDbgReturn2();
 }
@@ -276,7 +331,7 @@
 
         We classify CALL as both DML and DDL. At some point this code will need to know
for certian.
     */
-    switch ( nCommandType )
+    switch ( nType )
     {
         case COMMAND_TYPE_SELECT:
         case COMMAND_TYPE_SELECT_INTO:
@@ -306,7 +361,7 @@
 
         We classify CALL as both DML and DDL. At some point this code will need to know
for certian.
     */
-    switch ( nCommandType )
+    switch ( nType )
     {
         case COMMAND_TYPE_CALL:
         case COMMAND_TYPE_CREATE:
@@ -381,7 +436,7 @@
 
         We assume CALL produces a result-set. At some point this code will need to know
for certian.
     */
-    switch ( nCommandType )
+    switch ( nType )
     {
         case COMMAND_TYPE_CALL:
         case COMMAND_TYPE_SELECT:
@@ -423,7 +478,7 @@
 
         We assume CALL may modify data. At some point this code will need to know for
certian.
     */
-    switch ( nCommandType )
+    switch ( nType )
     {
         case COMMAND_TYPE_CALL:
         case COMMAND_TYPE_CREATE:
@@ -456,7 +511,7 @@
         we may get it wrong at times as some feature within a command type
         may not be supported.
     */
-    switch ( nCommandType )
+    switch ( nType )
     {
         case COMMAND_TYPE_SELECT:
         case COMMAND_TYPE_UPDATE:
@@ -482,9 +537,10 @@
     pConnection             = rval.pConnection;
     pStatement              = rval.pStatement;
     stringCommand           = rval.stringCommand;
-    stringCommandNative     = rval.stringCommandNative;
+    stringNative            = rval.stringNative;
     listParameterMarkers    = rval.listParameterMarkers;
-    nCommandType            = rval.nCommandType;                   
+    stringlistSegments      = rval.stringlistSegments;
+    nType                   = rval.nType;                   
 
     return *this;
 }

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h	2006-07-16 21:41:21 UTC (rev 444)
@@ -66,9 +66,11 @@
 
     /* getters */
     QString         getCommand();               // simply returns the Text provided to
setCommand()
-    QString         getCommandNative();         // version of text which has any ODBC
specifics switched to server friendly syntax
+    QString         getNative();                // version of text which has any ODBC
specifics switched to server friendly syntax
     QList<int>      getParameterMarkers();      // list of index pos into native
command string where we can find parameter marker ( '?' )
-    COMMAND_TYPE    getCommandType();           // general type of the command as
indicated by first keyword
+    int             getParameterMarkerCount();  // save some cpu over calling
getParameterMarkers().count()
+    QStringList     getSegments();              // the command separated by parameter
markers and without parameter markers
+    COMMAND_TYPE    getType();                  // general type of the command as
indicated by first keyword
 
     /* doers */
     void doClear();
@@ -91,12 +93,13 @@
     MDiagnostic *   getDiagnostic();
 
 private:
-    MConnection *   pConnection;                    /*!< connection we are supporting 
                                                 */
-    MStatement *    pStatement;                     /*!< statement we are supporting
(null if we just supporting the connection)        */
-    QString         stringCommand;                  /*!< the command we are based upon
(may have ODBC _and/or_ server specifics)        */
-    QString         stringCommandNative;            /*!< native (prepared) command
(may have server specifics but no ODBC specifics)    */
-    QList<int>      listParameterMarkers;           /*!< list of index pos into
native command string where we can find param marker    */
-    COMMAND_TYPE    nCommandType;                   /*!< the command type (mostly
based upon first keyword in command)                  */
+    MConnection *   pConnection;            /*!< connection we are supporting         
                                         */
+    MStatement *    pStatement;             /*!< statement we are supporting (null if
we just supporting the connection)        */
+    QString         stringCommand;          /*!< the command we are based upon (may
have ODBC _and/or_ server specifics)        */
+    QString         stringNative;           /*!< native (prepared) command (may have
server specifics but no ODBC specifics)    */
+    QList<int>      listParameterMarkers;   /*!< list of index pos into native
command string where we can find param marker    */
+    QStringList     stringlistSegments;     /*!< command separated by parameter
markers and without parameter markers           */
+    COMMAND_TYPE    nType;                  /*!< the command type (mostly based upon
first keyword in command)                  */
 };
 
 #endif

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp	2006-07-16 21:41:21 UTC (rev 444)
@@ -4995,7 +4995,7 @@
         state; the application can reuse them for subsequent SQL requests or can call
SQLFreeStmt or 
         SQLFreeHandle with a HandleType of SQL_HANDLE_STMT to deallocate them.
     */
-    if ( nCompletionType == SQL_ROLLBACK && getInfoCursorRollbackBehavior() ==
SQL_CB_DELETE )
+    if ( getInfoCursorRollbackBehavior() == SQL_CB_DELETE )
     {
         QList<QObject*> listObjects;
         QListIterator<QObject*> i( (QList<QObject*>)children() );
@@ -5019,7 +5019,7 @@
         present in a prepared state; the application can call SQLExecute for a statement
associated with the 
         connection without first calling SQLPrepare.
     */
-    if ( nCompletionType == SQL_ROLLBACK && getInfoCursorRollbackBehavior() ==
SQL_CB_CLOSE )
+    if ( getInfoCursorRollbackBehavior() == SQL_CB_CLOSE )
     {
         QList<QObject*> listObjects;
         QListIterator<QObject*> i( (QList<QObject*>)children() );
@@ -5045,7 +5045,7 @@
         does not affect open cursors associated with the connection. Cursors remain at
the row they pointed to 
         prior to the call to SQLEndTran.
     */
-    if ( nCompletionType == SQL_ROLLBACK && getInfoCursorRollbackBehavior() ==
SQL_CB_PRESERVE )
+    if ( getInfoCursorRollbackBehavior() == SQL_CB_PRESERVE )
     {
         /* do nothing special  */
     }

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MResultRes.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MResultRes.cpp	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MResultRes.cpp	2006-07-16 21:41:21 UTC (rev 444)
@@ -454,7 +454,9 @@
 
         In other words; all parameters markers must have bound data.
     */
-    if ( pDescriptorIPD->getCount() < stringlistStatement.count( "?" ) )
+    QList<int> listParameterMarkers = command.getParameterMarkers();
+
+    if ( pDescriptorIPD->getCount() < listParameterMarkers.count() )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07002, 0,
QString( "number of IPD records (%1) must be >= number of parameter markers (%2)"
).arg( pDescriptorIPD->getCount() ).arg( stringlistStatement.count( "?" ) ) ) );
 
     /*!
@@ -463,7 +465,7 @@
         APD's can be swapped out by the app between/after SQLBindParameter etc and as
such get out of 
         synch. It should be sufficient to catch the case where we have too few APD
records.
     */
-    if ( pDescriptorAPD->getCount() < stringlistStatement.count( "?" ) )
+    if ( pDescriptorAPD->getCount() < listParameterMarkers.count() )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_07002, 0,
tr("number of APD records must be >= number of parameter markers") ) );
 
     /*!

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp	2006-07-16 21:41:21 UTC (rev 444)
@@ -2205,6 +2205,7 @@
     if ( !SQL_SUCCEEDED( nReturn1 ) )
         MYODBCDbgReturn( nReturn1 );
 
+    /* this controls whether or not we can roll back to prepare state */
     setImplicitPrepare( true );
 
     /*!
@@ -2244,8 +2245,15 @@
         No columns then no resultset - set state accordingly. Being in state S5 does
         not imply that we have data/rows in the resultset - just that we have a 
         resultset.
+
+        \note
+
+        This can also be obtained by getImpRowDesc()->getCount() because at this point

+        we have been executed - so always have good IRD.
     */
-    if ( getImpRowDesc()->getCount() )
+    MCommand command = pCommands->at( pCommands->getCurrent() );
+
+    if ( command.isResultSetPossible() )
         setState( STATE_S5 );
     else
         setState( STATE_S4 );
@@ -2302,7 +2310,7 @@
             1. app calls SQLExecDirect() and then SQLExecute() (without a SQLPrepare() in
the middle)
             2. app calls a catalog function like SQLTables() and then SQLExecute()
(without a SQLPrepare() in the middle)
     */
-    if ( getImplicitPrepare() )
+    if ( isImplicitPrepare() )
         MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY010 ) );
 
     /*!
@@ -2346,8 +2354,15 @@
         No columns then no resultset - set state accordingly. Being in state S5 does
         not imply that we have data/rows in the resultset - just that we have a 
         resultset.
+
+        \note
+
+        This can also be obtained by getImpRowDesc()->getCount() because at this point

+        we have been executed - so always have good IRD.
     */
-    if ( getImpRowDesc()->getCount() )
+    MCommand command = pCommands->at( pCommands->getCurrent() );
+
+    if ( command.isResultSetPossible() )
         setState( STATE_S5 );
     else
         setState( STATE_S4 );
@@ -2954,6 +2969,8 @@
 {
     MYODBCDbgEnter();
 
+    MCommand command;
+
     /*!
         \internal ODBC RULE
 
@@ -3053,7 +3070,7 @@
     }
 
     /* get 1st command - this is the one we will prepare for execute now */
-    MCommand command = pCommands->at( pCommands->getCurrent() );
+    command = pCommands->at( pCommands->getCurrent() );
 
     /* what flavour of resultset do we want? */
     int nStatementType = getConnection()->getStatementType();
@@ -4920,14 +4937,6 @@
     MYODBCDbgReturn3( "%p", pDiagnostic );
 }
 
-BOOLEAN MStatement::getImplicitPrepare()
-{
-    MYODBCDbgEnter();
-
-    MYODBCDbgReturn3( "%d", bImplicitPrepare );
-}
-
-
 MDescriptor *MStatement::getAppParamDescOrig()
 {
     MYODBCDbgEnter();
@@ -5309,9 +5318,10 @@
 
         We silently start a transaction as needed. We do not rely upon the server doing
this for us but perhaps we should - will see.
     */
+    MConnection *   pConnection = getConnection();
+
     if ( pConnection->isTransaction() == false )
     {
-        MConnection *pConnection = getConnection();
 
         switch ( pConnection->getInfoTxnCapable() )
         {
@@ -5334,4 +5344,12 @@
     MYODBCDbgReturn( nReturn );
 }
 
+BOOLEAN MStatement::isImplicitPrepare()
+{
+    MYODBCDbgEnter();
 
+    MYODBCDbgReturn3( "%d", bImplicitPrepare );
+}
+
+
+

Modified: trunk/MYSQLPlus/include/MStatement.h
===================================================================
--- trunk/MYSQLPlus/include/MStatement.h	2006-07-16 18:59:26 UTC (rev 443)
+++ trunk/MYSQLPlus/include/MStatement.h	2006-07-16 21:41:21 UTC (rev 444)
@@ -129,7 +129,6 @@
     /* getters */
     MConnection *   getConnection();                
     MDiagnostic *   getDiagnostic();
-    BOOLEAN         getImplicitPrepare();
 
     MDescriptor*    getAppParamDescOrig();          /*!< Original app param desc.     
                                     */ 
     MDescriptor*    getAppRowDescOrig();            /*!< Original app row desc.       
                                     */ 
@@ -173,6 +172,9 @@
     SQLRETURN       doIdentifierArgumentMakeNice( QString stringIA );
     SQLRETURN       doPrepare( const MCommand &command );
 
+    /* is'ers */
+    BOOLEAN         isImplicitPrepare();
+
 private:
     STATE           nState;                 /*!< our current state                    
                         */
     MDiagnostic *   pDiagnostic;            /*!< Statements diagnostic.               
                         */

Thread
Connector/ODBC 5 commit: r444 - in trunk/MYSQLPlus: MYSQLPlusLib includepharvey16 Jul