Added:
trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
Modified:
trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h
trunk/MYSQLPlus/MYSQLPlusLib/MInternal.h
trunk/MYSQLPlus/MYSQLPlusLib/MYSQLPlusLib.pro
trunk/MYSQLPlus/include/MStatement.h
Log:
fleshing out MCommands
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommand.h 2006-07-10 06:31:33 UTC (rev 432)
@@ -35,17 +35,17 @@
public:
enum COMMAND_TYPE
{
- COMMAND_TYPE_NULL, /*!< we do not have a statement
*/
- COMMAND_TYPE_SELECT, /*!< SELECT statement has been prepared
*/
- COMMAND_TYPE_SELECT_INTO, /*!< SELECT INTO statement has been prepared
*/
- COMMAND_TYPE_SHOW, /*!< SHOW statement has been prepared
*/
- COMMAND_TYPE_UPDATE, /*!< UPDATE statement has been prepared
*/
- COMMAND_TYPE_DELETE, /*!< DELETE statement has been prepared
*/
- COMMAND_TYPE_INSERT, /*!< INSERT statement has been prepared
*/
- COMMAND_TYPE_CALL, /*!< CALL statement has been prepared
*/
- COMMAND_TYPE_CREATE, /*!< CALL statement has been prepared
*/
- COMMAND_TYPE_GRANT, /*!< CALL statement has been prepared
*/
- COMMAND_TYPE_SET /*!< CALL statement has been prepared
*/
+ COMMAND_TYPE_NULL, /*!< we do not have a statement
*/
+ COMMAND_TYPE_SELECT, /*!< SELECT statement has been prepared
*/
+ COMMAND_TYPE_SELECT_INTO, /*!< SELECT INTO statement has been prepared
*/
+ COMMAND_TYPE_SHOW, /*!< SHOW statement has been prepared
*/
+ COMMAND_TYPE_UPDATE, /*!< UPDATE statement has been prepared
*/
+ COMMAND_TYPE_DELETE, /*!< DELETE statement has been prepared
*/
+ COMMAND_TYPE_INSERT, /*!< INSERT statement has been prepared
*/
+ COMMAND_TYPE_CALL, /*!< CALL statement has been prepared
*/
+ COMMAND_TYPE_CREATE, /*!< CREATE statement has been prepared
*/
+ COMMAND_TYPE_GRANT, /*!< GRANT statement has been prepared
*/
+ COMMAND_TYPE_SET /*!< SET statement has been prepared
*/
};
MCommand( MConnection *pConnection );
Added: trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommands.cpp 2006-07-10 06:31:33 UTC (rev 432)
@@ -0,0 +1,177 @@
+/*!
+ \file MCommands.cpp
+ \author Peter Harvey <pharvey@stripped>
+ Copyright (C) MySQL AB 2004-2006, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2006
+*/
+
+#ifndef MCOMMANDS_H
+#define MCOMMANDS_H
+
+#include "MInternal.h"
+
+MCommands::MCommands( MConnection *pConnection )
+{
+ MYODBCDbgEnter();
+
+ Q_ASSERT( !pConnection );
+ this->pConnection = pConnection;
+ pStatement = NULL;
+
+ MYODBCDbgReturn2();
+}
+
+MCommands::MCommands( 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::setCommands( const QString &stringCommands )
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn = SQL_SUCCESS;
+
+ this->stringCommands = stringCommands;
+
+ MYODBCDbgReturn( nReturn );
+}
+
+/*!
+ \internal
+ \brief Simply returns the command string provided earlier with setCommands - if
any.
+
+ \return QString
+*/
+QString MCommands::getCommands()
+{
+ MYODBCDbgEnter();
+
+ MYODBCDbgReturn3( "%s", stringCommands );
+}
+
+/*!
+ \brief Assembles all commands, in native form, separated by ';'.
+
+ This is to support SQLNativeSql.
+
+ \return QString
+*/
+QString MCommands::getCommandsNative()
+{
+ MYODBCDbgEnter();
+
+ SQLRETURN nReturn = SQL_SUCCESS;
+ SQLRETURN n;
+ QString stringCommand;
+
+ for ( int i = 0; i < size(); ++i )
+ {
+ if ( stringCommand.isEmpty() )
+ stringCommand += ";";
+ stringCommand += ((MCommand)at( i )).getCommandNative();
+ }
+
+ MYODBCDbgReturn3( "%s", stringCommand );
+}
+
+/*!
+ \internal
+ \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 all commands will honour a transaction.
+ \retval false One or more commands will not honour a transaction.
+*/
+BOOLEAN MCommands::isTransactionPossible()
+{
+ MYODBCDbgEnter();
+
+ for ( int i = 0; i < size(); ++i )
+ {
+ if ( !((MCommand)at( i )).isTransactionPossible() )
+ MYODBCDbgReturn3( "%d", false );
+ }
+
+ MYODBCDbgReturn3( "%d", true );
+}
+
+/*!
+ \internal
+ \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.
+
+ \return BOOLEAN
+
+ \retval true If any of the commands will create a result-set.
+ \retval false None of the commands will create a result-set.
+*/
+BOOLEAN MCommands::isResultSetPossible()
+{
+ MYODBCDbgEnter();
+
+ for ( int i = 0; i < size(); ++i )
+ {
+ if ( ((MCommand)at( i )).isResultSetPossible() )
+ MYODBCDbgReturn3( "%d", true );
+ }
+
+ MYODBCDbgReturn3( "%d", false );
+}
+
+/*!
+ \internal
+ \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 any of the commands may modify data.
+ \retval false None of the commands will modify data.
+*/
+BOOLEAN MCommands::isDataModificationPossible()
+{
+ MYODBCDbgEnter();
+
+ for ( int i = 0; i < size(); ++i )
+ {
+ if ( ((MCommand)at( i )).isDataModificationPossible() )
+ MYODBCDbgReturn3( "%d", true );
+ }
+
+ MYODBCDbgReturn3( "%d", false );
+}
+
+MDiagnostic *MCommands::getDiagnostic()
+{
+ if ( pStatement )
+ pStatement->getDiagnostic();
+
+ pConnection->getDiagnostic();
+}
+
+
+
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MCommands.h 2006-07-10 06:31:33 UTC (rev 432)
@@ -6,8 +6,8 @@
\date 2006
*/
-#ifndef MCOMMAND_H
-#define MCOMMAND_H
+#ifndef MCOMMANDS_H
+#define MCOMMANDS_H
#include "MInternal.h"
@@ -29,6 +29,9 @@
a complete parser would be useful as we can not get all of this information
via the
mysqlclient/server - certianly not in the connection/statement states we need
them in.
+ This is not, at this time, optimized for speed. The focus is on clarity. In
particular; this
+ does multiple passes over the command(s).
+
\sa MCommand
*/
class MCommands : public QList<MCommand>
@@ -49,6 +52,7 @@
/* isers */
BOOLEAN isTransactionPossible();
BOOLEAN isResultSetPossible();
+ BOOLEAN isDataModificationPossible();
protected:
/* setters */
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MInternal.h
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MInternal.h 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MInternal.h 2006-07-10 06:31:33 UTC (rev 432)
@@ -9,6 +9,8 @@
#include <MYODBCDbg.h>
+class MCommands;
+class MCommand;
class MResult;
class MResultPlus;
class MResultRes;
@@ -25,6 +27,8 @@
class MDescriptorRecordIPD;
class MDescriptorRecordIRD;
+#include "MCommands.h"
+#include "MCommand.h"
#include "MDiagnostic.h"
#include "MDiagnosticRecord.h"
#include "MDescriptorAPD.h"
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MYSQLPlusLib.pro
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MYSQLPlusLib.pro 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MYSQLPlusLib.pro 2006-07-10 06:31:33 UTC (rev 432)
@@ -24,6 +24,8 @@
../include/MConnection.h \
../include/MStatement.h \
../include/MDescriptor.h \
+ MCommand.h \
+ MCommands.h \
MResult.h \
MResultPlus.h \
MResultRes.h \
@@ -42,6 +44,8 @@
MInternal.h
SOURCES = \
+ MCommand.cpp \
+ MCommands.cpp \
MEnvironment.cpp \
MConnection.cpp \
MStatement.cpp \
Modified: trunk/MYSQLPlus/include/MStatement.h
===================================================================
--- trunk/MYSQLPlus/include/MStatement.h 2006-07-10 05:07:27 UTC (rev 431)
+++ trunk/MYSQLPlus/include/MStatement.h 2006-07-10 06:31:33 UTC (rev 432)
@@ -5,6 +5,7 @@
class MStatement : public QObject
{
+ friend class MStatement;
friend class MConnection;
friend class MResult;
friend class MResultPlus;
| Thread |
|---|
| • Connector/ODBC 5 commit: r432 - in trunk/MYSQLPlus: MYSQLPlusLib include | pharvey | 10 Jul |