Modified:
trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
trunk/MYSQLPlus/include/MConnection.h
Log:
adding logic to start transactions
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp 2006-07-07 14:45:18 UTC (rev 429)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MConnection.cpp 2006-07-07 23:07:30 UTC (rev 430)
@@ -4880,6 +4880,104 @@
}
/*!
+ \brief Starts a transaction.
+
+ This is a convenience function which is used to request that the server
+ starts a transaction.
+
+ \note The caller must ensure that this request fits in with the state, config
options
+ and features available. This just sends the request to the server.
+
+ \sa doTransactionCommit
+ doTransactionRollback
+*/
+SQLRETURN MConnection::doTransactionStart()
+{
+ MYODBCDbgEnter();
+
+ if ( !SQL_SUCCEEDED( doSubmitCommand( "START TRANSACTION" ) ) )
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_HY000, 0,
tr("Failed to start transaction.") ) );
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+/*!
+ \brief Commits a transaction.
+
+ This is a convenience function which is used to request that the server
+ commit a transaction.
+
+ \note The caller must ensure that this request fits in with the state, config
options
+ and features available. This just sends the request to the server.
+
+ \sa doTransactionStart
+ doTransactionRollback
+*/
+SQLRETURN MConnection::doTransactionCommit()
+{
+ MYODBCDbgEnter();
+
+ /*!
+ \internal
+ \note
+
+ We could use mysql_commit() but we do not want to deal with the
+ possibility that our connection could be closed (see C API doc)
+ so we use an SQL statement.
+
+ \sa mysql_commit
+ */
+ if ( !SQL_SUCCEEDED( doSubmitCommand( "COMMIT" ) ) )
+ /*!
+ \internal ODBC RULE
+
+ The HandleType was SQL_HANDLE_DBC, and the connection associated with the
Handle failed during the execution of the
+ function, and it cannot be determined whether the requested COMMIT or
ROLLBACK occurred before the failure.
+ */
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_08007 ) );
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+/*!
+ \brief Commits a transaction.
+
+ This is a convenience function which is used to request that the server
+ rollback a transaction.
+
+ \note The caller must ensure that this request fits in with the state, config
options
+ and features available. This just sends the request to the server.
+
+ \sa doTransactionStart
+ doTransactionCommit
+*/
+SQLRETURN MConnection::doTransactionRollback()
+{
+ MYODBCDbgEnter();
+
+ /*!
+ \internal
+ \note
+
+ We could use mysql_rollback() but we do not want to deal with the
+ possibility that our connection could be closed (see C API doc) so
+ we use an SQL statement.
+
+ \sa mysql_rollback
+ */
+ if ( !SQL_SUCCEEDED( doSubmitCommand( "ROLLBACK" ) ) )
+ /*!
+ \internal ODBC RULE
+
+ The HandleType was SQL_HANDLE_DBC, and the connection associated with the
Handle failed during the execution of the
+ function, and it cannot be determined whether the requested COMMIT or
ROLLBACK occurred before the failure.
+ */
+ MYODBCDbgReturn( getDiagnostic()->doAppend( MDiagnostic::DIA_08007 ) );
+
+ MYODBCDbgReturn( SQL_SUCCESS );
+}
+
+/*!
\brief Convenience method for checking if the state 'is connected'.
This is a convenience method which, hopefully, makes the calling code
Modified: trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp
===================================================================
--- trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-07-07 14:45:18 UTC (rev 429)
+++ trunk/MYSQLPlus/MYSQLPlusLib/MStatement.cpp 2006-07-07 23:07:30 UTC (rev 430)
@@ -3046,6 +3046,67 @@
break;
}
+ /*
+ Handle transaction.
+ */
+ MConnection *pConnection = getConnection();
+ switch ( pConnection->getInfoTxnCapable() )
+ {
+ case SQL_TC_NONE:
+ break;
+ case SQL_TC_DML:
+ /*!
+ \internal ODBC RULE
+
+ Transactions can contain only Data Manipulation Language (DML) statements
(SELECT, INSERT, UPDATE,
+ DELETE). Data Definition Language (DDL) statements encountered in a
transaction cause an error.
+ */
+ switch ( pResult->getStatementType() )
+ {
+ case MResult::STATEMENT_TYPE_SELECT:
+ case MResult::STATEMENT_TYPE_UPDATE:
+ case MResult::STATEMENT_TYPE_DELETE:
+ case MResult::STATEMENT_TYPE_INSERT:
+ if ( pConnection->getInfoTxnCapable() == SQL_TC_DML ||
pConnection->getInfoTxnCapable() == SQL_TC_ALL )
+ break;
+ case MResult::STATEMENT_TYPE_NULL:
+ case MResult::STATEMENT_TYPE_MULTI:
+ case MResult::STATEMENT_TYPE_SHOW:
+ case MResult::STATEMENT_TYPE_PLUS:
+ case MResult::STATEMENT_TYPE_OTHER:
+ }
+ case SQL_TC_DDL_COMMIT:
+ case SQL_TC_DDL_IGNORE:
+ case SQL_TC_ALL:
+ }
+
+"START TRANSACTION"
+
+ if ( pConnection->isTransaction() == false )
+ {
+ /* do we support transactions? */
+ if ( pConnection->getInfoTxnCapable() == SQL_TC_NONE )
+ {
+ /* should we start a transaction? */
+ switch ( pResult->getStatementType() )
+ {
+ case MResult::STATEMENT_TYPE_SELECT:
+ case MResult::STATEMENT_TYPE_UPDATE:
+ case MResult::STATEMENT_TYPE_DELETE:
+ case MResult::STATEMENT_TYPE_INSERT:
+ if ( pConnection->getInfoTxnCapable() == SQL_TC_DML ||
pConnection->getInfoTxnCapable() == SQL_TC_ALL )
+ break;
+ case MResult::STATEMENT_TYPE_NULL:
+ case MResult::STATEMENT_TYPE_MULTI:
+ case MResult::STATEMENT_TYPE_SHOW:
+ case MResult::STATEMENT_TYPE_PLUS:
+ case MResult::STATEMENT_TYPE_OTHER:
+ }
+ }
+ }
+
+
+
MYODBCDbgReturn( nReturn );
}
Modified: trunk/MYSQLPlus/include/MConnection.h
===================================================================
--- trunk/MYSQLPlus/include/MConnection.h 2006-07-07 14:45:18 UTC (rev 429)
+++ trunk/MYSQLPlus/include/MConnection.h 2006-07-07 23:07:30 UTC (rev 430)
@@ -353,6 +353,9 @@
SQLRETURN doConnectInternal( MYODBCInsDriverConnect *pDriverConnect );
SQLRETURN doSubmitCommand( const QString &stringCommand );
BOOLEAN doServerAliveSanityCheck();
+ SQLRETURN doTransactionStart();
+ SQLRETURN doTransactionCommit();
+ SQLRETURN doTransactionRollback();
/* iser */
BOOLEAN isConnected();
| Thread |
|---|
| • Connector/ODBC 5 commit: r430 - in trunk/MYSQLPlus: MYSQLPlusLib include | pharvey | 8 Jul |