internal void _beginTransaction(Transaction transaction) { _transactions.Add(transaction); }
internal void _endTransaction(Transaction transaction) { _transactions.Remove(transaction); if (_transactions.Count == 0) try { _oriConnection.Close(); Status = ConnectionStatus.Closed; } catch { } }
public static int ExecuteNonQuery(this IEnumerable<Command> cmds, Transaction trans) { Debug.Assert(cmds != null, "IEnumerable<Command>.ExecuteNonQuery: cmds Cannot be NULL"); if (cmds == null) return -1; DbConnection conn = null; DbTransaction _trans = null; Command _cmd = null; try { if (trans != null) { conn = trans.CurrentConnection.OriConnection; _trans = trans.CurrentTransaction; } else { conn = DbProvider.Current.CreateConnection(); conn.Open(); _trans = conn.BeginTransaction(); } int res = 0; foreach (Command cmd in cmds) { _cmd = cmd; res = cmd.AsCommonCommand(conn, _trans).ExecuteNonQuery(); } if (trans == null) _trans.Commit(); return res; } catch (Exception e) { #if DEBUG CommandException ce = new CommandException("ExecuteNonQuery", _cmd, e); Debug.WriteLine(ce); throw ce; #endif try { if (trans == null) trans.Rollback(); else trans.success = false; } catch (Exception ex) { #if DEBUG CommandException ce2 = new CommandException("ExecuteNonQuery", _cmd, ex); Debug.WriteLine(ce2); throw ce2; #endif } return -1; } finally { try { if (trans == null) conn.Close(); } catch (Exception e) { #if DEBUG CommandException ce = new CommandException("ExecuteNonQuery", _cmd, e); Debug.WriteLine(ce); throw ce; #endif } } }
public Transaction BeginTransaction() { Debug.Assert(Status == ConnectionStatus.Opend, "Connection.BeginTransaction: Status must be Opened."); if (Status == ConnectionStatus.Opend) { Transaction res = new Transaction(); res.Begin(this); return res; } return null; }
public static bool ExecuteReader(string cmd, DBReaderDelegate func, Transaction trans) { return new Command(cmd).ExecuteReader(func, trans); }
public int ExecuteNonQuery(Transaction trans) { DbConnection conn = null; bool err = false; try { DbCommand cmd; if (trans != null) cmd = this.AsCommonCommand(trans.CurrentConnection.OriConnection, trans.CurrentTransaction); else { conn = DbProvider.Current.CreateConnection(); conn.Open(); cmd = this.AsCommonCommand(conn, null); } return cmd.ExecuteNonQuery(); } catch (Exception e) { err = true; if (trans != null) trans.success = false; #if DEBUG CommandException ce = new CommandException("ExecuteNonQuery", this, e); Debug.WriteLine(ce); throw ce; #endif return -1; } finally { try { if (trans == null) conn.Close(); } catch (Exception e) { if (trans != null) trans.success = false; #if DEBUG if (!err) { CommandException ce = new CommandException("ExecuteNonQuery", this, e); Debug.WriteLine(ce); throw ce; } #endif } } }
public static Object ExecuteScalar(string cmd, Transaction trans) { return new Command(cmd).ExecuteScalar(trans); }
public static NameValueList[] Execute(Transaction trans, string cmd) { return new Command(cmd).Execute(trans); }
public static int ExecuteNonQuery(Transaction trans, params string[] cmds) { List<Command> commands = new List<Command>(); foreach (string cmd in cmds) commands.Add(new Command(cmd)); return commands.ExecuteNonQuery(trans); }
public bool ExecuteReader(DBReaderDelegate func, Transaction trans) { Debug.Assert(func != null, "DBReaderDelegate Cannot be NULL"); DbConnection conn = null; DbDataReader r = null; bool err = false; try { DbCommand cmd; if (trans != null) cmd = this.AsCommonCommand(trans.CurrentConnection.OriConnection, trans.CurrentTransaction); else { conn = DbProvider.Current.CreateConnection(); conn.Open(); cmd = this.AsCommonCommand(conn, null); } r = cmd.ExecuteReader(); while (r.Read() && func(r)) ; return true; } catch (Exception e) { err = true; if (trans != null) trans.success = false; #if DEBUG CommandException ce = new CommandException("ExecuteReader", this, e); Debug.WriteLine(ce); throw ce; #endif return false; } finally { try { r.Close(); } catch (Exception e) { if (trans != null) trans.success = false; #if DEBUG if (!err) { CommandException ce = new CommandException("ExecuteReader", this, e); Debug.WriteLine(ce); throw ce; } #endif } try { if (trans == null) conn.Close(); } catch (Exception e) { if (trans != null) trans.success = false; #if DEBUG if (!err) { CommandException ce = new CommandException("ExecuteReader", this, e); Debug.WriteLine(ce); throw ce; } #endif } } }
public NameValueList[] Execute(Transaction trans) { DbConnection conn = null; DbDataReader r = null; bool err = false; try { DbCommand cmd; if (trans != null) cmd = this.AsCommonCommand(trans.CurrentConnection.OriConnection, trans.CurrentTransaction); else { conn = DbProvider.Current.CreateConnection(); conn.Open(); cmd = this.AsCommonCommand(conn, null); } r = cmd.ExecuteReader(); List<NameValueList> res = new List<NameValueList>(); List<string> keys = new List<string>(); while (r.Read()) { NameValueList data = new NameValueList(); for (int i = 0; i < r.FieldCount; i++) { if (res.Count == 0) keys.Add(r.GetName(i)); data.Add(keys[i], r.GetValue(i)); } res.Add(data); } r.Close(); return res.ToArray(); } catch (Exception e) { err = true; if (trans != null) trans.success = false; #if DEBUG CommandException ce = new CommandException("Execute", this, e); Debug.WriteLine(ce); throw ce; #endif return new NameValueList[] { }; } finally { try { r.Close(); } catch (Exception e) { if (trans != null) trans.success = false; #if DEBUG if (!err) { CommandException ce = new CommandException("Execute", this, e); Debug.WriteLine(ce); throw ce; } #endif } try { if (trans == null) conn.Close(); } catch (Exception e) { if (trans != null) trans.success = false; #if DEBUG if (!err) { CommandException ce = new CommandException("Execute", this, e); Debug.WriteLine(ce); throw ce; } #endif } } }