/// <param name="fields">要更新的字段</param> /// <param name="union">条件语句中的unoin关键字 比如 OR 或 AND</param> /// <param name="operation">条件语句中的操作符 比如 = 或 like</param> /// <param name="conditionFields">条件字段</param> public void Update(SQLField[] fields, SQLUnion union, SQLOperation operation, params SQLField[] conditionFields) { if ((fields == null || fields.Length <= 0) || IsCountAndValueEmpty(conditionFields)) { return; } SQLStatement statement = new SQLStatement(GetTableName()); statement.UpateFields(fields).AddConditions(operation, union, conditionFields); Upate(statement); }
/// <param name="union">条件语句中的unoin关键字 比如 OR 或 AND</param> public void Delete(SQLField[] fields, SQLUnion union, SQLOperation operation = SQLOperation.EQUAL) { if (fields == null) { return; } SQLStatement statement = new SQLStatement(GetTableName()); statement.AddConditions(operation, union, fields); Delete(statement); }
/// <returns>返回多条查询结果 每条结果包含多个字段的值</returns> /// <param name="fieldNames">要查询的字段名</param> /// <param name="union">条件语句中的unoin关键字 比如 OR 或 AND</param> /// <param name="operation">条件语句中的操作符 比如 = 或 like</param> /// <param name="conditionFields">条件字段</param> public List <SQLField[]> Query(string[] fieldNames, SQLUnion union, SQLOperation operation, params SQLField[] conditionFields) { if (fieldNames == null || fieldNames.Length <= 0) { return(null); } SQLStatement statement = new SQLStatement(GetTableName()); statement.SelectFields(fieldNames); if (!IsCountAndValueEmpty(conditionFields)) { statement.AddConditions(operation, union, conditionFields); } return(Query(statement)); }
public virtual string SerializeUnionType(SQLUnion.Type type) { switch (type) { case SQLUnion.Type.Distinct: return "UNION"; case SQLUnion.Type.All: return "UNION ALL"; default: throw new NotImplementedException(type.ToString()); } }
public virtual string SerializeUnion(SQLUnion union) { if (union.SelectStatements.Count() < 2) throw new Exceptions.DatabaseObjectsException("The select statements have not been set"); var tokens = new TokenSerializer(); int index = 0; foreach (var statement in union.SelectStatements) { if (index > 0) tokens.Add(SerializeUnionType(union.UnionTypes[index - 1])); tokens.Add("(" + SerializeSelect(statement) + ")"); index++; } if (union.OrderBy != null && !union.OrderBy.IsEmpty) { tokens.Add("ORDER BY"); tokens.Add(SerializeSelectOrderByFields(union.OrderBy)); } return tokens.ToString(); }
//添加条件语句 public SQLStatement AddConditions(SQLOperation operation, SQLUnion union, params SQLField[] fields) { if (fields != null) { string unionStatement; switch (union) { case SQLUnion.OR: unionStatement = " OR "; break; case SQLUnion.AND: unionStatement = " AND "; break; default: unionStatement = ""; break; } string operateStatement; switch (operation) { case SQLOperation.BETWEEN: operateStatement = " BETWEEN "; break; case SQLOperation.LIKE: operateStatement = " LIKE "; break; case SQLOperation.UNEQUAL: operateStatement = " <> "; break; case SQLOperation.GREATER: operateStatement = " > "; break; case SQLOperation.LESS: operateStatement = " < "; break; case SQLOperation.GREATER_EQUAL: operateStatement = " >= "; break; case SQLOperation.LESS_EQUAL: operateStatement = " <= "; break; default: operateStatement = " = "; break; } for (int i = 0; i < fields.Length; i++) { if (!string.IsNullOrEmpty(conditions.ToString())) { conditions.Append(unionStatement); } conditions.Append(fields[i].name); conditions.Append(operateStatement); if (operation == SQLOperation.LIKE) { conditions.Append("'%"); } else { conditions.Append("'"); } conditions.Append(fields[i].value); if (operation == SQLOperation.LIKE) { conditions.Append("%'"); } else { conditions.Append("'"); } } } return(this); }
public List <SQLField[]> Query(string fieldName, SQLUnion union, params SQLField[] conditionFields) { return(Query(fieldName, union, SQLOperation.EQUAL, conditionFields)); }
public List <SQLField[]> Query(string fieldName, SQLUnion union, SQLOperation operation, params SQLField[] conditionFields) { return(Query(new string[] { fieldName }, union, operation, conditionFields)); }
public void Update(SQLField field, SQLUnion union, params SQLField[] conditionFields) { Update(field, union, SQLOperation.EQUAL, conditionFields); }
public void Update(SQLField field, SQLUnion union, SQLOperation operation, params SQLField[] conditionFields) { Update(new SQLField[] { field }, union, operation, conditionFields); }