示例#1
0
        public static IEnumerable <object[]> ExecMulti(this ISqlProc proc, SqlDataReader dataReader,
                                                       IDataMapHelper <object[]> mapper,
                                                       Action <SqlDataReader, SqlField[]> onReadFields = null,
                                                       Action <double> progress = null)
        {
            var helper = mapper;

            helper.GetProperties(dataReader);

            if (onReadFields != null)
            {
                onReadFields(dataReader, helper.GetFields(dataReader));
            }

            do
            {
                object[] objVal = helper.DbRecordArray();
                dataReader.GetValues(objVal);

                object[] val = helper.SetValues(objVal);
                yield return(val);
            }while (dataReader.Read());

            if (progress != null)
            {
                progress(1.0);
            }
        }
示例#2
0
        // in T
        public static bool ExecFill <T>(this ISqlProc proc, IList <T> list,
                                        IDataMapHelper <T> mapper,
                                        Action <double> progress = null) where T : class // , TMap : IDataMapHelper
        {
            Ai.Guard.Check(proc.Connection != null, "proc.Connection null error in ExecFill");
            Ai.Guard.Check(list != null, "list null error in ExecFill");
            if (proc.Connection.State != ConnectionState.Open)
            {
                proc.Connection.Open();
            }

            using (var command = proc.CreateCommand())
            {
                if (progress != null)
                {
                    progress(0.0);
                }

                using (SqlDataReader dataReader = command.ExecuteReader())
                {
                    var results = list as IList <T>;
                    if (!dataReader.Read())
                    {
                        if (progress != null)
                        {
                            progress(1.0);
                        }
                        return(false);
                    }

                    // Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellationToken);
                    var helper = mapper; //  new DbDataMapHelper<T>();
                    helper.GetProperties(dataReader);

                    do
                    {
                        object[] objVal = helper.DbRecordArray();
                        // int ret =
                        dataReader.GetValues(objVal);
                        T val = helper.SetValues(objVal);
                        results.Add(val);
                    }while (dataReader.Read());

                    if (progress != null)
                    {
                        progress(1.0);
                    }

                    return(true);
                }
            }
        }
示例#3
0
        public MultiResult <T> Prepare(SqlProc proc
                                       , Action <SqlCommand> setup        = null
                                       , Action <SqlField[]> onReadFields = null
                                       , bool noMoveFirst = false
                                       )
        {
            this.proc = proc;
            var mapper = new DbObject();

            numerator = DbEnumeratorData.GetEnumerator(() =>
            {
                this.reader = SqlMultiDyn.ExecMultiReader(proc, setup, progress: null);
                return(reader);
            });

            if (numerator == null)
            {
                return(null);
            }
            if (reader.IsClosed || reader.Depth != 0)
            {
                return(null);
            }

            if (noMoveFirst)
            {
                return(this);
            }

            numerator.MoveNext();
            var rec = numerator.Current as object[]; // DbDataRecord;

            mapHelper = mapper.GetProperties(reader);

            Fields      = reader.GetFields(); // SqlFieldArray
            FirstRecord = rec;
            // mapHelper.SetValues(mapHelper.DbRecordArray());
            return(this);
        }
示例#4
0
        public static IEnumerable <object[]> ExecEnumerable(this ISqlProc proc,
                                                            IDataMapHelper <object[]> mapper,
                                                            Action <double> progress = null, Action <SqlField[]> onReadFields = null)
        {
            Ai.Guard.Check(proc.Connection != null, "proc.Connection null error in ExecFill");

            using (SqlConnection connection = new SqlConnection(proc.ConnectionString()))
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                    if (connection.State != ConnectionState.Open)
                    {
                        yield break;
                    }
                }
                if (connection.Database != proc.DbName)
                {
                    connection.ChangeDatabase(proc.DbName);
                }

                using (var command = proc.CreateCommand())
                {
                    command.Connection = connection;

                    if (progress != null)
                    {
                        progress(0.0);
                    }

                    using (SqlDataReader dataReader = command.ExecuteReader())
                    {
                        if (!dataReader.Read())
                        {
                            if (progress != null)
                            {
                                progress(1.0);
                            }

                            yield break;
                        }

                        // Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellationToken);
                        var helper = mapper; //  new DbDataMapHelper<T>();
                        helper.GetProperties(dataReader);

                        if (onReadFields != null)
                        {
                            onReadFields(helper.GetFields(dataReader));
                        }

                        do
                        {
                            object[] objVal = helper.DbRecordArray();
                            dataReader.GetValues(objVal);

                            object[] val = helper.SetValues(objVal);
                            yield return(val);
                        }while (dataReader.Read());

                        if (progress != null)
                        {
                            progress(1.0);
                        }
                    }
                }
            }
        }
示例#5
0
 public bool ExecMap <T>(IList <T> list, IDataMapHelper <T> mapper,
                         Action <double> progress = null) where T : class
 {
     return(DbGetHelper.ExecFill <T>(this, list, mapper, progress));
 }