/// <summary> /// Initializes a new instance of the <see cref="Criteria"/> class /// containing an expression like "alias.field". /// </summary> /// <param name="alias">The alias.</param> /// <param name="field">The field.</param> /// <exception cref="ArgumentNullException"> /// Field or alias is null or empty string. /// </exception> public Criteria(string alias, string field) { if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } if (string.IsNullOrEmpty(alias)) { throw new ArgumentNullException("alias"); } expression = alias + "." + SqlSyntax.AutoBracketValid(field); }
/// <summary> /// Initializes a new instance of the <see cref="Criteria"/> class /// containing an expression like "tjoinnumber.field" (t7.field). /// </summary> /// <param name="joinNumber">The join number.</param> /// <param name="field">The field.</param> /// <exception cref="ArgumentNullException">field is null or empty</exception> /// <exception cref="ArgumentOutOfRangeException">joinNumber is less than zero</exception> public Criteria(int joinNumber, string field) { if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } if (joinNumber < 0) { throw new ArgumentOutOfRangeException("joinNumber"); } expression = joinNumber.TableAliasDot() + SqlSyntax.AutoBracketValid(field); }
/// <summary> /// Adds a table to the FROM statement. When it is called more than once, puts a comma /// between table names (cross join) /// </summary> /// <param name="table">Table name</param> /// <returns>The query itself.</returns> public SqlQuery From(string table) { if (string.IsNullOrEmpty(table)) { throw new ArgumentNullException("table"); } if (from.Length > 0) { from.Append(", "); } from.Append(SqlSyntax.AutoBracketValid(table)); return(this); }
/// <summary> /// Formats a DELETE query.</summary> /// <param name="tableName"> /// Tablename.</param> /// <param name="where"> /// Where part of the query.</param> /// <returns> /// Formatted query.</returns> public static string Format(string tableName, string where) { if (tableName == null || tableName.Length == 0) { throw new ArgumentNullException(tableName); } StringBuilder sb = new StringBuilder("DELETE FROM ", 24 + where.Length); sb.Append(SqlSyntax.AutoBracketValid(tableName)); if (!string.IsNullOrEmpty(where)) { sb.Append(" WHERE "); sb.Append(where); } return(sb.ToString()); }
/// <summary> /// Formats an INSERT query.</summary> /// <param name="tableName"> /// Tablename (required).</param> /// <param name="nameValuePairs"> /// Field names and values. Must be passed in the order of <c>[field1, value1, field2, /// value2, ...., fieldN, valueN]</c>. It must have even number of elements.</param> /// <returns> /// Formatted query.</returns> public static string Format(string tableName, List <string> nameValuePairs) { if (tableName == null || tableName.Length == 0) { throw new ArgumentNullException(tableName); } if (nameValuePairs == null) { throw new ArgumentNullException("nameValuePairs"); } if (nameValuePairs.Count % 2 != 0) { throw new ArgumentOutOfRangeException("nameValuePairs"); } StringBuilder sb = new StringBuilder("INSERT INTO ", 64 + nameValuePairs.Count * 16); sb.Append(SqlSyntax.AutoBracketValid(tableName)); sb.Append(" ("); for (int i = 0; i < nameValuePairs.Count; i += 2) { if (i > 0) { sb.Append(", "); } sb.Append(SqlSyntax.AutoBracket(nameValuePairs[i])); } sb.Append(") VALUES ("); for (int i = 1; i < nameValuePairs.Count; i += 2) { if (i > 1) { sb.Append(", "); } sb.Append(nameValuePairs[i]); } sb.Append(')'); return(sb.ToString()); }
private void JoinToString(Join join, StringBuilder sb, bool modifySelf) { sb.Append(join.GetKeyword()); sb.Append(' '); sb.Append(SqlSyntax.AutoBracketValid(join.Table)); // joinAlias belirtilmişse ekle if (!string.IsNullOrEmpty(join.Name)) { sb.Append(' '); sb.Append(join.Name); } if (join.OnCriteria is object && !join.OnCriteria.IsEmpty) { sb.Append(" ON "); if (!(join.OnCriteria is BinaryCriteria)) { sb.Append('('); } if (modifySelf) { sb.Append(join.OnCriteria.ToString(this)); } else { sb.Append(join.OnCriteria.ToStringIgnoreParams()); } if (!(join.OnCriteria is BinaryCriteria)) { sb.Append(')'); } } }