示例#1
0
        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;
            }
        }
示例#2
0
        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);
        }
示例#3
0
        public Condition(ISqlField field1, ComparisonOperator oper, ISqlField field2 = null)
        {
            validate(field1, oper, field2);

            Field1   = field1;
            Field2   = field2;
            Operator = oper;
        }
示例#4
0
 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);
 }
示例#5
0
        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));
        }
示例#6
0
        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));
        }
示例#7
0
        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);
        }
示例#8
0
        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;
            }));
        }
示例#9
0
        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);
        }
示例#10
0
文件: SqlField.cs 项目: forki/bars2db
 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;
 }
示例#11
0
 public static SqlFilterParameter Create(SqlFilterConfiguration configuration, ISqlField sqlField)
 => new SqlFieldParameter(configuration, sqlField);
示例#12
0
 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);
 }
示例#15
0
 public TResult GreaterThanOrEqual(ISqlField field)
 => _sqlFilterBuilder.ComparisonFilter <TResult>(GREATER_THAN_OR_EQUAL_OPERATOR, field);
示例#16
0
 public MoreCondition(LogicalOperator logicalOperator, ISqlField field1, ComparisonOperator oper, ISqlField field2 = null)
 {
     LogicalOperator = logicalOperator;
     Condition       = new Condition(field1, oper, field2);
 }
示例#17
0
 public TResult LessThanOrEqual(ISqlField field)
 => _sqlFilterBuilder.ComparisonFilter <TResult>(LESS_THAN_OR_EQUAL_OPERATOR, field);
示例#18
0
 internal SqlFilterField(ImmutableList <SqlFilterItemCallback> sqlFilterItems, ISqlField sqlField,
                         Func <ImmutableList <SqlFilterItemCallback>, TResult> filterCreatorFunc)
 {
     _sqlField         = sqlField;
     _sqlFilterBuilder = new SqlFilterBuilder <TEntity>(sqlFilterItems, sqlField, filterCreatorFunc);
 }
示例#19
0
文件: Not.cs 项目: forki/bars2db
 public IExpr <T1, T2> Field(ISqlField field)
 {
     return(Expr(field));
 }
示例#20
0
 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;
 }
示例#22
0
 public T BuildFilter <T>(string expression, ISqlField sqlField)
 => BuildFilter <T>(_sqlFilterItems.Add(config
                                        => new SqlFilterItem.SqlFilterItem(expression, SqlFilterParameter.Create(config, sqlField))));
示例#23
0
 public SelectField(ISqlField field, string alias = null)
 {
     Field = field;
     Alias = alias;
 }
示例#24
0
 public TResult NotEqualTo(ISqlField field)
 => _sqlFilterBuilder.ComparisonFilter <TResult>(NOT_EQUAL_OPERATOR, field);
示例#25
0
 public SortField(ISqlField field, bool desc = false)
 {
     Field      = field;
     Descending = desc;
 }
示例#26
0
 public T2 Field(ISqlField field)
 {
     return(Expr(field));
 }
示例#27
0
 public SqlFilterBuilder(ImmutableList <SqlFilterItemCallback> sqlFilterItems, ISqlField sqlField, Func <ImmutableList <SqlFilterItemCallback>, SqlFilterBase> filterCreatorFunc)
 {
     _sqlFilterItems    = sqlFilterItems;
     _sqlField          = sqlField;
     _filterCreatorFunc = filterCreatorFunc;
 }