示例#1
0
        public List <object> ExecuteGoQuery(string query, bool noTransaction = true, DBExecuteType type = DBExecuteType.Scalar)
        {
            var result = new List <object>();

            foreach (var go in SplitGoQuery(query))
            {
                result.Add(ExecuteQuery(go, noTransaction, type));
            }
            return(result);
        }
示例#2
0
        internal void OnExecute(DBExecuteType type, string text, TimeSpan ms, object rez)
        {
            if (rez is Exception ex)
            {
                Helper.Logs.Add(new StateInfo("Transaction", ex.Message, text, StatusType.Warning));
            }

            Execute?.Invoke(new DBExecuteEventArg {
                Time = ms, Query = text, Type = type, Rezult = rez
            });
        }
示例#3
0
 public object ExecuteQuery(string query, bool noTransaction = false, DBExecuteType type = DBExecuteType.Scalar)
 {
     if (string.IsNullOrEmpty(query))
     {
         return(null);
     }
     using (var transaction = new DBTransaction(this, null, noTransaction))
     {
         var result = transaction.ExecuteQuery(transaction.AddCommand(query), type);
         transaction.Commit();
         return(result);
     }
 }
示例#4
0
        public override async Task <object> ExecuteQueryAsync(IDbCommand command, DBExecuteType type, CommandBehavior behavior)
        {
            var npgsqlCommand = (NpgsqlCommand)command;

            switch (type)
            {
            case DBExecuteType.Scalar:
                return(await npgsqlCommand.ExecuteScalarAsync());

            case DBExecuteType.Reader:
                return(await npgsqlCommand.ExecuteReaderAsync(behavior));

            case DBExecuteType.NoReader:
                return(await npgsqlCommand.ExecuteNonQueryAsync());
            }
            return(null);
        }
示例#5
0
        public object ExecuteQuery(IDbCommand command, DBExecuteType type = DBExecuteType.Scalar, CommandBehavior behavior = CommandBehavior.Default)
        {
            object buf   = null;
            var    watch = new Stopwatch();

            try
            {
                //Debug.WriteLine(command.Connection.ConnectionString);
                //Debug.WriteLine(command.CommandText);
                watch.Start();
                switch (type)
                {
                case DBExecuteType.Scalar:
                    buf = command.ExecuteScalar();
                    break;

                case DBExecuteType.Reader:
                    buf = command.ExecuteReader(behavior);
                    break;

                case DBExecuteType.NoReader:
                    buf = command.ExecuteNonQuery();
                    break;
                }

                watch.Stop();
            }
            catch (Exception ex)
            {
                Rollback();
                buf = ex;
            }
            finally
            {
                OnExecute(type, command.CommandText, watch.Elapsed, buf);
                if (buf is Exception)
                {
                    throw (Exception)buf;
                }
            }
            return(buf);
        }
示例#6
0
 public object ExecuteQuery(string commandText, DBExecuteType type = DBExecuteType.Scalar)
 {
     return(ExecuteQuery(AddCommand(commandText), type));
 }
示例#7
0
 public object ExecuteQuery(DBExecuteType type = DBExecuteType.Scalar)
 {
     return(ExecuteQuery(Command, type));
 }
示例#8
0
 public override Task <object> ExecuteQueryAsync(IDbCommand command, DBExecuteType type, CommandBehavior behavior)
 {
     throw new NotImplementedException();
 }