Exemplo n.º 1
0
        public void ExecuteReader()
        {
            var rs = DbExecutor.ExecuteReader(connectionFactory(),
                                              "select * from sqlite_master where type=@TypeId ", new { TypeId = "table" }).ToArray();

            rs.Length.Is(6);

            using (var exec = new DbExecutor(connectionFactory()))
            {
                //select name from sqlite_master where type='table';
                var ri = exec.ExecuteReader("select * from sqlite_master where type=@TypeId ", new { TypeId = "table" })
                         .Select(dr =>
                {
                    var x      = new SqliteMaster();
                    x.name     = (string)dr["name"];
                    x.rootpage = (int)dr["rootpage"];
                    x.sql      = (string)dr["sql"];
                    x.tbl_name = (string)dr["tbl_name"];
                    x.type     = (string)dr["type"];
                    return(x);
                })
                         .ToArray();
                ri.Length.Is(6);
                ri.Select(x => x.name).Is("employees", "departments", "dept_emp", "dept_manager", "titles", "salaries");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存类库中的视图
        /// </summary>
        /// <param name="type"></param>
        private void SaveViewSetting(Type type)
        {
            PlatformSource?platform = ViewUtils.GetPlatform(type);

            if (platform == null)
            {
                return;
            }
            ViewSetting setting = new ViewSetting()
            {
                Name     = type.Name,
                Platform = platform.Value,
                Code     = type.FullName,
                Status   = ViewSetting.ViewStatus.Normal
            };

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (setting.Exists(db, t => t.Code))
                {
                    setting = setting.Info(db, t => t.Code);
                }
                else
                {
                    setting.AddIdentity(db);
                }
                db.AddCallback(() =>
                {
                    ViewCaching.Instance().SaveViewID(setting.Code, setting.ID);
                });
                db.Commit();
            }
        }
Exemplo n.º 3
0
        public void SaveMarkTime(OrderTaskModel task, long time, byte mark = 0)
        {
            int?gameId = GameAgent.Instance().GetGameSetting(task)?.ID;

            if (gameId == null)
            {
                return;
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameMark>(t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type))
                {
                    db.Update <GameMark, long>(t => t.Time, time, t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type);
                }
                else
                {
                    new GameMark()
                    {
                        GameID = gameId.Value,
                        Mark   = mark,
                        Type   = task.Type,
                        Time   = time
                    }.Add(db);
                }
                db.Commit();
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            DbExecutor.Delete(connectionFactory(), "Departments", new { dept_no = "1" });
            DbExecutor.Insert(connectionFactory(), "Departments", new { dept_no = "1", dept_name = "name1" });

            using (var exec = new DbExecutor(connectionFactory(), IsolationLevel.ReadCommitted))
            {
                exec.Select <Departments>("select * from Departments where dept_no = 1")
                .First()
                .Is(x => x.dept_name == "name1");

                exec.Update("Departments", new { dept_name = "UpdateName" }, new { dept_no = 1 });

                exec.Select <Departments>("select * from Departments where dept_no = 1")
                .First()
                .Is(x => x.dept_name == "UpdateName");
            }

            DbExecutor.Select <Departments>(connectionFactory(), "select * from Departments where dept_no = 1")
            .First()
            .Is(x => x.dept_name == "name1");

            DbExecutor.Update(connectionFactory(), "Departments", new { dept_name = "UpdateName" }, new { dept_no = 1 });

            DbExecutor.Select <Departments>(connectionFactory(), "select * from Departments where dept_no = 1")
            .First()
            .Is(x => x.dept_name == "UpdateName");

            DbExecutor.Update(connectionFactory(), "Departments", new { dept_name = "Int32" }, new { dept_no = 1 });
        }
        public IEnumerable <string> GetPortNames(string dataType, string componentType)
        {
            var conditions = new List <string>();

            if (!string.IsNullOrEmpty(dataType) && dataType != "*")
            {
                conditions.Add("DataType = @DataType");
            }
            if (!string.IsNullOrEmpty(componentType) && componentType != "*")
            {
                conditions.Add("ComponentType = @ComponentType");
            }
            string condition = "";

            if (conditions.Count != 0)
            {
                condition = "where " + string.Join(" and ", conditions);
            }
            var portNames = DbExecutor.ExecuteReader(
                new SQLiteConnection(_connectionString),
                @"select distinct PortName from RecordDescriptions " + condition,
                new { DataType = dataType, ComponentType = componentType });

            return(portNames.Select(dr => (string)dr["PortName"])
                   .Concat(EnumerableEx.Return("*")));
        }
Exemplo n.º 6
0
        internal string[] GetCloumns(DbExecutor db, string tableName)
        {
            // 获取表结构
            var cols = db.GetDataTable(CommandType.Text, $"sp_columns [{tableName}]");

            return(new string[0]);
        }
Exemplo n.º 7
0
        public void ExecuteReaderDynamic()
        {
            var rs = DbExecutor.ExecuteReaderDynamic(connectionFactory(),
                                                     "select * from Methods where TypeId = @TypeId", new { TypeId = 2 })
                     .Select(d => new Method
            {
                Name     = d.Name,
                MethodId = d.MethodId,
            })
                     .ToArray();

            rs.Length.Is(3);
            rs.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains");

            using (var exec = new DbExecutor(connectionFactory()))
            {
                var ri = exec.ExecuteReaderDynamic("select * from Methods where TypeId = @TypeId", new { TypeId = 2 })
                         .Select(d => new Method
                {
                    Name     = d.Name,
                    MethodId = d.MethodId,
                })
                         .ToArray();
                ri.Length.Is(3);
                ri.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains");
            }
        }
Exemplo n.º 8
0
        public void ExecuteReader()
        {
            var rs = DbExecutor.ExecuteReader(connectionFactory(),
                                              "select * from Methods where TypeId = @TypeId", new { TypeId = 2 })
                     .Select(dr => new Method
            {
                Name     = (string)dr["Name"],
                MethodId = (int)dr["MethodId"],
            })
                     .ToArray();

            rs.Length.Is(3);
            rs.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains");

            using (var exec = new DbExecutor(connectionFactory()))
            {
                var ri = exec.ExecuteReader("select * from Methods where TypeId = @TypeId", new { TypeId = 2 })
                         .Select(dr => new Method
                {
                    Name     = (string)dr["Name"],
                    MethodId = (int)dr["MethodId"],
                })
                         .ToArray();
                ri.Length.Is(3);
                ri.Select(x => x.Name).Is("StartsWith", "EndsWith", "Contains");
            }
        }
Exemplo n.º 9
0
        public void Update()
        {
            using (var exec = new DbExecutor(connectionFactory(), IsolationLevel.ReadCommitted))
            {
                exec.Select <Type>("select * from Types where TypeId = 1")
                .First()
                .Is(x => x.Name == "Int32");

                exec.Update("Types", new { Name = "UpdateName" }, new { TypeId = 1 });

                exec.Select <Type>("select * from Types where TypeId = 1")
                .First()
                .Is(x => x.Name == "UpdateName");
            }

            DbExecutor.Select <Type>(connectionFactory(), "select * from Types where TypeId = 1")
            .First()
            .Is(x => x.Name == "Int32");

            DbExecutor.Update(connectionFactory(), "Types", new { Name = "UpdateName" }, new { TypeId = 1 });

            DbExecutor.Select <Type>(connectionFactory(), "select * from Types where TypeId = 1")
            .First()
            .Is(x => x.Name == "UpdateName");

            DbExecutor.Update(connectionFactory(), "Types", new { Name = "Int32" }, new { TypeId = 1 });
        }
Exemplo n.º 10
0
        /// <summary>
        /// 保存资料
        /// </summary>
        public bool SaveDetail(SiteDetail detail)
        {
            if (!string.IsNullOrEmpty(detail.Mobile) && !WebAgent.IsMobile(detail.Mobile))
            {
                return(this.FaildMessage("手机号码错误"));
            }
            if (!string.IsNullOrEmpty(detail.Email) && !WebAgent.IsEMail(detail.Email))
            {
                return(this.FaildMessage("邮箱错误"));
            }

            //存在就修改,否则就插入
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (detail.Exists(db))
                {
                    detail.Update(db, t => t.Mobile, t => t.Email);
                }
                else
                {
                    detail.Add(db);
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Site, $"修改商户资料"));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 保存系统参数配置
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SaveSetting(SystemSetting.SettingType type, string value)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                SystemSetting setting = new SystemSetting()
                {
                    Type  = type,
                    Value = value
                };
                if (setting.Exists(db))
                {
                    setting.Update(db);
                }
                else
                {
                    setting.Add(db);
                }

                db.AddCallback(() =>
                {
                    SystemCaching.Instance().SaveSetting(type, value);
                });

                db.Commit();
            }
            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 从存储过程获取DataSet
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static DataSet GetDataSet <T>(this DbExecutor db, T obj) where T : IProcedureModel
        {
            DataSet ds = db.GetDataSet(CommandType.StoredProcedure, typeof(T).Name,
                                       obj.ToDbParameter());

            obj.Fill();
            return(ds);
        }
Exemplo n.º 13
0
 /// <summary>
 ///     插入数据
 /// </summary>
 /// <param name="db">可传入事务的db</param>
 /// <param name="identity">标识,刚插入的ID</param>
 public static bool Insert <TInfo>(this TInfo info, out int identity, DbExecutor db = null) where TInfo : ModelInfo, new()
 {
     if ((new TInfo()) is BaseCacheModel <TInfo> )
     {
         return(BaseCacheModel <TInfo> .Data.Insert(info, out identity, db));
     }
     return(BaseModel <TInfo> .Data.Insert(info, out identity, db));
 }
Exemplo n.º 14
0
 /// <summary>
 ///     更改实体类
 /// </summary>
 /// <param name="db">可传入事务的db</param>
 /// <param name="ID">条件,等同于:o=>o.ID == ID 的操作</param>
 public static bool Update <TInfo>(this TInfo info, int?ID, DbExecutor db = null) where TInfo : ModelInfo, new()
 {
     if ((new TInfo()) is BaseCacheModel <TInfo> )
     {
         return(BaseCacheModel <TInfo> .Data.Where(o => o.ID == ID).Update(info, db));
     }
     return(BaseModel <TInfo> .Data.Where(o => o.ID == ID).Update(info, db));
 }
Exemplo n.º 15
0
 /// <summary>
 ///     更改实体类
 /// </summary>
 /// <param name="db">可传入事务的db</param>
 /// <param name="IDs">条件,等同于:o=> IDs.Contains(o.ID) 的操作</param>
 public static bool Update <TInfo>(this TInfo info, List <int> IDs, DbExecutor db = null) where TInfo : ModelInfo, new()
 {
     if ((new TInfo()) is BaseCacheModel <TInfo> )
     {
         return(BaseCacheModel <TInfo> .Data.Where(o => IDs.Contains(o.ID)).Update(info, db));
     }
     return(BaseModel <TInfo> .Data.Where(o => IDs.Contains(o.ID)).Update(info, db));
 }
Exemplo n.º 16
0
        /// <summary>
        /// 执行存储过程,返回受影响的行数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="db"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery <T>(this DbExecutor db, T obj) where T : IProcedureModel
        {
            int rows = db.ExecuteNonQuery(CommandType.StoredProcedure, typeof(T).Name,
                                          obj.ToParameters());

            obj.Fill();
            return(rows);
        }
Exemplo n.º 17
0
 public IndexModel(
     UserManager <ThoughtDesignUser> userManager,
     SignInManager <ThoughtDesignUser> signInManager,
     DbExecutor db)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _db            = db;
 }
Exemplo n.º 18
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        protected override bool HasUpdatedOnce()
        {
            var cmd = InitCommand(
                "select table_name from INFORMATION_SCHEMA.TABLES where table_name = 'meta' and table_schema='qorpent'",
                DbCallNotation.Scalar);
            var table_name = DbExecutor.GetResultSync(cmd);

            return(null != table_name);
        }
Exemplo n.º 19
0
 /// <summary>
 /// 事务
 /// </summary>
 /// <param name="database">数据库执行</param>
 /// <param name="tableName">表名称</param>
 public ViewContext(DbExecutor database, string tableName = null) : base(database, tableName)
 {
     if (string.IsNullOrWhiteSpace(tableName))
     {
         Name = TableMapCache.GetMap <TEntity>().ClassInfo.Name;
     }
     ViewSet = new ViewSet <TEntity>(this);
     Query   = DbFactory.CreateQueryView(this);
 }
Exemplo n.º 20
0
 /// <summary>
 /// 修改状态
 /// </summary>
 /// <param name="setting"></param>
 /// <returns></returns>
 public bool UpdateStatus(GameSetting setting)
 {
     using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
     {
         setting.Update(db, t => t.Status, t => t.MaintainTime);
         db.Commit();
     }
     return(this.AccountInfo.Log(LogType.Setting, $"修改开启状态:{setting.Name}"));
 }
Exemplo n.º 21
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        protected override bool HasUpdatedOnce()
        {
            var cmd = InitCommand(
                "select database_id from sys.databases where name = @database",
                DbCallNotation.Scalar);
            var id = DbExecutor.GetResultSync(cmd);

            return(null != id);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 添加域名
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domain">根域名</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomain(int siteId, string domain, string[] subName, CDNProviderType provider)
        {
            domain = WebAgent.GetTopDomain(domain);
            if (string.IsNullOrEmpty(domain))
            {
                return(this.FaildMessage("域名错误"));
            }
            if (this.ReadDB.Exists <SiteDomain>(t => t.Domain == domain))
            {
                return(this.FaildMessage("域名已被添加"));
            }
            foreach (string name in subName)
            {
                if (!Regex.IsMatch(name, @"^@$|^\*$|^\w+$"))
                {
                    return(this.FaildMessage($"子域名{name}不符合规范"));
                }
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadCommitted))
            {
                SiteDomain siteDomain = new SiteDomain()
                {
                    SiteID = siteId,
                    Domain = domain
                };
                siteDomain.AddIdentity(db);

                foreach (string name in subName.Distinct())
                {
                    // 添加域名记录
                    DomainRecord record = new DomainRecord()
                    {
                        CDNType  = provider,
                        CName    = this.CreateRecordCName(name, domain),
                        DomainID = siteDomain.ID,
                        Status   = DomainRecord.RecordStatus.Wait,
                        SubName  = name
                    };
                    record.AddIdentity(db);

                    // 添加CDN记录
                    DomainCDN cdn = new DomainCDN()
                    {
                        RecordID = record.ID,
                        Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                        CName    = string.Empty,
                        CDNType  = provider,
                        Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                    };
                    cdn.Add(db);
                }
                db.Commit();
            }

            return(true);
        }
Exemplo n.º 23
0
        /// <summary>
        ///     关联两个实体
        /// </summary>
        /// <typeparam name="T1">主实体</typeparam>
        /// <typeparam name="T2">要附加关联的实体</typeparam>
        /// <param name="lst">主列表</param>
        /// <param name="JoinModule">要关联的子实体</param>
        /// <param name="JoinModuleSelect">要附加关联的子实体的字段筛选</param>
        /// <param name="JoinModuleID">主表关系字段</param>
        /// <param name="defJoinModule">为空时如何处理?</param>
        /// <param name="db">事务</param>
        public static List <T1> Join <T1, T2>(this List <T1> lst, Expression <Func <T1, T2> > JoinModule,
                                              Func <T1, int?> JoinModuleID = null,
                                              Expression <Func <T2, object> > JoinModuleSelect = null,
                                              T2 defJoinModule = null, DbExecutor db = null)
            where T1 : ModelInfo, new()
            where T2 : ModelInfo, new()
        {
            if (lst == null || lst.Count == 0)
            {
                return(lst);
            }
            if (JoinModuleID == null)
            {
                JoinModuleID = o => o.ID;
            }

            #region 获取实际类型

            var memberExpression = JoinModule.Body as MemberExpression;
            // 获取属性类型
            var propertyType = (PropertyInfo)memberExpression.Member;

            var lstPropery = new List <PropertyInfo>();
            while (memberExpression.Expression.NodeType == ExpressionType.MemberAccess)
            {
                memberExpression = memberExpression.Expression as MemberExpression;
                lstPropery.Add((PropertyInfo)memberExpression.Member);
            }
            lstPropery.Reverse();

            #endregion

            // 内容ID
            var lstIDs = lst.Select(JoinModuleID).ToList().Select(o => o.GetValueOrDefault()).ToList();
            // 详细资料
            var lstSub = (new T2()) is BaseCacheModel <T2>
                         ?BaseCacheModel <T2> .Cache(db).ToList(lstIDs)
                             : BaseModel <T2> .Data.Where(o => lstIDs.Contains(o.ID))
                             .Select(JoinModuleSelect)
                             .Select(o => o.ID)
                             .ToList(db);

            foreach (var item in lst)
            {
                var subInfo = lstSub.FirstOrDefault(o => o.ID == JoinModuleID.Invoke(item)) ?? defJoinModule;

                object value = item;
                foreach (var propery in lstPropery)
                {
                    value = propery.GetValue(value, null);
                }
                propertyType.SetValue(value, subInfo, null);
            }

            return(lst);
        }
Exemplo n.º 24
0
 /// <summary>
 /// 事务
 /// </summary>
 /// <param name="database">数据库执行</param>
 /// <param name="tableName">表名称</param>
 public TableContext(DbExecutor database, string tableName = null) : base(database, tableName)
 {
     if (string.IsNullOrWhiteSpace(tableName))
     {
         Name = TableMapCache.GetMap <TEntity>().ClassInfo.Name;
     }
     TableSet       = new TableSet <TEntity>(this);
     IsMergeCommand = true;
     Query          = DbFactory.CreateQueryTable(this);
 }
        public override Driver Get(int driverId)
        {
            var sql = $@"
select * 
from Drivers
where Id = {driverId};
";

            return(DbExecutor.Query <Driver>(sql).FirstOrDefault());
        }
Exemplo n.º 26
0
        private void ExecuteScript(string script)
        {
            var cmd = InitCommand(script);

            DbExecutor.Execute(cmd).Wait();
            if (!cmd.Ok)
            {
                throw cmd.Error;
            }
        }
        public void Insert(RecordDescription data)
        {
            // RecordDescriptionはNotificationObjectを継承しているので、そのままInsertすると
            // Livet.WeakEventListenerHolderがunknown sqlce typeと言われてしまう。
            // そこで、いったん匿名型に入れ替える必要がある。

            DbExecutor.Insert(new SQLiteConnection(_connectionString), "RecordDescriptions",
                              new { data.Title, data.CreatedDateTime, data.TimeSpan, data.NamingName, data.ComponentType,
                                    data.PortName, data.DataType, data.SumSize, data.Count, data.IsLittleEndian,
                                    data.IndexFileName, data.DataFileName });
        }
Exemplo n.º 28
0
        protected void SaveMeta(IVersionedDescriptor src)
        {
            var cmd = InitCommand("qorpent.metaupdate");

            cmd.ParametersSoruce = new { code = src.Name, hash = src.Hash, version = src.Version.AddSeconds(-1) };
            DbExecutor.Execute(cmd).Wait();
            if (!cmd.Ok)
            {
                throw cmd.Error;
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// 获取频道ID
 /// </summary>
 /// <param name="channelName"></param>
 /// <returns></returns>
 public int GetChannelID(string channelName)
 {
     using (DbExecutor db = NewExecutor())
     {
         TranslateChannel channel = new TranslateChannel()
         {
             Name = channelName
         }.Info(db, t => t.Name);
         return(channel == null ? 0 : channel.ID);
     }
 }
Exemplo n.º 30
0
        /// <summary>
        ///     压缩数据库
        /// </summary>
        /// <param name="dataType">数据库类型</param>
        /// <param name="connetionString">连接字符串</param>
        public static void Compression(string connetionString, DataBaseType dataType = DataBaseType.SqlServer)
        {
            var db = new DbExecutor(connetionString, dataType, 30);

            switch (dataType)
            {
            case DataBaseType.SQLite: db.ExecuteNonQuery(CommandType.Text, "VACUUM", null); break;

            default: throw new NotImplementedException("该数据库不支持该方法!");
            }
        }
Exemplo n.º 31
0
        public void BeginGetTableTranTest()
        {
            DataTable dt;
            DataTable dt1;
            DataSet ds;
            dt = new DataTable();
            dt.Columns.Add("SysId");
            dt.Columns.Add("Name");
            dt.Columns.Add("Mark");
            CodeTimer.Time("ss", 1, () =>
            {
                using (DbExecutor db = new DbExecutor(new SqlConnection(connString),IsolationLevel.ReadCommitted))
                {
                    dt = db.BeginGetTable(SqlClientFactory.Instance, "select * from MyTest");

                    dt.Rows[0]["Name"] = "Test" + DateTime.Now;

                    dt.Rows[dt.Rows.Count - 1].Delete();

                    DataRow dr = dt.NewRow();

                    dt.Rows.Add(dr);

                    dr["Name"] = "jiguixinss"+DateTime.Now;
                    dr["Mark"] = "Makr4444";

                    db.EndCommitTable(dt);

                    Console.WriteLine(dr["SysId"].ToString());
                    Console.WriteLine(dr["Name"]);

                    //var mydt = db.BeginGetTable(SqlClientFactory.Instance,
                    //                            "select * from MyTest where SysId=@SysId",
                    //                            new
                    //                            {
                    //                                SysId
                    //                            =
                    //                            100054
                    //                            }
                    //    );
                    //mydt.Rows[0]["Name"] = "JIm"+DateTime.Now;
                    //db.EndCommitTable(mydt);

                    db.TransactionComplete();
                }
            });
        }
Exemplo n.º 32
0
        public void TestDbExecutor()
        {
            CodeTimer.Time("DbExecutor", 1, () =>
            {
                using (DbExecutor db = new DbExecutor(new SqlConnection(connString)))
                {
                    //var lst = db.Select<Customer>("select * from Customers ");

                    //Console.WriteLine(lst.Count());
                    string sql =
                                                   string.Format(
                                                       "insert into Customers Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')",
                                                       Guid.NewGuid(), "sds", "sf", "sf", "sf", "sf", 212, true);
                    db.ExecuteNonQuery(sql);
                }
            });
        }
Exemplo n.º 33
0
        public void BeginGetTableTest()
        {
            DataTable dt;
            DataTable dt1;
            DataSet ds;
            dt = new DataTable();
            dt.Columns.Add("SysId");
            dt.Columns.Add("Name");
            dt.Columns.Add("Mark");
            CodeTimer.Time("ss", 1, () =>
                                        {
                                            using (DbExecutor db = new DbExecutor(new SqlConnection(connString)))
                                            {
                                                dt = db.BeginGetTable(SqlClientFactory.Instance, "select * from MyTest");

                                                //dt.Rows[0]["Name"] = "ji1111n";

                                                DataRow dr = dt.NewRow();

                                                dt.Rows.Add(dr);

                                                dr["Name"] = "jiguixin4444";
                                                dr["Mark"] = "Makr4444";
                                                //db.CommitData(dt, "MyTest");

                                                db.EndCommitTable(dt);

                                                Console.WriteLine(dr["SysId"].ToString());
                                                Console.WriteLine(dr["Name"]);

                                                var mydt = db.BeginGetTable(SqlClientFactory.Instance,
                                                                            "select * from MyTest where SysId=@SysId",
                                                                            new
                                                                                {
                                                                                    SysId
                                                                                =
                                                                                100054
                                                                                }
                                                    );
                                                mydt.Rows[0]["Name"] = "JIm";
                                                db.EndCommitTable(mydt);

                                            }
                                        });
        }
Exemplo n.º 34
0
 public void DbProviderTest()
 {
     using (DbExecutor db = new DbExecutor(new SqlConnection(connString)))
     {
         var dt = db.GetTable(SqlClientFactory.Instance, "select * from MyTest");
         Assert.IsNotNull(dt);
         Assert.IsTrue(dt.Rows.Count > 0);
         Console.WriteLine(dt.Rows.Count);
     }
 }
Exemplo n.º 35
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="database">数据库操作</param>
 /// <param name="contextMap">映射关系</param>
 public ProcQueueManger(DbExecutor database, ContextMap contextMap)
     : base(database, contextMap)
 {
     _groupQueueList = new List<Queue>();
 }
Exemplo n.º 36
0
        public void CommitDataTest()
        {
            using (DbExecutor db = new DbExecutor(new SqlConnection(connString)))
            {
                var dt = db.GetTable(SqlClientFactory.Instance, "select * from MyTest");

                dt.Rows[0]["Name"] = "zhangjuncui";

                DataRow newDr = dt.NewRow();
                dt.Rows.Add(newDr);
                newDr["Name"] = "ABCD";
                newDr["Mark"] = "1244";

                db.CommitData(SqlClientFactory.Instance, dt, "MyTest");

                Console.WriteLine("Id:"+newDr["SysId"]);
            }
        }
Exemplo n.º 37
0
        public void TestStoreProc()
        {
            using (DbExecutor db = new DbExecutor(new SqlConnection(@"Data Source=JIGUIXIN\SQLEXPRESS;Initial Catalog=MyTest;Uid=jiguixin;pwd=123456;")))
            {
                SqlParameter par = new SqlParameter("p2",SqlDbType.Int,4);
                par.Direction = ParameterDirection.Output;

                //dynamic s2 = new { p1 = 1, par };

                var s = db.ExecuteNonQuery((string) "[dbo].[sp_name]",  new {p1=1,par}, CommandType.StoredProcedure);

                Console.WriteLine(par.Value);
            }
        }
Exemplo n.º 38
0
        public void GetTablesTest()
        {
            using (DbExecutor db = new DbExecutor(new SqlConnection(connString)))
            {
                var ds = db.GetTables(SqlClientFactory.Instance, "select * from MyTest;select * from MyTest1");
                Assert.IsNotNull(ds);
                Assert.IsNotNull(ds.Tables[0]);
                Assert.IsTrue(ds.Tables[0].Rows.Count > 0);
                Console.WriteLine(ds.Tables[0].Rows.Count);

                Assert.IsNotNull(ds.Tables[1]);
                Assert.IsTrue(ds.Tables[1].Rows.Count > 0);
                Console.WriteLine(ds.Tables[1].Rows.Count);
            }
        }
Exemplo n.º 39
0
        public void CommitDataTranTest()
        {
            using (DbExecutor db = new DbExecutor(new SqlConnection(connString),IsolationLevel.ReadCommitted))
            {
                var dt = db.GetTable(SqlClientFactory.Instance, "select * from MyTest");

                dt.Rows[1]["Name"] = "zhangjuncui";

                DataRow newDr = dt.NewRow();
                dt.Rows.Add(newDr);
                newDr["Name"] = DateTime.Now;
                newDr["Mark"] = "1244";

                db.CommitData(SqlClientFactory.Instance, dt, "MyTest");

                Console.WriteLine("Id:" + newDr["SysId"]);
                db.TransactionComplete();
            }
        }
Exemplo n.º 40
0
        public void ExecuteReaderTest()
        {
            using(DbExecutor db = new DbExecutor(new SqlConnection(connString)))
            {
                 var s = db.ExecuteReader("select * from MyTest").Select(dr=>new {Name=dr["Name"],mark=dr["Mark"]});

                foreach (var v in s)
                {
                     Console.WriteLine(v.mark);
                }

            }
        }
Exemplo n.º 41
0
 public ViewQueueManger(DbExecutor database, ContextMap contextMap)
     : base(database, contextMap) { }