コード例 #1
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public static bool ExecuteReader(string cmd, DBReaderDelegate func, Transaction trans)
 {
     return(new Command(cmd).ExecuteReader(func, trans));
 }
コード例 #2
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public bool ExecuteReader(DBReaderDelegate func)
 {
     return(this.ExecuteReader(func, null as Transaction));
 }
コード例 #3
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public static bool ExecuteReader(string cmd, DBReaderDelegate func)
 {
     return(new Command(cmd).ExecuteReader(func));
 }
コード例 #4
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
                }
            }
        }
コード例 #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 static bool ExecuteReader(string cmd, DBReaderDelegate func)
 {
     return new Command(cmd).ExecuteReader(func);
 }
コード例 #7
0
ファイル: Command.cs プロジェクト: burstinair/burst.net
 public bool ExecuteReader(DBReaderDelegate func)
 {
     return this.ExecuteReader(func, null as Transaction);
 }
コード例 #8
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
                }
            }
        }