示例#1
0
        public static ExecArgs Update(string table, AlterArgs args)
        {
            SQLiteParameter[] param = null;
            string            set   = string.Empty;

            if (args != null && args.Length > 0)
            {
                param = new SQLiteParameter[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    param[i] = new SQLiteParameter(args[i].Name, args[i].Value);
                    if (!args.Where.Contains(args[i].Name))
                    {
                        set += string.Format("{0}=@{0},", args[i].Name);
                    }
                }

                set = set.Remove(set.Length - 1);
            }

            string cmdText = string.Format("Update {0} Set {1} Where {2}", table, set, args?.Where);

            ExecArgs ea = new ExecArgs()
            {
                Text  = cmdText,
                Type  = CommandType.Text,
                Param = param
            };

            return(ea);
        }
示例#2
0
        public int Insert <T>(T tag, params string[] keys)
        {
            ExecArgs ea    = ArgsHelper.Insert <T>(tag, keys);
            int      count = ExecEditor(ea.Text, ea.Type, ea.Param);

            return(count);
        }
 public override Task <BreakableChainReturnValue <string> > ExecuteDown(ExecArgs <TestParameterType, string> execArgs)
 {
     return(Task.FromResult(new BreakableChainReturnValue <string>()
     {
         Value = execArgs.Paramater.Value + " Test Chain Item reached"
     }));
 }
示例#4
0
        public object SelectToValue(QueryArgs args)
        {
            ExecArgs ea  = ArgsHelper.Select("Record", args);
            object   obj = ExecScalar(ea.Text, ea.Type, ea.Param);

            return(obj);
        }
示例#5
0
        public int Update(AlterArgs args)
        {
            ExecArgs ea    = ArgsHelper.Update("Record", args);
            int      count = ExecEditor(ea.Text, ea.Type, ea.Param);

            return(count);
        }
示例#6
0
        private void CreateDb()
        {
            if (!IsHasDir(db))
            {
                AddedArgs param = new AddedArgs(new DbParams[]
                {
                    new DbParams("ID", "INTEGER PRIMARY KEY AUTOINCREMENT"),
                    new DbParams("Key", "String"),
                    new DbParams("Value", "String")
                });
                ExecArgs args = ArgsHelper.Create("Table", "Config", param);

                DataBase dbh = new DataBase(db);
                dbh.CreateTable(args);

                param = new AddedArgs(new DbParams[]
                {
                    new DbParams("ID", "INTEGER PRIMARY KEY AUTOINCREMENT"),
                    new DbParams("FID", "STRING"),
                    new DbParams("File", "STRING"),
                    new DbParams("Date", "DATETIME"),
                    new DbParams("TargetKey", "STRING"),
                    new DbParams("TargetName", "STRING"),
                    new DbParams("SampleKey", "STRING"),
                    new DbParams("SampleName", "STRING"),
                    new DbParams("Value", "DOUBLE")
                });
                args = ArgsHelper.Create("Table", "Record", param);
                dbh.CreateTable(args);
            }
        }
示例#7
0
        public static ExecArgs Select(string table, QueryArgs args)
        {
            SQLiteParameter[] param = null;
            if (args != null && args.Length > 0)
            {
                param = new SQLiteParameter[args.Length];
                for (int i = 0; i < args?.Length; i++)
                {
                    param[i] = new SQLiteParameter(args[i].Name, args[i].Value);
                }
            }

            string row = string.IsNullOrEmpty(args?.Rows) ? "*" : args?.Rows;

            string where = !string.IsNullOrEmpty(args?.Where) ? string.Format("Where {0}", args.Where) : args?.Where;
            string group = !string.IsNullOrEmpty(args?.Group) ? string.Format("Group By {0}", args.Group) : args?.Group;
            string order = !string.IsNullOrEmpty(args?.Order) ? string.Format("Order By {0}", args.Order) : args?.Order;

            string cmdText = string.Format("Select {0} From {1} {2} {3} {4}", row, table, where, group, order);

            ExecArgs ea = new ExecArgs()
            {
                Text  = cmdText,
                Type  = CommandType.Text,
                Param = param
            };

            return(ea);
        }
示例#8
0
        public int Insert(AddedArgs args)
        {
            ExecArgs ea    = ArgsHelper.Insert("Record", args);
            int      count = ExecEditor(ea.Text, ea.Type, ea.Param);

            return(count);
        }
示例#9
0
        public DataTable SelectToDT(QueryArgs args)
        {
            ExecArgs  ea = ArgsHelper.Select("Record", args);
            DataTable dt = ExecQuery(ea.Text, ea.Type, ea.Param);

            return(dt);
        }
示例#10
0
        public static ExecArgs Insert(string table, AddedArgs args)
        {
            string skey   = string.Empty;
            string svalue = string.Empty;

            SQLiteParameter[] param = null;
            if (args != null && args.Length > 0)
            {
                param = new SQLiteParameter[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    skey    += string.Format("{0},", args[i].Name);
                    svalue  += string.Format("@{0},", args[i].Name);
                    param[i] = new SQLiteParameter(args[i].Name, args[i].Value);
                }

                skey   = skey.Remove(skey.Length - 1);
                svalue = svalue.Remove(svalue.Length - 1);
            }


            string cmdText = string.Format("Insert Into {0} ({1}) Values ({2})", table, skey, svalue);

            ExecArgs ea = new ExecArgs()
            {
                Text  = cmdText,
                Type  = CommandType.Text,
                Param = param
            };

            return(ea);
        }
示例#11
0
        public T SelectToObject <T>(QueryArgs args) where T : class
        {
            ExecArgs ea   = ArgsHelper.Select("Record", args);
            List <T> list = ExecQuery <T>(ea.Text, ea.Type, ea.Param);

            return(list[0]);
        }
示例#12
0
        public object SelectToValue(QueryArgs args)
        {
            ExecArgs ea = ArgsHelper.Select("Config", args);

            object value = this.ExecScalar(ea.Text, ea.Type, ea.Param);

            return(value);
        }
示例#13
0
        public int Delete(AlterArgs args)
        {
            ExecArgs ea = ArgsHelper.Delete("Config", args);

            int count = this.ExecEditor(ea.Text, ea.Type, ea.Param);

            return(count);
        }
示例#14
0
        public static ExecArgs Create(string type, string name, AddedArgs args)
        {
            string rows = string.Empty;

            if (args != null && args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    rows += string.Format("{0} {1}, ", args[i].Name, args[i].Value);
                }
                rows = rows.Remove(rows.Length - 2);
            }

            string cmdText = string.Format("Create {0} {1} ({2})", type, name, rows);

            ExecArgs ea = new ExecArgs()
            {
                Text = cmdText,
                Type = CommandType.Text
            };

            return(ea);
        }
示例#15
0
        public static ExecArgs Delete(string table, AlterArgs args)
        {
            SQLiteParameter[] param = null;
            if (args != null && args.Length > 0)
            {
                param = new SQLiteParameter[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    param[i] = new SQLiteParameter(args[i].Name, args[i].Value);
                }
            }


            string cmdText = string.Format("Delete From {0} Where {1}", table, args?.Where);

            ExecArgs ea = new ExecArgs()
            {
                Text  = cmdText,
                Type  = CommandType.Text,
                Param = param
            };

            return(ea);
        }
示例#16
0
        public int Update(AlterArgs args)
        {
            ExecArgs ea = ArgsHelper.Update("Config", args);

            return(ExecEditor(ea.Text, ea.Type, ea.Param));
        }
示例#17
0
        public static ExecArgs Insert <T>(T tag, params string[] keys)
        {
            Type   tTag   = tag.GetType();
            string skey   = string.Empty;
            string svalue = string.Empty;

            SQLiteParameter[] param = null;

            List <SQLiteParameter> list = new List <SQLiteParameter>();

            PropertyInfo[] ppts = tTag.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo ppt in ppts)
            {
                if (keys.Contains(ppt.Name))
                {
                    continue;
                }

                object obj = ppt.GetValue(tag, null);
                if (obj == null)
                {
                    continue;
                }
                else if (obj.GetType() == typeof(int))
                {
                    int iPpt = Convert.ToInt32(obj);
                    if (iPpt >= 0)
                    {
                        list.Add(new SQLiteParameter(ppt.Name, iPpt));
                    }
                }
                else if (obj.GetType() == typeof(DateTime))
                {
                    DateTime dtPpt = Convert.ToDateTime(obj);
                    if (dtPpt > DateTime.MinValue)
                    {
                        list.Add(new SQLiteParameter(ppt.Name, dtPpt));
                    }
                }
                else
                {
                    string sPpt = obj.ToString();
                    list.Add(new SQLiteParameter(ppt.Name, sPpt));
                }

                skey   += string.Format("{0},", ppt.Name);
                svalue += string.Format("@{0},", ppt.Name);
            }
            param  = list.ToArray();
            skey   = skey.Remove(skey.Length - 1);
            svalue = svalue.Remove(svalue.Length - 1);

            string cmdText = string.Format("Insert Into {0} ({1}) Values ({2})", tTag.Name, skey, svalue);

            ExecArgs ea = new ExecArgs()
            {
                Text  = cmdText,
                Type  = CommandType.Text,
                Param = param
            };

            return(ea);
        }
示例#18
0
        public DataTable SelectToDT(QueryArgs args)
        {
            ExecArgs ea = ArgsHelper.Select("Config", args);

            return(ExecQuery(ea.Text, ea.Type, ea.Param));
        }
示例#19
0
        public T SelectToObject <T>(QueryArgs args) where T : class
        {
            ExecArgs ea = ArgsHelper.Select("Config", args);

            return(ExecQuery <T>(ea.Text, ea.Type, ea.Param)[0]);
        }
示例#20
0
        public int Insert(AddedArgs args)
        {
            ExecArgs ea = ArgsHelper.Insert("Config", args);

            return(this.ExecEditor(ea.Text, ea.Type, ea.Param));
        }