// Set Auto-commit (102) connection attribute // [MonoTODO]: nice to have before svn: define libodbc.SQL_IS_UINTEGER = -5 private static void SetAutoCommit(OdbcConnection conn, bool isAuto) { OdbcReturn ret = libodbc.SQLSetConnectAttr(conn.hDbc, OdbcConnectionAttribute.AutoCommit, (IntPtr)(isAuto ? 1 : 0), -5); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) { throw conn.CreateOdbcException(OdbcHandleType.Dbc, conn.hDbc); } }
private static IsolationLevel GetIsolationLevel(OdbcConnection conn) { int lev; int length; OdbcReturn ret = libodbc.SQLGetConnectAttr(conn.hDbc, OdbcConnectionAttribute.TransactionIsolation, out lev, 0, out length); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) { throw conn.CreateOdbcException(OdbcHandleType.Dbc, conn.hDbc); } return(MapOdbcIsolationLevel((OdbcIsolationLevel)lev)); }
void Commit() { if (!isOpen) { throw ExceptionHelper.TransactionNotUsable(GetType()); } if (connection.transaction == this) { OdbcReturn ret = libodbc.SQLEndTran((short)OdbcHandleType.Dbc, connection.hDbc, 0); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) { throw connection.CreateOdbcException(OdbcHandleType.Dbc, connection.hDbc); } SetAutoCommit(connection, true); // restore default auto-commit connection.transaction = null; connection = null; isOpen = false; } else { throw new InvalidOperationException(); } }
void Cancel() { if (hstmt != IntPtr.Zero) { OdbcReturn Ret = libodbc.SQLCancel(hstmt); if (Ret != OdbcReturn.Success && Ret != OdbcReturn.SuccessWithInfo) { throw connection.CreateOdbcException(OdbcHandleType.Stmt, hstmt); } } else { throw new InvalidOperationException(); } }
internal OdbcTransaction (OdbcConnection conn, IsolationLevel isolationlevel) { // Set Auto-commit (102) to false SetAutoCommit (conn, false); // Handle isolation level OdbcIsolationLevel lev = OdbcIsolationLevel.ReadCommitted; OdbcConnectionAttribute attr = OdbcConnectionAttribute.TransactionIsolation; switch (isolationlevel) { case IsolationLevel.ReadUncommitted: lev = OdbcIsolationLevel.ReadUncommitted; break; case IsolationLevel.ReadCommitted: lev = OdbcIsolationLevel.ReadCommitted; break; case IsolationLevel.RepeatableRead: lev = OdbcIsolationLevel.RepeatableRead; break; case IsolationLevel.Serializable: lev = OdbcIsolationLevel.Serializable; break; case IsolationLevel.Snapshot: // badly broken on MS: // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=305736 lev = OdbcIsolationLevel.Snapshot; // SQL_ATTR_TXN_ISOLATION can be used to set all other isolation // levels except for SQL_TXN_SS_SNAPSHOT. If you want to use snapshot // isolation, you must set SQL_TXN_SS_SNAPSHOT through // SQL_COPT_SS_TXN_ISOLATION. However, you can retrieve the // isolation level by using either SQL_ATTR_TXN_ISOLATION or // SQL_COPT_SS_TXN_ISOLATION. // Source: // http://msdn2.microsoft.com/en-us/library/ms131709.aspx attr = OdbcConnectionAttribute.CoptTransactionIsolation; break; case IsolationLevel.Unspecified: // when isolationlevel is not specified, then use // default isolation level of the driver and // lazy initialize it in the IsolationLevel property break; case IsolationLevel.Chaos: throw new ArgumentOutOfRangeException ("IsolationLevel", string.Format (CultureInfo.CurrentCulture, "The IsolationLevel enumeration " + "value, {0}, is not supported by " + "the .Net Framework Odbc Data " + "Provider.", (int) isolationlevel)); default: throw new ArgumentOutOfRangeException ("IsolationLevel", string.Format (CultureInfo.CurrentCulture, "The IsolationLevel enumeration value, {0}, is invalid.", (int) isolationlevel)); } // only change isolation level if it was explictly set if (isolationlevel != IsolationLevel.Unspecified) { // mbd: Getting the return code of the second call to SQLSetConnectAttr is missing from original code! OdbcReturn ret = libodbc.SQLSetConnectAttr (conn.hDbc, attr, (IntPtr) lev, 0); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) throw conn.CreateOdbcException (OdbcHandleType.Dbc, conn.hDbc); } this.isolationlevel = isolationlevel; connection = conn; isOpen = true; }
private static IsolationLevel GetIsolationLevel (OdbcConnection conn) { int lev; int length; OdbcReturn ret = libodbc.SQLGetConnectAttr (conn.hDbc, OdbcConnectionAttribute.TransactionIsolation, out lev, 0, out length); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) throw conn.CreateOdbcException (OdbcHandleType.Dbc, conn.hDbc); return MapOdbcIsolationLevel ((OdbcIsolationLevel) lev); }
// Set Auto-commit (102) connection attribute // [MonoTODO]: nice to have before svn: define libodbc.SQL_IS_UINTEGER = -5 private static void SetAutoCommit (OdbcConnection conn, bool isAuto) { OdbcReturn ret = libodbc.SQLSetConnectAttr (conn.hDbc, OdbcConnectionAttribute.AutoCommit, (IntPtr) (isAuto ? 1 : 0), -5); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) throw conn.CreateOdbcException (OdbcHandleType.Dbc, conn.hDbc); }
internal OdbcTransaction(OdbcConnection conn, IsolationLevel isolationlevel) { // Set Auto-commit (102) to false SetAutoCommit(conn, false); // Handle isolation level OdbcIsolationLevel lev = OdbcIsolationLevel.ReadCommitted; OdbcConnectionAttribute attr = OdbcConnectionAttribute.TransactionIsolation; switch (isolationlevel) { case IsolationLevel.ReadUncommitted: lev = OdbcIsolationLevel.ReadUncommitted; break; case IsolationLevel.ReadCommitted: lev = OdbcIsolationLevel.ReadCommitted; break; case IsolationLevel.RepeatableRead: lev = OdbcIsolationLevel.RepeatableRead; break; case IsolationLevel.Serializable: lev = OdbcIsolationLevel.Serializable; break; case IsolationLevel.Snapshot: // badly broken on MS: // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=305736 lev = OdbcIsolationLevel.Snapshot; // SQL_ATTR_TXN_ISOLATION can be used to set all other isolation // levels except for SQL_TXN_SS_SNAPSHOT. If you want to use snapshot // isolation, you must set SQL_TXN_SS_SNAPSHOT through // SQL_COPT_SS_TXN_ISOLATION. However, you can retrieve the // isolation level by using either SQL_ATTR_TXN_ISOLATION or // SQL_COPT_SS_TXN_ISOLATION. // Source: // http://msdn2.microsoft.com/en-us/library/ms131709.aspx attr = OdbcConnectionAttribute.CoptTransactionIsolation; break; case IsolationLevel.Unspecified: // when isolationlevel is not specified, then use // default isolation level of the driver and // lazy initialize it in the IsolationLevel property break; case IsolationLevel.Chaos: throw new ArgumentOutOfRangeException("IsolationLevel", string.Format(CultureInfo.CurrentCulture, "The IsolationLevel enumeration " + "value, {0}, is not supported by " + "the .Net Framework Odbc Data " + "Provider.", (int)isolationlevel)); default: throw new ArgumentOutOfRangeException("IsolationLevel", string.Format(CultureInfo.CurrentCulture, "The IsolationLevel enumeration value, {0}, is invalid.", (int)isolationlevel)); } // only change isolation level if it was explictly set if (isolationlevel != IsolationLevel.Unspecified) { // mbd: Getting the return code of the second call to SQLSetConnectAttr is missing from original code! OdbcReturn ret = libodbc.SQLSetConnectAttr(conn.hDbc, attr, (IntPtr)lev, 0); if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo) { throw conn.CreateOdbcException(OdbcHandleType.Dbc, conn.hDbc); } } this.isolationlevel = isolationlevel; connection = conn; isOpen = true; }