Esempio n. 1
0
 void GetCondition <T>(string col, T val, string andor = AndOr.And, string op = Op.Eq, bool isFunc = false)
 {
     if (IsKeyCondition)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(col))
     {
         return;
     }
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(andor);
     }
     if (isFunc)
     {
         OtherCondition.Append(DB.SetColumnFunc(col, val));
     }
     else
     {
         OtherCondition.Append(DB.GetCondition(col, op));
         Params.Add(DB.GetParam(col, val));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 原生条件字符串
        /// </summary>
        /// <param name="sqlString">id=? or name=?</param>
        /// <param name="args"></param>
        /// <returns></returns>
        public Sql Where(string sqlString, params object[] args)
        {
            if (string.IsNullOrWhiteSpace(sqlString))
            {
                throw new Exception("数据库操作命令不能为空");
            }
            var cmd = DB.GetRawSql(" " + sqlString + " ", args);

            if (cmd.SqlParams != null)
            {
                Params.AddRange(cmd.SqlParams);
            }
            // 如果有左括号,忽略逻辑运算符
            if (hasParenthesis)
            {
                hasParenthesis = false;
            }
            else if (OtherCondition.Length > 0)
            {
                OtherCondition.Append(AndOr.And);
            }

            OtherCondition.Append(cmd.SqlString);
            return(this);
        }
Esempio n. 3
0
 public Sql LP()
 {
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(AndOr.And);
     }
     OtherCondition.Append(" ( ");
     hasParenthesis = true;
     return(this);
 }
Esempio n. 4
0
 void GetBetweenCondition <T>(string colName, T t1, T t2, string andor = AndOr.And, string op = Op.Between)
 {
     if (IsKeyCondition)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(colName) || t1 == null || t2 == null)
     {
         return;
     }
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(andor);
     }
     OtherCondition.Append(string.Concat("(", DB._RestrictPrefix, colName, DB._RestrictPostfix, op, t1, " AND ", t2, ")"));
 }
Esempio n. 5
0
 void GetInCondition <T>(string colName, string andor = AndOr.And, string op = Op.In, params T[] args)
 {
     if (IsKeyCondition)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(colName) || args == null || args.Length == 0)
     {
         return;
     }
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(andor);
     }
     OtherCondition.Append(string.Concat("(", DB._RestrictPrefix, colName, DB._RestrictPostfix, op, "(", string.Join(",", args), "))"));
 }
Esempio n. 6
0
 void GetNullCondition(string col, string andor = AndOr.And, bool isnull = true)
 {
     if (IsKeyCondition)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(col))
     {
         return;
     }
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(andor);
     }
     OtherCondition.Append(string.Concat("(", DB._RestrictPrefix, col, DB._RestrictPostfix, isnull ? Op.Null : Op.NotNull, ")"));
 }
Esempio n. 7
0
 bool GetLikeCondition(string col, string val, string andor = AndOr.And, string op = Op.Like)
 {
     if (IsKeyCondition)
     {
         return(false);
     }
     if (string.IsNullOrWhiteSpace(col) || string.IsNullOrWhiteSpace(val))
     {
         return(false);
     }
     // 如果有左括号,忽略逻辑运算符
     if (hasParenthesis)
     {
         hasParenthesis = false;
     }
     else if (OtherCondition.Length > 0)
     {
         OtherCondition.Append(andor);
     }
     OtherCondition.Append(string.Concat("(", DB._RestrictPrefix, col, DB._RestrictPostfix, op, DB._ParameterPrefix, col, ")"));
     return(true);
 }
 public void ShowSQLString()
 {
     ShowSQLString(OtherCondition.ToString(), Params);
 }
Esempio n. 9
0
 public Sql RP()
 {
     OtherCondition.Append(" ) ");
     return(this);
 }