Example #1
0
 /// <summary>
 /// 空条件
 /// </summary>
 /// <param name="where"></param>
 /// <returns></returns>
 public static WhereExpressionMySQL Empty(this WhereExpressionMySQL where)
 {
     if (where == null)
     {
         return Empty();
     }
     return where.AddExpression(string.Empty);//string.Format("{0}={1}", "1", "1")
 }
Example #2
0
 /// <summary>
 /// LIKE % 左匹配
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static WhereExpressionSQL LikeLeft(this WhereExpressionSQL where, string fieldName, string value)
 {
     if (where == null)
     {
         return LikeLeft(fieldName, value);
     }
     SqlParameter parameter = CreateParameter(fieldName, SqlDbType.VarChar, value);
     return where.AddExpression(string.Format("{0} LIKE '%'+{1}", fieldName, parameter.ParameterName), new IDbDataParameter[] { parameter });
 }
Example #3
0
 /// <summary>
 /// 空 ISNULL
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public static WhereExpressionSQL IsNull(this WhereExpressionSQL where, string fieldName)
 {
     if (where == null)
     {
         return IsNull(fieldName);
     }
     return where.AddExpression(string.Format("{0} IS NULL", fieldName), new IDbDataParameter[0]);
 }
Example #4
0
 /// <summary>
 /// IN
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="type"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 public static WhereExpressionSQL In(this WhereExpressionSQL where, string fieldName, DbType type, params object[] values)
 {
     if (where == null)
     {
         return In(fieldName, type, values);
     }
     List<string> list = new List<string>();
     List<SqlParameter> list2 = new List<SqlParameter>();
     SqlParameter item = null;
     for (int i = 0; i < values.Length; i++)
     {
         item = CreateParameter(string.Format("{0}{1}", fieldName, i), DbTypeToSqlDbType(type), values[i]);
         list.Add(item.ParameterName);
         list2.Add(item);
     }
     where.AddExpression(string.Format("{0} IN({1})", fieldName, string.Join(",", list)), list2.ToArray());
     return where;
 }
Example #5
0
 /// <summary>
 /// 大于等于>=
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="type"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static WhereExpressionSQL GTE(this WhereExpressionSQL where, string fieldName, DbType type, object value)
 {
     if (where == null)
     {
         return GTE(fieldName, type, value);
     }
     SqlParameter parameter = CreateParameter(fieldName, DbTypeToSqlDbType(type), value);
     return where.AddExpression(string.Format("{0}>[email protected]{0}", fieldName), new IDbDataParameter[] { parameter });
 }
Example #6
0
 /// <summary>
 /// AND
 /// </summary>
 /// <param name="where"></param>
 /// <param name="expressions"></param>
 /// <returns></returns>
 public static WhereExpressionMySQL And(this WhereExpressionMySQL where, params WhereExpressionMySQL[] expressions)
 {
     if ((expressions == null) || (expressions.Length == 0))
     {
         return where;
     }
     if (where == null)
     {
         return And(expressions);
     }
     List<IDbDataParameter> list = new List<IDbDataParameter>();
     List<string> values = new List<string>();
     foreach (WhereExpressionMySQL expression in expressions)
     {
         list.AddRange(expression.GetParameters());
         values.Add(expression.GetExpression());
     }
     if (where.GetExpression() == string.Empty)
     {
         return where.AddExpression(string.Format(" {0}", string.Join(" AND ", values)), list.ToArray());
     }
     return where.AddExpression(string.Format(" AND {0}", string.Join(" AND ", values)), list.ToArray());
 }
Example #7
0
 /// <summary>
 /// 等于=
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="type"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static WhereExpressionSQL Equal(this WhereExpressionSQL where, string fieldName, DbType type, object value)
 {
     if (where == null)
     {
         return Equal(fieldName, type, value);
     }
     SqlParameter parameter = new SqlParameter
     {
         ParameterName = GetParameterName(fieldName),
         Value = value,
         SqlDbType = DbTypeToSqlDbType(type)
     };
     return where.AddExpression(string.Format("{0}={1}", fieldName, parameter.ParameterName), new IDbDataParameter[] { parameter });
 }
Example #8
0
 /// <summary>
 /// BETWEEN AND
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="type"></param>
 /// <param name="leftValue"></param>
 /// <param name="rightValue"></param>
 /// <returns></returns>
 public static WhereExpressionSQL Between(this WhereExpressionSQL where, string fieldName, DbType type, object leftValue, object rightValue)
 {
     if (where == null)
     {
         return Between(fieldName, type, leftValue, rightValue);
     }
     SqlParameter parameter = CreateParameter(string.Format("{0}LeftParameter", fieldName), DbTypeToSqlDbType(type), leftValue);
     SqlParameter parameter2 = CreateParameter(string.Format("{0}RightParameter", fieldName), DbTypeToSqlDbType(type), rightValue);
     return where.AddExpression(string.Format("{0} BETWEEN @{0}LeftParameter AND @{0}RightParameter", fieldName), new IDbDataParameter[] { parameter, parameter2 });
 }
Example #9
0
 /// <summary>
 /// 或 OR
 /// </summary>
 /// <param name="where"></param>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static WhereExpressionMySQL Or(this WhereExpressionMySQL where, WhereExpressionMySQL left, WhereExpressionMySQL right)
 {
     if (where == null)
     {
         return Or(left, right);
     }
     List<IDbDataParameter> list = new List<IDbDataParameter>();
     list.AddRange(left.GetParameters());
     list.AddRange(right.GetParameters());
     return where.AddExpression(string.Format("({0}) OR ({1})", left.GetExpression(), right.GetExpression()), list.ToArray());
 }
Example #10
0
 /// <summary>
 /// 不等于
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="type"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static WhereExpressionMySQL NotEqual(this WhereExpressionMySQL where, string fieldName, DbType type, object value)
 {
     if (where == null)
     {
         return NotEqual(fieldName, type, value);
     }
     MySqlParameter parameter = CreateParameter(fieldName, DbTypeToMySqlDbType(type), value);
     return where.AddExpression(string.Format("{0}<>{1}", fieldName, parameter.ParameterName), new IDbDataParameter[] { parameter });
 }
Example #11
0
 /// <summary>
 /// LIKE %% 全匹配
 /// </summary>
 /// <param name="where"></param>
 /// <param name="fieldName"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static WhereExpressionMySQL LikeFull(this WhereExpressionMySQL where, string fieldName, string value)
 {
     if (where == null)
     {
         return LikeFull(fieldName, value);
     }
     MySqlParameter parameter = CreateParameter(fieldName, MySqlDbType.VarChar, value);
     return where.AddExpression(string.Format("{0} LIKE CONCAT('%',{1},'%')", fieldName, parameter.ParameterName), new IDbDataParameter[] { parameter });
 }