[self odbcErrorWithChannel:nil string:@"SQLDriverConnect in -[ODBCContext odbcConnect]" raise: (result != SQL_SUCCESS_WITH_INFO)];
}
_isConnected = YES;
}
- (void)odbcDisconnect
{
RETCODE result;
//
// If already disconected then return
//
if (!_isConnected) return;
//
// Check the current transaction count
//
if (_transactionNestingLevel){
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempt to disconnect while a transaction was in progress", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// Disconnect from the datasource and free the handle.
// NOTE: Some drivers don't support SQLDisconnect...
//
if(_debug) NSLog(@"disconnect");
result = SQLDisconnect(_odbcDatabaseConnection);
if ( result != SQL_SUCCESS ) {
[self odbcErrorWithChannel:nil string:@"SQLDisconnect in -[ODBCContext odbcDisconnect]" raise: (result != SQL_SUCCESS_WITH_INFO)];
}
_isConnected = NO;
}
- (void)beginTransaction
{
//
// If not connected then raise exception
//
if (!_isConnected) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to begin a transaction without connecting", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// If within a transaction then raise exception
//
if (_transactionNestingLevel) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to begin a transaction within a transaction", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// Notify the delegate with should
//
if (_delegateRespondsTo.shouldBegin) {
if(![_delegate adaptorContextShouldBegin:self])
return;
}
//
// This is a little bit of a lie, since it does nothing. In ODBC, the
// transaction begins at login time, or after a commit or rollback.
//
[self transactionDidBegin];
//
// Notify the delegate with did
//
if (_delegateRespondsTo.didBegin)
[_delegate adaptorContextDidBegin:self];
}
- (void)commitTransaction
{
RETCODE result;
//
// If not within a traction then raise execption
//
if (!_transactionNestingLevel) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to commit a transaction without beginning one", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// If already fetching then raise exception
//
if (_fetchesInProgress) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to commit a transaction while a fetch was in progress", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// Notify the delegate
//
if (_delegateRespondsTo.shouldCommit) {
if(![_delegate adaptorContextShouldCommit:self])
return;
}
//
// Commit the transaction
//
result = SQLTransact(SQL_NULL_HENV, _odbcDatabaseConnection, SQL_COMMIT);
if ( result != SQL_SUCCESS ) {
[self odbcErrorWithChannel:nil string:@"SQLTransact in -[ODBCContext commitTransaction]" raise: (result != SQL_SUCCESS_WITH_INFO)];
}
[self transactionDidCommit];
//
// Notify the delegate
//
if (_delegateRespondsTo.didCommit)
[_delegate adaptorContextDidCommit:self];
}
- (void)rollbackTransaction
{
RETCODE result;
//
// If not within transaction then raise exception
//
if (!_transactionNestingLevel) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to rollback a transaction without beginning one", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];
}
//
// If already fetching the raise exception
//
if (_fetchesInProgress) {
[NSException raise:NSInternalInconsistencyException format:@"%@ -- %@ 0x%x: attempted to rollback a transaction while a fetch was in progress", NSStringFromSelector(_cmd), NSStringFromClass([self class]), self];