List:Commits« Previous MessageNext Message »
From:pharvey Date:July 10 2006 4:02pm
Subject:Connector/ODBC 5 commit: r435 - trunk/MYSQLPlus/MYSQLPlusLib
View as plain text  
Added:
   trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
Modified:
   trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
Log:
fleshing out MCommand

Added: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp	2006-07-10 15:50:01 UTC (rev 434)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.cpp	2006-07-10 16:02:49 UTC (rev 435)
@@ -0,0 +1,219 @@
+/*! 
+    \file       MCommand.cpp
+    \author     Peter Harvey <pharvey@stripped>
+                Copyright (C) MySQL AB 2004-2006, Released under GPL.
+    \version    Connector/ODBC v5
+    \date       2006
+*/
+
+#include "MCommand.h"
+
+MCommand::MCommand( MConnection *pConnection )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !pConnection );
+    this->pConnection = pConnection;
+    pStatement = NULL;
+
+    MYODBCDbgReturn2();
+}
+
+MCommand::MCommand( MStatement *pStatement )
+{
+    MYODBCDbgEnter();
+
+    Q_ASSERT( !pStatement );
+    this->pStatement = pStatement;
+    pConnection = pStatement->getConnection();
+
+    MYODBCDbgReturn2();
+}
+
+/*!
+    \brief      Causes the given command to be prepared.
+
+                We separate the commands by ';' and create an MCommand for each. 
+
+                The MCommand will do the remaining processing.
+
+    \return     SQLRETURN
+*/
+SQLRETURN MCommands::setCommand( const QString &stringCommands )
+{
+    MYODBCDbgEnter();
+
+    QChar   cQuote;
+    QChar   cMarker( '?' );
+    QChar   cBraceOpen( '{' );
+    QChar   cBraceClose( '}' );
+    int     nBraceNest = 0;
+    BOOLEAN bBraceCheck = true;
+    QString stringQuotes = "\"'";
+    QString stringStatementSegment;
+
+    for ( int nChar = 0; nChar < stringStatement.length(); nChar++ )
+    {
+        QChar cChar = stringStatement.at( nChar );
+
+        /* brace opening (not in quotes) */
+        if ( bBraceCheck && cQuote.isNull() && cChar == cBraceOpen )
+        {
+            nBraceNest++;
+            if ( nBraceNest == 1 )
+                continue;
+        }
+
+        /* brace closing (not in quotes) */
+        if ( bBraceCheck && cQuote.isNull() && cChar == cBraceClose )
+        {
+            nBraceNest--;
+            if ( nBraceNest == 0 )
+            {
+                bBraceCheck = false;
+                continue;
+            }
+        }
+
+        /* turn off brace check? */
+        if ( bBraceCheck && nBraceNest == 0 && !cChar.isSpace() )
+            bBraceCheck = false;
+
+        /* parameter marker */
+        if ( cQuote.isNull() && cChar == cMarker )
+        {
+            if ( !stringStatementSegment.isNull() )
+                stringlistStatement += stringStatementSegment;
+            stringlistStatement += QString( cMarker );
+            stringStatementSegment.clear();
+            continue;
+        }
+
+        /* quote opening */
+        if ( cQuote.isNull() && stringQuotes.contains( cChar ) )
+            cQuote = cChar;
+        /* quote closing */
+        else if ( !cQuote.isNull() && cQuote == cChar )
+            cQuote = '\0';
+
+        stringStatementSegment += cChar;
+    }
+    if ( !stringStatementSegment.isNull() )
+        stringlistStatement += stringStatementSegment;
+
+    this->stringCommand = stringCommand;
+
+    MYODBCDbgReturn( nReturn );
+}
+
+/*!
+    \brief      Simply returns the command string provided earlier with setCommand - if
any.
+
+    \return     QString
+*/
+QString MCommands::getCommand()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%s", stringCommand );
+}
+
+/*!
+    \brief  Gets the server friendly version of command string.
+
+            This will include any parameter markers.
+
+            This is to support SQLNativeSql.
+
+    \return QString
+*/
+QString MCommands::getCommandNative()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%s", stringCommandNative );
+}
+
+/*!
+    \brief  Gets a list of parameter marker positions.
+
+            This can be used to replace the parameter markers in getCommandNative() with 
+            parameter data.
+
+    \return QList<int>
+*/
+QList<int> MCommands::getParameterMarkers()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%p", listParameterMarkers );
+}
+
+/*!
+    \brief  Used to determine if command is going to honour any transaction it may be a
party to.
+
+            This may be used to enforce ODBC rules during a prepare.
+
+    \return BOOLEAN
+
+    \retval true    If command will honour a transaction.
+    \retval false   If command will not honour a transaction.
+*/
+BOOLEAN MCommands::isTransactionPossible()
+{
+    MYODBCDbgEnter();
+
+
+    MYODBCDbgReturn3( "%d", false );
+}
+
+/*!
+    \brief  Used to determine if a result-set will be generated if command were to be
submitted to server.
+
+            This may be used to determine what state to put a MStatement into after a
prepare and when
+            rolling back its state.
+
+    \note   In this context; returning only an 'affected rows' count is not considered to
be a result-set. In other
+            words - the result-set may or may not be empty but it must have at least one
column.
+
+    \return BOOLEAN
+
+    \retval true    If command will create a result-set.
+    \retval false   If command will not create a result-set.
+*/
+BOOLEAN MCommands::isResultSetPossible()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%d", false );
+}
+
+/*!
+    \brief  Used to determine if data modification may occur if command were to be
submitted to server.
+
+            This may be used to check if a command could be sent to the server during a
prepare so as
+            to obtain the row count. But note that even this scenario would depend upon
the absence of 
+            any parameter markers.
+
+    \return BOOLEAN
+
+    \retval true    If command may modify data.
+    \retval false   If command will not modify data.
+*/
+BOOLEAN MCommands::isDataModificationPossible()
+{
+    MYODBCDbgEnter();
+
+    MYODBCDbgReturn3( "%d", false );
+}
+
+MDiagnostic *MCommands::getDiagnostic()
+{
+    if ( pStatement )
+        pStatement->getDiagnostic();
+
+    pConnection->getDiagnostic();
+}
+
+
+

Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp	2006-07-10 15:50:01 UTC (rev 434)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp	2006-07-10 16:02:49 UTC (rev 435)
@@ -6,11 +6,8 @@
     \date       2006
 */
 
-#ifndef MCOMMANDS_H
-#define MCOMMANDS_H
+#include "MCommands.h"
 
-#include "MInternal.h"
-
 MCommands::MCommands( MConnection *pConnection )
 {
     MYODBCDbgEnter();
@@ -180,7 +177,7 @@
 
     \return QList<int>
 */
-QList<int> MCommands::getCommandsNativeMarkers()
+QList<int> MCommands::getParameterMarkers()
 {
     MYODBCDbgEnter();
 

Thread
Connector/ODBC 5 commit: r435 - trunk/MYSQLPlus/MYSQLPlusLibpharvey10 Jul