1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/***************************************************************************
* Copyright (C) 1995-2002 MySQL AB, www.mysql.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
****************************************************************************/
/***************************************************************************
* TRANSACT.C *
* *
* @description: For processing transactions *
* *
* @author : MySQL AB(monty@mysql.com, venu@mysql.com) *
* @date : 2001-Aug-15 *
* @product : myodbc3 *
* *
****************************************************************************/
/***************************************************************************
* The following ODBC APIs are implemented in this file: *
* *
* SQLEndTran (ISO 92) *
* SQLTransact (ODBC, Deprecated) *
* *
****************************************************************************/
#include "myodbc3.h"
/*
@type : internal
@purpose : to do the transaction at the connection level
*/
SQLRETURN my_transact(SQLHDBC hdbc,SQLSMALLINT CompletionType)
{
SQLRETURN result = SQL_SUCCESS;
DBC FAR *dbc = (DBC FAR *)hdbc;
const char *query;
if (dbc && !(dbc->flag & FLAG_NO_TRANSACTIONS))
{
switch(CompletionType) {
case SQL_COMMIT:
query = "COMMIT";
break;
case SQL_ROLLBACK:
if (!(dbc->mysql.server_capabilities & CLIENT_TRANSACTIONS))
{
return set_handle_error(SQL_HANDLE_DBC,hdbc,MYERR_S1C00,
"Underlying server does not support transactions, upgrade to version >= 3.23.38",0);
}
query = "ROLLBACK";
break;
default:
return set_handle_error(SQL_HANDLE_DBC,hdbc,MYERR_S1012,NULL,0);
}
pthread_mutex_lock(&dbc->lock);
if (check_if_server_is_alive(dbc) ||
mysql_real_query(&dbc->mysql,query,strlen(query)))
{
result=set_handle_error(SQL_HANDLE_DBC,hdbc,MYERR_S1000,
mysql_error(&dbc->mysql),
mysql_errno(&dbc->mysql));
}
pthread_mutex_unlock(&dbc->lock);
}
return(result);
}
/*
@type : ODBC 3.0
@purpose : requests a commit or rollback operation for all active
operations on all statements associated with a connection
*/
SQLRETURN SQL_API
SQLEndTran(SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT CompletionType)
{
SQLRETURN result=SQL_SUCCESS;
DBUG_ENTER("SQLEndTran");
DBUG_PRINT("enter",("type:%d,handle:%x,option:%d",HandleType,Handle,
CompletionType));
switch (HandleType) {
case SQL_HANDLE_ENV:
/*
TODO : The simple logic could be to call my_transact
with all connection handles in the current environment,
but as majority of the applications doesn't use this
option, lets wait for the request or any bug-report
*/
break;
case SQL_HANDLE_DBC:
result=my_transact(Handle,CompletionType);
break;
default:
result=SQL_ERROR;
set_handle_error(HandleType,Handle,MYERR_S1092,NULL,0);
break;
}
DBUG_RETURN(result);
}
/*
@type : ODBC 1.0
@purpose : Requests a commit or rollback operation for all active
operations on all statement handles (hstmts) associated
with a connection or for all connections associated
with the environment handle, henv
*/
SQLRETURN SQL_API SQLTransact(SQLHENV henv,SQLHDBC hdbc,SQLUSMALLINT fType)
{
SQLRETURN result=SQL_SUCCESS;
DBUG_ENTER("SQLTransact");
DBUG_PRINT("enter",("henv:%x,hdbc:%x,option:%d",henv,hdbc,fType));
if (hdbc)
result = my_transact(hdbc,fType);
DBUG_RETURN(result);
}
|