Ejemplo n.º 1
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="table"></param>
        /// <param name="field">更新的字段列表</param>
        /// <param name="ws">条件</param>
        /// <param name="values">值,[{id:1},{id,2}]</param>
        /// <param name="predicate"></param>
        public virtual void update_batch(string table, string fields, SqlParam[] ws, JToken values, string predicate = "and")
        {
            //加载结构
            this.m_table = this.table(table);
            var field_all = this.m_table.SelectToken("fields");
            var field_sel = this.selFields(fields, field_all);
            var field_cdt = this.selFields(ws, field_all);

            JObject o   = new JObject();
            string  sql = string.Format("update {0} set {1} where {2}"
                                        , table
                                        , this.toSqlSeter(fields)
                                        , this.toSqlCondition(ws, predicate));

            DbHelper db  = new DbHelper();
            var      cmd = db.GetCommand(sql);

            this.m_pc.create(cmd, field_sel);
            this.m_pc.create(cmd, field_cdt);
            cmd.Connection.Open();
            cmd.Prepare();

            SqlValueSetter pvs = new SqlValueSetter();

            //设置条件
            foreach (var v in values)
            {
                pvs.setVal(cmd, field_sel, v);
                pvs.setVal(cmd, field_cdt, v);
                cmd.ExecuteNonQuery();
            }

            cmd.Connection.Close();
        }
Ejemplo n.º 2
0
        public override void delete_batch(string table, SqlParam[] ws, JToken values, string predicate = "and")
        {
            //加载结构
            this.m_table = this.table(table);
            var field_all = this.m_table.SelectToken("fields");
            var field_sel = this.selFields(ws, field_all);

            JObject o   = new JObject();
            string  sql = string.Format("delete from \"{0}\" where {1}"
                                        , table
                                        , this.toSqlCondition(ws, predicate));

            DbHelper db  = new DbHelper();
            var      cmd = db.GetCommand(sql);

            this.m_parSetter.setVal(cmd, field_sel, ws);
            cmd.Connection.Open();
            cmd.Prepare();

            SqlValueSetter pvs = new SqlValueSetter();

            foreach (var v in values)
            {
                pvs.setVal(cmd, field_sel, v);
                cmd.ExecuteNonQuery();
            }

            cmd.Connection.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 批量SQL语句
        /// </summary>
        /// <param name="table"></param>
        /// <param name="sql"></param>
        /// <param name="fields"></param>
        /// <param name="where"></param>
        /// <param name="values">字段值列表</param>
        public virtual void exec_batch(string table, string sql, string fields, string where, JToken values)
        {
            //加载结构
            this.m_table = this.table(table);
            var field_all = this.m_table.SelectToken("fields");
            var field_sel = this.selFields(fields, field_all);
            var field_cdt = this.selFields(where, field_all);

            DbHelper db  = new DbHelper();
            var      cmd = db.GetCommand(sql);

            this.m_pc.create(cmd, field_sel);
            this.m_pc.create(cmd, field_cdt);

            cmd.Connection.Open();
            cmd.Prepare();

            SqlValueSetter pvs = new SqlValueSetter();

            //设置条件
            foreach (var v in values)
            {
                pvs.setVal(cmd, field_sel, v);
                pvs.setVal(cmd, field_cdt, v);
                cmd.ExecuteNonQuery();
            }

            cmd.Connection.Close();
        }