FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

play transactions with odbc

 
Post new topic   Reply to topic     Forum Index -> DDBI
View previous topic :: View next topic  
Author Message
davidl



Joined: 17 Aug 2006
Posts: 27

PostPosted: Tue Nov 28, 2006 4:49 am    Post subject: play transactions with odbc Reply with quote

add following methods to odbcdatabase.d in the odbcdatabase class
void BeginTrans()
{
if (!SQL_SUCCEEDED(SQLSetConnectAttr(connection, SQL_ATTR_AUTOCOMMIT, cast(SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER))){
throw new DBIException("Unable to begin trans ODBC returned");
}
}

void CommitTrans()
{
if (!SQL_SUCCEEDED(SQLEndTran(SQL_HANDLE_DBC, connection, SQL_COMMIT))) {
throw new DBIException("Unable to commit. ODBC returned " ~ getLastErrorMessage, "Transactions", getLastErrorCode);
}
if (!SQL_SUCCEEDED(SQLSetConnectAttr(connection, SQL_ATTR_AUTOCOMMIT, cast(SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_UINTEGER))){
throw new DBIException("Unable to set attr back to auto after commit. ODBC returned");
}
}
void RollBack()
{
if (!SQL_SUCCEEDED(SQLEndTran(SQL_HANDLE_DBC, connection, SQL_ROLLBACK))) {
throw new DBIException("Unable to rollback after a query failure. ODBC returned " ~ getLastErrorMessage, "Transactions", getLastErrorCode);
}
if (!SQL_SUCCEEDED(SQLSetConnectAttr(connection, SQL_ATTR_AUTOCOMMIT, cast(SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_UINTEGER))){
throw new DBIException("Unable to set attr back to auto after rollback. ODBC returned");
}
}

create a def file ( i don't know if it's odbc32.lib's mistake)
we need the SQLSetConnectAttr

myodbc32.lib

LIBRARY 'odbc32.DLL'

EXPORTS

_SQLSetConnectAttr@16 = SQLSetConnectAttr


then
implib.exe myodbc32.lib myodbc32.def

last step of using it

auto db= new OdbcDatabase();
db.connect("your connection string");
db.BeginTrans;
db.execute("your SQL");
db.CommitTrans;

if u want more than 1 transactions u need more than 1 connection.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DDBI All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group