protected override void Dispose(bool disposing) { if (mDisposed) { return; } if (disposing) { // give up references to transaction and connection mTransaction = null; mConn = null; } base.Dispose(disposing); mDisposed = true; }
// // Summary: // Starts a database transaction with the specified isolation level. // // Parameters: // isolationLevel: // Specifies the isolation level for the transaction. // // Returns: // An object representing the new transaction. public new PqsqlTransaction BeginTransaction(IsolationLevel isolationLevel) { #if CODECONTRACTS Contract.Requires <ArgumentException>(isolationLevel != IsolationLevel.Chaos); Contract.Ensures(Contract.Result <PqsqlTransaction>() != null); #else if (isolationLevel == IsolationLevel.Chaos) { throw new ArgumentException("isolationLevel == IsolationLevel.Chaos"); } #endif if (mConnection == IntPtr.Zero) { Open(); } PqsqlTransaction t = null; PqsqlTransaction txn; try { t = new PqsqlTransaction(this, isolationLevel); // get transaction start command byte[] txnString = t.TransactionStart; ExecStatusType s = Exec(txnString); if (s != ExecStatusType.PGRES_COMMAND_OK) { string err = GetErrorMessage(); throw new PqsqlException("Transaction start failed: " + err); } // swap t with txn txn = t; t = null; } finally { t?.Dispose(); // only dispose PqsqlTransaction if s != ExecStatusType.PGRES_COMMAND_OK } return(txn); }