コード例 #1
0
ファイル: Connection.cs プロジェクト: burstinair/burst.net
 internal void _beginTransaction(Transaction transaction)
 {
     _transactions.Add(transaction);
 }
コード例 #2
0
ファイル: Connection.cs プロジェクト: burstinair/burst.net
 internal void _endTransaction(Transaction transaction)
 {
     _transactions.Remove(transaction);
     if (_transactions.Count == 0)
         try
         {
             _oriConnection.Close();
             Status = ConnectionStatus.Closed;
         }
         catch { }
 }
コード例 #3
0
ファイル: Extension.cs プロジェクト: burstinair/burst.net
 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
         }
     }
 }
コード例 #4
0
ファイル: Connection.cs プロジェクト: burstinair/burst.net
 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;
 }
コード例 #5
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public static bool ExecuteReader(string cmd, DBReaderDelegate func, Transaction trans)
 {
     return new Command(cmd).ExecuteReader(func, trans);
 }
コード例 #6
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
        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
                }
            }
        }
コード例 #7
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public static Object ExecuteScalar(string cmd, Transaction trans)
 {
     return new Command(cmd).ExecuteScalar(trans);
 }
コード例 #8
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public static NameValueList[] Execute(Transaction trans, string cmd)
 {
     return new Command(cmd).Execute(trans);
 }
コード例 #9
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 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);
 }
コード例 #10
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
        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
                }
            }
        }
コード例 #11
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
        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
                }
            }
        }