Пример #1
0
        public int ExecuteCommands()
        {
            DatabaseReturn return2 = this.dbes.Execute(this._iDbCommandList);

            if (return2.ReturnException != null)
            {
                throw new DBException(return2.ErrorSQL, return2.ReturnException);
            }
            return(return2.EffectRowCount);
        }
Пример #2
0
        public string IsExecuteVaild(string sql)
        {
            DatabaseReturn return2 = this.dbes.Execute(sql);

            if (return2.ReturnException == null)
            {
                return(null);
            }
            return(return2.ReturnException.Message.Replace("沒有資料被影響異動。", "").Replace("没有数据被影响异动。", "").Replace("No data is affecting changes.", ""));
        }
Пример #3
0
        public int Execute(string sql, List <IDbDataParameter> parameters, bool showErrorSQL)
        {
            DatabaseReturn return2 = this.dbes.Execute(sql, parameters);

            if (return2.ReturnException != null)
            {
                throw new Exception(this.GetAllInnerExceptionString(return2.ErrorSQL, return2.ReturnException));
            }
            return(return2.EffectRowCount);
        }
Пример #4
0
        public int ExecuteCommandAtOnce(List <IDbCommand> commands)
        {
            DatabaseReturn return2 = this.dbes.ExecuteCommandAtOnce(commands);

            if (return2.ReturnException != null)
            {
                throw new Exception(this.GetAllInnerExceptionString(return2.ErrorSQL, return2.ReturnException));
            }
            return(return2.EffectRowCount);
        }
Пример #5
0
        public int DoTransaction(List <IDbCommand> commands, IDbTransaction transaction)
        {
            DatabaseReturn return2 = this.dbes.Execute(commands, transaction);

            if (return2.ReturnException != null)
            {
                throw new Exception(this.GetAllInnerExceptionString(return2.ErrorSQL, return2.ReturnException));
            }
            return(return2.EffectRowCount);
        }
Пример #6
0
        public int DoTransaction(string[] sqls)
        {
            DatabaseReturn return2 = this.dbes.Execute(sqls);

            if (return2.ReturnException != null)
            {
                throw new Exception(this.GetAllInnerExceptionString(return2.ErrorSQL, return2.ReturnException));
            }
            return(return2.EffectRowCount);
        }
Пример #7
0
        public DatabaseReturn Execute(List <IDbCommand> commandList)
        {
            this.errorSQL = "";
            this.count    = 0;
            if ((this.connString == null) || (this.conn == null))
            {
                throw new Exception(Message.NoConnection);
            }
            DatabaseReturn return2     = new DatabaseReturn();
            IDbTransaction transaction = this.conn.BeginTransaction();

            if ((commandList != null) && (commandList.Count != 0))
            {
                try
                {
                    foreach (IDbCommand command in commandList)
                    {
                        if ((command != null) && !(command.CommandText == ""))
                        {
                            this.errorSQL       = command.CommandText;
                            command.Connection  = this.conn;
                            command.Transaction = transaction;
                            this.count          = command.ExecuteNonQuery();
                            if (this.count <= 0)
                            {
                                throw new Exception(Message.NoRowEffected);
                            }
                            return2.EffectRowCount += this.count;
                        }
                    }
                    this.errorSQL = "";
                    transaction.Commit();
                    return2.ReturnException = null;
                }
                catch (Exception exception)
                {
                    transaction.Rollback();
                    return2.EffectRowCount  = 0;
                    return2.ReturnException = exception;
                    return2.ErrorSQL        = this.errorSQL;
                }
            }
            return(return2);
        }
Пример #8
0
        public DatabaseReturn Execute(string sql, List <IDbDataParameter> parameterList)
        {
            this.errorSQL = "";
            if ((this.connString == null) || (this.conn == null))
            {
                throw new Exception(Message.NoConnection);
            }
            DatabaseReturn return2 = new DatabaseReturn();
            IDbCommand     command = this.conn.CreateCommand();

            command.CommandText = sql;
            try
            {
                command.Parameters.Clear();
                if ((parameterList != null) && (parameterList.Count != 0))
                {
                    foreach (IDbDataParameter parameter in parameterList)
                    {
                        command.Parameters.Add(parameter);
                    }
                }
                return2.EffectRowCount = command.ExecuteNonQuery();
                if (return2.EffectRowCount <= 0)
                {
                    throw new Exception(Message.NoRowEffected);
                }
                return2.ReturnException = null;
            }
            catch (Exception exception)
            {
                this.errorSQL           = command.CommandText;
                return2.EffectRowCount  = 0;
                return2.ReturnException = exception;
                return2.ErrorSQL        = this.errorSQL;
            }
            finally
            {
                command.Dispose();
                command = null;
            }
            return(return2);
        }
Пример #9
0
        public DatabaseReturn Execute(string[] sqls)
        {
            this.errorSQL = "";
            this.count    = 0;
            if ((this.connString == null) || (this.conn == null))
            {
                throw new Exception(Message.NoConnection);
            }
            DatabaseReturn return2     = new DatabaseReturn();
            IDbTransaction transaction = this.conn.BeginTransaction();
            IDbCommand     command     = this.conn.CreateCommand();

            command.Transaction = transaction;
            try
            {
                foreach (string str in sqls)
                {
                    if (str.Trim() != "")
                    {
                        this.errorSQL       = str;
                        command.CommandText = str;
                        this.count          = command.ExecuteNonQuery();
                        if (this.count <= 0)
                        {
                            throw new Exception(Message.NoRowEffected);
                        }
                        return2.EffectRowCount += this.count;
                    }
                }
                this.errorSQL = "";
                transaction.Commit();
                return2.ReturnException = null;
            }
            catch (Exception exception)
            {
                transaction.Rollback();
                return2.EffectRowCount  = 0;
                return2.ReturnException = exception;
                return2.ErrorSQL        = this.errorSQL;
            }
            return(return2);
        }