示例#1
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            string tableName = MyStagingUtils.GetMapping(typeof(T));

            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }
            string cmdText = $"UPDATE {tableName} SET {string.Join(",", this.setList)} {"WHERE " + string.Join("\nAND ", WhereList)}";
            int    affrows = 0;

            if (OnChanged != null)
            {
                cmdText += " RETURNING *;";

                var objList = base.ByMaster().ExecuteReader <T>(cmdText);
                affrows = objList.Count;
                if (affrows > 0 && this.OnChanged != null)
                {
                    OnChanged(objList[0]);
                }
            }
            else
            {
                affrows = base.ExecuteNonQuery(cmdText);
            }

            return(affrows);
        }
示例#2
0
        private bool CheckWhere(OleDbConnection connection)
        {
            var reader = ADOSQLHelper.ExecuteReader(connection, string.Format("Select {0},{1},{2} from {3}", CheckFieldName, Key, string.Join(",", WhereFields), TableName));

            if (reader != null)
            {
                var str   = string.Empty;
                var error = string.Empty;
                var array = new string[WhereFields.Length];
                while (reader.Read())
                {
                    str = reader[0].ToString();
                    for (var i = 0; i < WhereFields.Length; i++)
                    {
                        array[i] = reader[i + 2].ToString();
                    }
                    var key = string.Join(Split, array);
                    if (WhereList.Contains(key))
                    {
                        if (!Values.Contains(str))
                        {
                            error = string.Format("{0}对应的‘{1}’不正确", reader[1].ToString(), str);
                            _questions.Add(new Question {
                                Code = "3201", Name = Name, Project = CheckProject.值符合性, TableName = TableName, BSM = reader[1].ToString(), Description = error
                            });
                        }
                    }
                }
                return(true);
            }
            return(false);
        }
示例#3
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query Where(string tableName, string columnName, WhereComparision comparison, object value)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     _ListWhere.Clear();
     _ListWhere.Add(new Where(WhereCondition.AND, tableName, columnName, comparison, value));
     return this;
 }
示例#4
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query Where(string columnName, object value)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     _ListWhere.Clear();
     _ListWhere.Add(new Where(WhereCondition.AND, columnName, ValueObjectType.ColumnName, WhereComparision.EqualsTo, value, ValueObjectType.Value));
     return this;
 }
示例#5
0
        /// <summary>
        ///  将当前更改保存到数据库
        /// </summary>
        /// <returns></returns>
        public int SaveChange()
        {
            if (WhereExpressionList.Count > 0)
            {
                foreach (var item in WhereExpressionList)
                {
                    DbExpressionVisitor expression = new DbExpressionVisitor();
                    expression.Visit(item.Body);
                    WhereList.Add(expression.SqlText.Builder.ToString().ToLower());
                    ParamList.AddRange(expression.SqlText.Parameters);
                }
            }

            CheckNotNull.NotEmpty(this.WhereList, "The delete operation must specify where conditions!");

            this.ToString();
            var affrows = 0;

            try
            {
                affrows = base.ExecuteNonQuery(this.CommandText);
            }
            finally
            {
                base.ParamList.Clear();
            }

            return(affrows);
        }
示例#6
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query Where(Where where, bool clearWhereList)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     if (clearWhereList) _ListWhere.Clear();
     _ListWhere.Add(where);
     return this;
 }
示例#7
0
        //Constructor
        //Init' property values

        public EntryObject()
        {
            EntryID = -1;
            NameList.Add("_null");
            TypeList.Add("_null");
            WhereList.Add("_null");
            ExtraList.Add("_null");
        }
示例#8
0
 public Delete(Format format, string tableName, string tableAlias = "")
 {
     this.Query      = Enums.SqlQuery.Delete;
     this.TableName  = tableName;
     this.TableAlias = tableAlias;
     this.Format     = format;
     this.Where      = new WhereList(this.Format);
 }
示例#9
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query AddWhere(WhereList whereList)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     foreach (Where where in whereList)
     {
         _ListWhere.Add(where);
     }
     return this;
 }
示例#10
0
 public Update(Format parameters, string tableName, string tableAlias = "")
 {
     this.Query      = Enums.SqlQuery.Update;
     this.Format     = parameters;
     this.TableName  = tableName;
     this.TableAlias = tableAlias;
     this.Sets       = new SetList(this.Format);
     this.Where      = new WhereList(this.Format);
 }
示例#11
0
        public void AndLess()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Less("a", "b", "c");
            string result = w.GetSql();
            string sql    = "[a]<@a AND [b]<@b AND [c]<@c";

            Assert.AreEqual(sql, result);
        }
示例#12
0
        public void RawSimple1()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Raw("[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'");
            string result = w.GetSql();
            string sql    = "[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'";

            Assert.AreEqual(sql, result);
        }
示例#13
0
        public void IsNotNullSimple()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.IsNotNULL("a", "b", "c");
            string result = w.GetSql();
            string sql    = "[a] IS NOT NULL AND [b] IS NOT NULL AND [c] IS NOT NULL";

            Assert.AreEqual(sql, result);
        }
示例#14
0
        public void WhereParenthesis4()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.RawParenthesis("[a] IS NULL OR [b] IS NULL");
            string result = w.GetSql();
            string sql    = "([a] IS NULL OR [b] IS NULL)";

            Assert.AreEqual(sql, result);
        }
示例#15
0
        public void InSimple3()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.In("id_user", "SELECT id FROM tab_users");
            string result = w.GetSql();
            string sql    = "[id_user] IN (SELECT id FROM tab_users)";

            Assert.AreEqual(sql, result);
        }
示例#16
0
        public void AndEqualSimple1()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Equal("a", "b", "c");
            string result = w.GetSql();
            string sql    = "[a]=@a AND [b]=@b AND [c]=@c";

            Assert.AreEqual(sql, result);
        }
示例#17
0
        /// <summary>
        ///  该方法没有对sql注入进行参数化过滤
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public QueryContext <T> Where(string expression)
        {
            if (string.IsNullOrEmpty(expression))
            {
                throw new ArgumentNullException("必须传递参数 expression");
            }

            WhereList.Add(expression);
            return(this);
        }
示例#18
0
        public void ComboAndEqualAndNotEqual()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.EqualValue("a", "1");
            w.NotEqualValue("b", "2");
            string result = w.GetSql();
            string sql    = "[a]=1 AND [b]!=2";

            Assert.AreEqual(sql, result);
        }
示例#19
0
 public Select(IFormatter parameters, string tableAlias = "")
 {
     Query      = SqlQuery.Select;
     Formatter  = parameters;
     TableAlias = tableAlias;
     Columns    = new ColumnsListAggregation(Formatter);
     Join       = new JoinList(Formatter);
     Where      = new WhereList(Formatter);
     OrderBy    = new OrderByList(Formatter);
     GroupBy    = new GroupByList(Formatter, Columns);
 }
示例#20
0
        public void ComboAndGreaterAndLess()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Greater("a");
            w.Less("b");
            string result = w.GetSql();
            string sql    = "[a]>@a AND [b]<@b";

            Assert.AreEqual(sql, result);
        }
示例#21
0
        public void RawSimple2()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Raw("[a] NOT LIKE '%text%'");
            w.Equal("id");
            string result = w.GetSql();
            string sql    = "[a] NOT LIKE '%text%' AND [id]=@id";

            Assert.AreEqual(sql, result);
        }
示例#22
0
        public void WhereParenthesis4()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            WhereList w = new WhereList(SqlBuilder.DefaultFormatter);

            w.RawParenthesis("[a] IS NULL OR [b] IS NULL");
            string result = w.GetSql();
            string sql    = "([a] IS NULL OR [b] IS NULL)";

            Assert.AreEqual(sql, result);
        }
示例#23
0
        public void IsNotNullSimple()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            WhereList w = new WhereList(SqlBuilder.DefaultFormatter);

            w.IsNotNULL("a", "b", "c");
            string result = w.GetSql();
            string sql    = "[a] IS NOT NULL AND [b] IS NOT NULL AND [c] IS NOT NULL";

            Assert.AreEqual(sql, result);
        }
示例#24
0
        public void RawSimple1()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            WhereList w = new WhereList(SqlBuilder.DefaultFormatter);

            w.Raw("[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'");
            string result = w.GetSql();
            string sql    = "[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'";

            Assert.AreEqual(sql, result);
        }
示例#25
0
        public void RawSimple1()
        {
            SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            var w = new WhereList(SuperSql.DefaultFormatter);

            w.Raw("[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'");
            var result = w.GetSql();
            var sql    = "[a] IS NULL AND [b]=2 AND [c] NOT LIKE '%text%'";

            Assert.Equal(sql, result);
        }
示例#26
0
        public void AndNotEqualParamValue()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.NotEqualValue("a", "1");
            w.NotEqualValue("b", "2");
            w.NotEqualValue("c", "3");
            string result = w.GetSql();
            string sql    = "[a]!=1 AND [b]!=2 AND [c]!=3";

            Assert.AreEqual(sql, result);
        }
示例#27
0
        public void WhereParenthesis4()
        {
            SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            var w = new WhereList(SuperSql.DefaultFormatter);

            w.RawParenthesis("[a] IS NULL OR [b] IS NULL");
            var result = w.GetSql();
            var sql    = "([a] IS NULL OR [b] IS NULL)";

            Assert.Equal(sql, result);
        }
示例#28
0
        public void AndEqualSimple2()
        {
            SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            var w = new WhereList(SuperSql.DefaultFormatter);

            w.Equal("a", "b", "c");
            var result = w.GetSql("t");
            var sql    = "[t].[a]=@a AND [t].[b]=@b AND [t].[c]=@c";

            Assert.Equal(sql, result);
        }
示例#29
0
        public void AndGreaterParam()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.GreaterValue("a", "1");
            w.GreaterValue("b", "2");
            w.GreaterValue("c", "3");
            string result = w.GetSql();
            string sql    = "[a]>1 AND [b]>2 AND [c]>3";

            Assert.AreEqual(sql, result);
        }
示例#30
0
        public void AndEqualSimple1()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            WhereList w = new WhereList(SqlBuilder.DefaultFormatter);

            w.Equal("a", "b", "c");
            string result = w.GetSql();
            string sql    = "[a]=@a AND [b]=@b AND [c]=@c";

            Assert.AreEqual(sql, result);
        }
示例#31
0
        public void InSimple1()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.Equal("a");
            w.In("b", "1", "2", "3");
            w.Equal("c");
            string result = w.GetSql();
            string sql    = "[a]=@a AND [b] IN (1, 2, 3) AND [c]=@c";

            Assert.AreEqual(sql, result);
        }
示例#32
0
        public void AndLessParam()
        {
            WhereList w = new WhereList(global::SqlBuilder.Format.MsSQL);

            w.LessValue("a", "1");
            w.LessValue("b", "2");
            w.LessValue("c", "3");
            string result = w.GetSql();
            string sql    = "[a]<1 AND [b]<2 AND [c]<3";

            Assert.AreEqual(sql, result);
        }
示例#33
0
        public void AndEqualGreater()
        {
            SuperSql.DefaultFormatter = FormatterLibrary.MsSql;

            var w = new WhereList(SuperSql.DefaultFormatter);

            w.EqualGreater("a", "b", "c");
            var result = w.GetSql();
            var sql    = "[a]>=@a AND [b]>=@b AND [c]>=@c";

            Assert.Equal(sql, result);
        }
示例#34
0
        public void InSimple2()
        {
            SqlBuilder.DefaultFormatter = FormatterLibrary.MsSql;

            WhereList w = new WhereList(SqlBuilder.DefaultFormatter);

            w.In("id_user", "SELECT id FROM tab_users");
            string result = w.GetSql();
            string sql    = "[id_user] IN (SELECT id FROM tab_users)";

            Assert.AreEqual(sql, result);
        }
示例#35
0
 public Query Having(WhereCondition condition, WhereList whereList)
 {
     return Having(new Where(condition, whereList));
 }
示例#36
0
 public Where(WhereList whereList)
 {
     First = whereList;
 }
示例#37
0
        private void BuildJoin(StringBuilder sb, ConnectorBase connection)
        {
            if (_ListJoin != null)
            {
                foreach (Join join in _ListJoin)
                {
                    switch (join.JoinType)
                    {
                        case JoinType.InnerJoin:
                            sb.Append(@" INNER JOIN ");
                            break;
                        case JoinType.LeftJoin:
                            sb.Append(@" LEFT JOIN ");
                            break;
                        case JoinType.RightJoin:
                            sb.Append(@" RIGHT JOIN ");
                            break;
                        case JoinType.LeftOuterJoin:
                            sb.Append(@" LEFT OUTER JOIN ");
                            break;
                        case JoinType.RightOuterJoin:
                            sb.Append(@" RIGHT OUTER JOIN ");
                            break;
                        case JoinType.FullOuterJoin:
                            sb.Append(@" FULL OUTER JOIN ");
                            break;
                    }
                    if (join.RightTableSchema != null)
                    {
                        if (join.RightTableSchema.DatabaseOwner.Length > 0)
                        {
                            sb.Append(connection.WrapFieldName(join.RightTableSchema.DatabaseOwner));
                            sb.Append('.');
                        }
                        sb.Append(connection.WrapFieldName(join.RightTableSchema.Name));
                    }
                    else
                    {
                        sb.Append('(');
                        if (join.RightTableSql is Query)
                        {
                            sb.Append(((Query)join.RightTableSql).BuildCommand(connection));
                        }
                        else
                        {
                            sb.Append(join.RightTableSql.ToString());
                        }
                        sb.Append(')');
                    }

                    sb.Append(' ');

                    if (join.RightTableAlias != null)
                    {
                        sb.Append(join.RightTableAlias);
                    }
                    else
                    {
                        sb.Append(join.RightTableSchema != null ? join.RightTableSchema.Name : @"");
                    }

                    if (join.Pairs.Count > 1)
                    {
                        sb.Append(@" ON ");
                        WhereList wl = new WhereList();
                        foreach (WhereList joins in join.Pairs)
                        {
                            wl.AddRange(joins);
                        }
                        wl.BuildCommand(sb, connection, this, join.RightTableSchema, join.RightTableAlias == null ? join.RightTableSchema.Name : join.RightTableAlias);
                    }
                    else if (join.Pairs.Count == 1)
                    {
                        sb.Append(@" ON ");
                        join.Pairs[0].BuildCommand(sb, connection, this, join.RightTableSchema, join.RightTableAlias == null ? join.RightTableSchema.Name : join.RightTableAlias);
                    }
                }
            }
        }
示例#38
0
 /// <summary>
 /// Adds a where condition. Does not remove any existing conditions.
 /// </summary>
 /// <param name="where"></param>
 /// <returns>Current <typeparamref name="Query"/> object</returns>
 public Query Where(Where where)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     _ListWhere.Add(where);
     return this;
 }
示例#39
0
 public WhereList AND(IPhrase phrase, WhereComparison comparison, object value)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.AND(phrase, comparison, value);
 }
示例#40
0
 public Query Having(Where where)
 {
     if (_ListHaving == null) _ListHaving = new WhereList();
     _ListHaving.Add(where);
     return this;
 }
示例#41
0
 public Query Where(WhereList whereList)
 {
     return Where(new Where(WhereCondition.AND, whereList));
 }
示例#42
0
 public WhereList OR(IPhrase phrase, WhereComparison comparison, object value, ValueObjectType valueType)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase, comparison, value, valueType);
 }
示例#43
0
 public WhereList OR(IPhrase phrase, WhereComparison comparison, string tableName, string columnName)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase, comparison, tableName, columnName);
 }
示例#44
0
 public WhereList OR(string literalExpression)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(literalExpression);
 }
示例#45
0
 public WhereList OR(IPhrase phrase)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(phrase);
 }
示例#46
0
 public WhereList OR(string columnName, object columnValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(columnName, columnValue);
 }
示例#47
0
 public WhereList OR(object thisObject, ValueObjectType thisObjectType, WhereComparison comparison, object thatObject, ValueObjectType thatObjectType)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(thisObject, thisObjectType, comparison, thatObject, thatObjectType);
 }
示例#48
0
 public WhereList AND(string tableName, string columnName, object betweenValue, object andValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.AND(tableName, columnName, betweenValue, andValue);
 }
示例#49
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query AND(WhereList whereList)
 {
     return Where(new Where(WhereCondition.AND, whereList), false);
 }
示例#50
0
 public WhereList OR(WhereList whereList)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(whereList);
 }
示例#51
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query OR(WhereList whereList)
 {
     return Where(new Where(WhereCondition.OR, whereList), false);
 }
示例#52
0
 public WhereList OR(string tableName, string columnName, WhereComparison comparison, object columnValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(tableName, columnName, comparison, columnValue);
 }
示例#53
0
 public Query Having(WhereList whereList)
 {
     return Having(WhereCondition.AND, whereList);
 }
示例#54
0
 public WhereList OR(string tableName, string columnName, WhereComparison comparison, string otherTableName, string otherColumnName)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(tableName, columnName, comparison, otherTableName, otherColumnName);
 }
示例#55
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query AddWhere(WhereCondition condition, WhereList whereList)
 {
     return Where(new Where(condition, whereList), false);
 }
示例#56
0
 public WhereList OR(string columnName, object betweenValue, object andValue)
 {
     var wl = new WhereList();
     wl.Add(this);
     return wl.OR(columnName, betweenValue, andValue);
 }
示例#57
0
文件: Wheres.cs 项目: ycaihua/dg.Sql
 public Query AddWhere(string tableName, string columnName, WhereComparision comparison, string otherTableName, string otherColumnName)
 {
     if (_ListWhere == null) _ListWhere = new WhereList();
     _ListWhere.Add(new Where(WhereCondition.AND, tableName, columnName, comparison, otherTableName, otherColumnName));
     return this;
 }
示例#58
0
 public Where(WhereCondition condition, WhereList whereList)
 {
     Condition = condition;
     First = whereList;
 }