static void validate(ISqlField field1, ComparisonOperator oper, ISqlField field2) { switch (oper) { case ComparisonOperator.IsNotNull: case ComparisonOperator.IsNull: if (field2 != null) { throw new InvalidOperationException("Field2 should be null for selected operator"); } break; case ComparisonOperator.Exists: case ComparisonOperator.NotExists: if (field2 != null) { throw new InvalidOperationException("Field2 should be null for selected operator"); } if (!(field1 is ISqlTable)) { throw new InvalidOperationException("Field2 should be query or table for selected operator"); } break; case ComparisonOperator.Between: case ComparisonOperator.NotBetween: if (!(field2 is BetweenField)) { throw new InvalidOperationException("Field2 should be BetweenField for selected operator"); } break; } }
private static IQueryExpression GetColumn(QueryData data, ISqlField field) { foreach (var query in data.Queries) { var q = query.Query; foreach (var table in q.From.Tables) { var t = FindField(field, table); if (t != null) { var n = q.Select.Columns.Count; var idx = q.Select.Add(field); if (n != q.Select.Columns.Count) { if (!q.GroupBy.IsEmpty || q.Select.Columns.Any(c => IsAggregationFunction(c.Expression))) { q.GroupBy.Items.AddLast(field); } } return(q.Select.Columns[idx]); } } } return(null); }
public Condition(ISqlField field1, ComparisonOperator oper, ISqlField field2 = null) { validate(field1, oper, field2); Field1 = field1; Field2 = field2; Operator = oper; }
public QueryBuilder Where(ISqlField field1, ComparisonOperator @operator, ISqlField field2 = null) { if (query.Where == null) { query.Where = new ConditionClause(field1, @operator, field2); } else { query.Where.OtherConditions.Add(new MoreCondition(LogicalOperator.And, field1, @operator, field2)); } return(this); }
public override int CommandCount(ISelectQuery selectQuery) { if (selectQuery.IsCreateTable) { _identityField = selectQuery.CreateTable.Table.Fields.Values.FirstOrDefault(f => f.IsIdentity); if (_identityField != null) { return(3); } } return(base.CommandCount(selectQuery)); }
public T ComparisonFilter <T>(string @operator, ISqlField sqlField) { if (sqlField == null) { throw new ArgumentNullException(nameof(sqlField)); } Func <SqlFilterConfiguration, SqlFilterParameter[]> args = config => new[] { SqlFilterParameter.Create(config, _sqlField), SqlFilterParameter.Create(config, sqlField) }; return(BuildFilter <T>("{0} " + @operator + " {1}", args)); }
public QueryBuilder InnerJoin(ISqlTable table, ISqlTable foreignTable, ISqlField localKey, ISqlField foreignKey) { var relation = new TableRelation { Table = table, ForeignTable = foreignTable, JoinType = TableJoinType.InnerJoin }; relation.LocalForeignKeys.Add(new LocalForeignKey(localKey, foreignKey)); query.JoinTables.Add(relation); return(this); }
private static ITableSource FindField(ISqlField field, ITableSource table) { if (field.Table == table.Source) { return(table); } return(table.Joins.ApplyUntilNonDefaultResult( node => { var t = FindField(field, node.Value.Table); return t != null ? node.Value.Table : null; })); }
protected override void BuildCreateTableFieldType(ISqlField field) { if (field.IsIdentity) { if (field.DataType == DataType.Int32) { StringBuilder.Append("SERIAL"); return; } if (field.DataType == DataType.Int64) { StringBuilder.Append("BIGSERIAL"); return; } } base.BuildCreateTableFieldType(field); }
public SqlField(ISqlField field) { SystemType = field.SystemType; Alias = field.Alias; Name = field.Name; PhysicalName = field.PhysicalName; Nullable = field.Nullable; IsPrimaryKey = field.IsPrimaryKey; PrimaryKeyOrder = field.PrimaryKeyOrder; IsIdentity = field.IsIdentity; IsInsertable = field.IsInsertable; IsUpdatable = field.IsUpdatable; DataType = field.DataType; DbType = field.DbType; Length = field.Length; Precision = field.Precision; Scale = field.Scale; CreateFormat = field.CreateFormat; ColumnDescriptor = field.ColumnDescriptor; }
public static SqlFilterParameter Create(SqlFilterConfiguration configuration, ISqlField sqlField) => new SqlFieldParameter(configuration, sqlField);
public SqlFieldParameter(SqlFilterConfiguration configuration, ISqlField sqlField) : base(configuration) { _sqlField = sqlField; }
public ConditionClause And(ISqlField field1, ComparisonOperator oper, ISqlField field2 = null) { OtherConditions.Add(new MoreCondition(LogicalOperator.And, field1, oper, field2)); return(this); }
public ConditionClause(ISqlField field1, ComparisonOperator oper, ISqlField field2 = null) { Condition = new Condition(field1, oper, field2); }
public TResult GreaterThanOrEqual(ISqlField field) => _sqlFilterBuilder.ComparisonFilter <TResult>(GREATER_THAN_OR_EQUAL_OPERATOR, field);
public MoreCondition(LogicalOperator logicalOperator, ISqlField field1, ComparisonOperator oper, ISqlField field2 = null) { LogicalOperator = logicalOperator; Condition = new Condition(field1, oper, field2); }
public TResult LessThanOrEqual(ISqlField field) => _sqlFilterBuilder.ComparisonFilter <TResult>(LESS_THAN_OR_EQUAL_OPERATOR, field);
internal SqlFilterField(ImmutableList <SqlFilterItemCallback> sqlFilterItems, ISqlField sqlField, Func <ImmutableList <SqlFilterItemCallback>, TResult> filterCreatorFunc) { _sqlField = sqlField; _sqlFilterBuilder = new SqlFilterBuilder <TEntity>(sqlFilterItems, sqlField, filterCreatorFunc); }
public IExpr <T1, T2> Field(ISqlField field) { return(Expr(field)); }
public QueryBuilder OrWhere(ISqlField field1, ComparisonOperator @operator, ISqlField field2 = null) { query.Where.OtherConditions.Add(new MoreCondition(LogicalOperator.Or, field1, @operator, field2)); return(this); }
public LocalForeignKey(ISqlField local, ISqlField foreign) { LocalKey = local; ForeignKey = foreign; }
public T BuildFilter <T>(string expression, ISqlField sqlField) => BuildFilter <T>(_sqlFilterItems.Add(config => new SqlFilterItem.SqlFilterItem(expression, SqlFilterParameter.Create(config, sqlField))));
public SelectField(ISqlField field, string alias = null) { Field = field; Alias = alias; }
public TResult NotEqualTo(ISqlField field) => _sqlFilterBuilder.ComparisonFilter <TResult>(NOT_EQUAL_OPERATOR, field);
public SortField(ISqlField field, bool desc = false) { Field = field; Descending = desc; }
public T2 Field(ISqlField field) { return(Expr(field)); }
public SqlFilterBuilder(ImmutableList <SqlFilterItemCallback> sqlFilterItems, ISqlField sqlField, Func <ImmutableList <SqlFilterItemCallback>, SqlFilterBase> filterCreatorFunc) { _sqlFilterItems = sqlFilterItems; _sqlField = sqlField; _filterCreatorFunc = filterCreatorFunc; }