public WhereClip Or(ExpressionClip left, QueryOperator op, ExpressionClip right) { bool toWrapBrackets = false; string sqlStr = left.Sql; while (sqlStr.IndexOf("] [") > 0) sqlStr = sqlStr.Substring(sqlStr.IndexOf("] [") + 2); left.Sql = sqlStr; if (sql.Length > 0) { sql.Append(" OR "); toWrapBrackets = true; } this.sql.Append(SqlQueryUtils.ToString(left)); this.sql.Append(SqlQueryUtils.ToString(op)); this.sql.Append(SqlQueryUtils.ToString(right)); SqlQueryUtils.AddParameters(this.parameters, left); SqlQueryUtils.AddParameters(this.parameters, right); if (toWrapBrackets) this.sql = new StringBuilder("(" + this.sql.ToString() + ")"); return this; }
public virtual object Clone() { ExpressionClip newExpr = new ExpressionClip(); newExpr.dbType = this.dbType; string tempSql = this.sql.ToString(); Dictionary<string, KeyValuePair<DbType, object>>.Enumerator en = this.parameters.GetEnumerator(); while (en.MoveNext()) { object value = en.Current.Value.Value; if (value != null && value != DBNull.Value && value is ICloneable) { value = ((ICloneable)value).Clone(); } string newParamName = MakeUniqueParamNameWithoutPrefixToken(); tempSql = tempSql.Replace('@' + en.Current.Key.TrimStart("@:?".ToCharArray()), '@' + newParamName); newExpr.Parameters.Add('@' + newParamName, new KeyValuePair<DbType, object>(en.Current.Value.Key, value)); } newExpr.sql.Append(tempSql); return newExpr; }
public WhereClip NotIn(ExpressionClip subQuery) { Check.Require(!ExpressionClip.IsNullOrEmpty(subQuery), "subQuery could not be null or empty."); WhereClip where = new WhereClip(); where.Sql = string.Format("{0} NOT IN ({1})", this.ToString(), subQuery.ToString()); if (subQuery.Parameters.Count > 0) { Dictionary<string, KeyValuePair<DbType, object>>.Enumerator en = subQuery.Parameters.GetEnumerator(); while (en.MoveNext()) { where.Parameters.Add('@' + en.Current.Key.TrimStart("@:?".ToCharArray()), new KeyValuePair<DbType, object>(en.Current.Value.Key, en.Current.Value.Value)); } } return where; }
public ExpressionClip Append(QueryOperator op, ExpressionClip right) { this.sql.Append(SqlQueryUtils.ToString(op)); this.sql.Append(SqlQueryUtils.ToString(right)); SqlQueryUtils.AddParameters(this.parameters, right); return this; }
public ExpressionClip BitwiseXOr(ExpressionClip right) { ExpressionClip expr = (ExpressionClip)this.Clone(); expr.Append(QueryOperator.BitwiseXOR, right); return expr; }
public static bool IsNullOrEmpty(ExpressionClip expr) { return ((object)expr) == null || expr.sql.Length == 0; }
public static ExpressionClip GetCurrentUtcDate() { ExpressionClip expr = new ExpressionClip(); expr.Sql = ColumnFormatter.GetCurrentUtcDate(); expr.dbType = DbType.DateTime; return expr; }
public static ExpressionClip operator /(object left, ExpressionClip right) { ExpressionClip expr = new ExpressionClip(right.dbType, left); expr.Append(QueryOperator.Divide, right); return expr; }
public static ExpressionClip operator %(object left, ExpressionClip right) { ExpressionClip expr = new ExpressionClip(right.dbType, left); expr.Append(QueryOperator.Modulo, right); expr.dbType = DbType.Int32; return expr; }
public static ExpressionClip operator !(ExpressionClip left) { ExpressionClip expr = new ExpressionClip().Append(QueryOperator.BitwiseNOT, left); return expr; }