public override ISqlExpression GetIdentityExpression(SqlTable table, SqlField identityField, bool forReturning) { if (table.SequenceAttributes != null) return new SqlExpression("GEN_ID(" + table.SequenceAttributes[0].SequenceName + ", 1)", Precedence.Primary); return base.GetIdentityExpression(table, identityField, forReturning); }
public override int CommandCount(SelectQuery selectQuery) { if (Version == DB2Version.LUW && selectQuery.IsInsert && selectQuery.Insert.WithIdentity) { _identityField = selectQuery.Insert.Into.GetIdentityField(); if (_identityField == null) return 2; } return 1; }
public override ISqlExpression GetIdentityExpression(SqlTable table, SqlField identityField, bool forReturning) { if (table.SequenceAttributes != null) { var attr = GetSequenceNameAttribute(table, false); if (attr != null) return new SqlExpression(attr.SequenceName + ".nextval", Precedence.Primary); } return base.GetIdentityExpression(table, identityField, forReturning); }
public override int CommandCount(SqlQuery sqlQuery) { if (sqlQuery.IsInsert && sqlQuery.Insert.WithIdentity) { _identityField = sqlQuery.Insert.Into.GetIdentityField(); if (_identityField == null) return 2; } return 1; }
public override int CommandCount(SelectQuery selectQuery) { if (selectQuery.IsCreateTable) { _identityField = selectQuery.CreateTable.Table.Fields.Values.FirstOrDefault(f => f.IsIdentity); if (_identityField != null) return 3; } return base.CommandCount(selectQuery); }
public Address() { party_id = new SqlField("party_id", SqlDbType.BigInt); address_format_type_cd_id = new SqlField("address_format_type_cd_id", SqlDbType.BigInt, isNullable: true); address_type_cd_id = new SqlField("address_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.ADDRESS_TYPE); attention = new SqlField("attention", SqlDbType.VarChar, isNullable: true, maxLength: 50); city = new SqlField("city", SqlDbType.VarChar, isNullable: true, maxLength: 30); country = new SqlField("country", SqlDbType.VarChar, isNullable: true, maxLength: 30); county = new SqlField("county", SqlDbType.VarChar, isNullable: true, maxLength: 50); postal_code = new SqlField("postal_code", SqlDbType.VarChar, isNullable: true, maxLength: 10); state = new SqlField("state", SqlDbType.VarChar, isNullable: true, maxLength: 50); street_3 = new SqlField("street_3", SqlDbType.VarChar, isNullable: true, maxLength: 50); street_aux = new SqlField("street_aux", SqlDbType.VarChar, isNullable: true, maxLength: 50); street_main = new SqlField("street_main", SqlDbType.VarChar, isNullable: true, maxLength: 50); usage_cd_id = new SqlField("usage_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.ADDRESS_USAGE); }
protected override void BuildCreateTableFieldType(SqlField field) { if (field.IsIdentity) { if (field.DataType == DataType.Int32) { StringBuilder.Append("SERIAL"); return; } if (field.DataType == DataType.Int64) { StringBuilder.Append("SERIAL8"); return; } } base.BuildCreateTableFieldType(field); }
public void From_GenericSqlField_Success() { var filter = SqlFilter <Person> .From(SqlField <Person> .From(m => m.Id)).EqualTo(5); Assert.Equal("pe.Id = 5", filter.RawSql); }
public Business_unit_payment_processor() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); payment_processor_id = new SqlField("payment_processor_id", SqlDbType.BigInt); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); payment_method_cd_id = new SqlField("payment_method_cd_id", SqlDbType.BigInt, isNullable: true); start_date = new SqlField("start_date", SqlDbType.DateTime, isNullable: true); }
public Business_unit_order_comment() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); comment_cd_id = new SqlField("comment_cd_id", SqlDbType.BigInt); end_date = new SqlField("end_date", SqlDbType.DateTime); start_date = new SqlField("start_date", SqlDbType.DateTime); display_order = new SqlField("display_order", SqlDbType.SmallInt, isNullable: true); order_processing_location_cd_id = new SqlField("order_processing_location_cd_id", SqlDbType.BigInt, isNullable: true); override_template_id = new SqlField("override_template_id", SqlDbType.BigInt, isNullable: true); }
public Business_unit_correspondence_reason() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); correspondence_reason_cd_id = new SqlField("correspondence_reason_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.CORRESPONDENCE_REASON); end_date = new SqlField("end_date", SqlDbType.DateTime); start_date = new SqlField("start_date", SqlDbType.DateTime); display_order = new SqlField("display_order", SqlDbType.SmallInt, isNullable: true); order_processing_location_cd_id = new SqlField("order_processing_location_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.ORDER_PLACEMENT_LOCATION); override_template_id = new SqlField("override_template_id", SqlDbType.BigInt, isNullable: true); }
public static SqlFilterField <TEntity, TFieldType, SqlFilter <TEntity> > From <TFieldType>(SqlField <TEntity, TFieldType> field) { return(CreateField <TFieldType>(ImmutableList <SqlFilterItemCallback> .Empty, field)); }
public TResult LessThanOrEqual <TRight>(SqlField <TRight, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(LESS_THAN_OR_EQUAL_OPERATOR, field);
protected override void BuildCreateTableIdentityAttribute2(SqlField field) { StringBuilder.Append("PRIMARY KEY AUTOINCREMENT"); }
public TResult GreaterThanOrEqual <TRight>(SqlField <TRight, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(GREATER_THAN_OR_EQUAL_OPERATOR, field);
public TResult LessThan(SqlField <TEntity, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(LESS_THAN_OPERATOR, field);
public TResult GreaterThan(SqlField <TEntity, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(GREATER_THAN_OPERATOR, field);
public T2 Field(SqlField field) { return(Expr(field)); }
public Expr_ Field(SqlField field) { return(Expr(field)); }
public SqlInfo[] ConvertToSql(Expression?expression, int level, ConvertFlags flags) { if (expression == null) { var query = SelectQuery; var sql = SelectQuery.Select.Columns[0]; if (Parent != null) { query = Parent.SelectQuery; } return(new[] { new SqlInfo { Query = query, Sql = sql } }); } switch (flags) { case ConvertFlags.Field: { if (expression.NodeType == ExpressionType.MemberAccess) { var memberExpression = (MemberExpression)expression; foreach (var column in _entityDescriptor.Columns) { if (column.MemberInfo.EqualsTo(memberExpression.Member, _elementType)) { if (!Table.Fields.TryGetValue(column.MemberInfo.Name, out var newField)) { newField = new SqlField(column); Table.Add(newField); for (var i = 0; i < _records.Count; i++) { object value; if (column.MemberInfo.IsPropertyEx()) { value = ((PropertyInfo)column.MemberInfo).GetValue(_records[i].Value); } else if (column.MemberInfo.IsFieldEx()) { value = ((FieldInfo)column.MemberInfo).GetValue(_records[i].Value); } else { throw new InvalidOperationException(); } var valueExpr = Expression.Constant(value, column.MemberType); var expr = Builder.ConvertToSqlExpression(Parent !, valueExpr); if (expr is SqlParameter p) { // avoid parameters is source, because their number is limited p.IsQueryParameter = !Builder.MappingSchema.ValueToSqlConverter.CanConvert(p.Type.SystemType); p.Type = p.Type.WithoutSystemType(column); } else if (expr is SqlValue val) { val.ValueType = val.ValueType.WithoutSystemType(column); } Table.Rows[i].Add(expr); } } return(new[] { new SqlInfo(column.MemberInfo) { Sql = newField, Query = SelectQuery } }); } } } break; } } throw new NotImplementedException(); }
public TResult EqualTo(SqlField <TEntity, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(EQUAL_OPERATOR, field);
protected override void BuildCreateTableIdentityAttribute1(SqlField field) { StringBuilder.Append("IDENTITY"); }
protected override void BuildCreateTableIdentityAttribute1(SqlField field) { StringBuilder.Append("GENERATED BY DEFAULT AS IDENTITY"); }
public SqlFilterField <TEntity, TFieldType, SqlFilter <TEntity> > Or <TFieldType>(SqlField <TEntity, TFieldType> field) { return(CreateField <TFieldType>(AddItem(SqlFilterItems.Or), field)); }
public Business_unit_close_method() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); close_method_cd_id = new SqlField("close_method_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.EOD_CLOSE_METHOD); display_index = new SqlField("display_index", SqlDbType.SmallInt, isNullable: true); }
public TResult NotEqualTo <TRight>(SqlField <TRight, TFieldType> field) => _sqlFilterBuilder.ComparisonFilter <TResult>(NOT_EQUAL_OPERATOR, field);
static ExpressionInfo <TR> .Parameter GetParameter <TR>(DbManager dataContext, SqlField field) { var exprParam = Expression.Parameter(typeof(Expression), "expr"); var mapper = Expression.Lambda <Func <ExpressionInfo <TR>, Expression, object[], object> >( Expression.Convert( Expression.PropertyOrField( Expression.Convert( Expression.Property( Expression.Convert(exprParam, typeof(ConstantExpression)), Constant.Value), typeof(T)), field.Name), typeof(object)), new [] { Expression.Parameter(typeof(ExpressionInfo <TR>), "info"), exprParam, Expression.Parameter(typeof(object[]), "ps") }); var param = new ExpressionInfo <TR> .Parameter { Expression = null, Accessor = mapper.Compile(), SqlParameter = new SqlParameter(field.SystemType, field.Name, null) }; if (field.SystemType.IsEnum) { var ms = dataContext.MappingSchema; var tp = field.SystemType; param.SqlParameter.ValueConverter = o => ms.MapEnumToValue(o, tp); } return(param); }
public override QueryField GetField(SqlField field) { return(EnsureField(base.GetField(field))); }
SqlValuesTable BuildValuesTableFromArray(NewArrayExpression arrayExpression) { if (Builder.MappingSchema.IsScalarType(_elementType)) { var rows = arrayExpression.Expressions.Select(e => new[] { Builder.ConvertToSql(Parent, e) }).ToList(); var field = new SqlField(Table, "item"); return(new SqlValuesTable(new[] { field }, null, rows)); } var knownMembers = new HashSet <MemberInfo>(); foreach (var row in arrayExpression.Expressions) { var members = new Dictionary <MemberInfo, Expression>(); Builder.ProcessProjection(members, row); knownMembers.AddRange(members.Keys); } var ed = Builder.MappingSchema.GetEntityDescriptor(_elementType); var builtRows = new List <ISqlExpression[]>(arrayExpression.Expressions.Count); var columnsInfo = knownMembers.Select(m => (Member: m, Column: ed.Columns.Find(c => c.MemberInfo == m))) .ToList(); foreach (var row in arrayExpression.Expressions) { var members = new Dictionary <MemberInfo, Expression>(); Builder.ProcessProjection(members, row); var rowValues = new ISqlExpression[columnsInfo.Count]; var idx = 0; foreach (var(member, column) in columnsInfo) { ISqlExpression sql; if (members.TryGetValue(member, out var accessExpr)) { sql = Builder.ConvertToSql(Parent, accessExpr, columnDescriptor: column); } else { var nullValue = Expression.Constant(Builder.MappingSchema.GetDefaultValue(_elementType), _elementType); sql = Builder.ConvertToSql(Parent, nullValue, columnDescriptor: column); } rowValues[idx] = sql; ++idx; } builtRows.Add(rowValues); } var fields = new SqlField[columnsInfo.Count]; for (var index = 0; index < columnsInfo.Count; index++) { var(member, column) = columnsInfo[index]; var field = column != null ? new SqlField(column) : new SqlField(member.GetMemberType(), "item" + (index + 1), true); fields[index] = field; } return(new SqlValuesTable(fields, columnsInfo.Select(ci => ci.Member).ToArray(), builtRows)); }
public Business_unit_connect_info() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); ftp_folder = new SqlField("ftp_folder", SqlDbType.VarChar, isNullable: true, maxLength: 100); ftp_password = new SqlField("ftp_password", SqlDbType.VarChar, isNullable: true, maxLength: 128); ftp_user = new SqlField("ftp_user", SqlDbType.VarChar, isNullable: true, maxLength: 50); gpg_options = new SqlField("gpg_options", SqlDbType.VarChar, isNullable: true, maxLength: 50); gpgp_key_name = new SqlField("gpgp_key_name", SqlDbType.VarChar, isNullable: true, maxLength: 50); is_ftp_s = new SqlField("is_ftp_s", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); postback_password = new SqlField("postback_password", SqlDbType.VarChar, isNullable: true, maxLength: 128); postback_url = new SqlField("postback_url", SqlDbType.VarChar, isNullable: true, maxLength: 1000); postback_user = new SqlField("postback_user", SqlDbType.VarChar, isNullable: true, maxLength: 50); server_name = new SqlField("server_name", SqlDbType.VarChar, isNullable: true, maxLength: 50); share_name = new SqlField("share_name", SqlDbType.VarChar, isNullable: true, maxLength: 100); }
public SqlInfo[] ConvertToSql(Expression?expression, int level, ConvertFlags flags) { if (expression == null) { var query = SelectQuery; var sql = SelectQuery.Select.Columns[0]; if (Parent != null) { query = Parent.SelectQuery; } return(new[] { new SqlInfo(sql, query) }); } switch (flags) { case ConvertFlags.Field: { if (expression.NodeType == ExpressionType.MemberAccess) { var memberExpression = (MemberExpression)expression; foreach (var column in _entityDescriptor.Columns) { if (column.MemberInfo.EqualsTo(memberExpression.Member, _elementType)) { if (!Table.FieldsLookup !.TryGetValue(column.MemberInfo.Name, out var newField)) { Table.Add(newField = new SqlField(column), (record, parameters) => { // TODO: improve this place to avoid closures object?value; if (column.MemberInfo.IsPropertyEx()) { value = ((PropertyInfo)column.MemberInfo).GetValue(record); } else if (column.MemberInfo.IsFieldEx()) { value = ((FieldInfo)column.MemberInfo).GetValue(record); } else { throw new InvalidOperationException(); } var valueExpr = Expression.Constant(value, column.MemberType); if (parameters.TryGetValue(valueExpr, out var parameter)) { return(parameter); } // TODO: parameter accessor is overkill here for disposable parameter // we need method to create parameter value directly with all conversions var sql = Builder.ConvertToSqlExpression(Parent !, valueExpr, column, false); if (sql is SqlParameter p) { p.IsQueryParameter = !Builder.MappingSchema.ValueToSqlConverter.CanConvert(p.Type.SystemType); foreach (var pa in Builder._parameters.Values) { if (pa.SqlParameter == p) { // Mimic QueryRunner.SetParameters p.Value = pa.ValueAccessor(Builder.Expression, Builder.DataContext, null); var dbDataType = pa.DbDataTypeAccessor(Builder.Expression, Builder.DataContext, null); p.Type = p.Type.WithSetValues(dbDataType); break; } } } parameters.Add(valueExpr, sql); return(sql); }); }
public Business_unit_merchant_number() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); is_card_present = new SqlField("is_card_present", SqlDbType.Char, maxLength: 1, isFlag: true); start_date = new SqlField("start_date", SqlDbType.DateTime); visa_mastercard_id = new SqlField("visa_mastercard_id", SqlDbType.VarChar, maxLength: 20); amex_id = new SqlField("amex_id", SqlDbType.VarChar, isNullable: true, maxLength: 20); discover_id = new SqlField("discover_id", SqlDbType.VarChar, isNullable: true, maxLength: 20); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); is_tax_number = new SqlField("is_tax_number", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); is_vcfee_tax_number = new SqlField("is_vcfee_tax_number", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); provider_id = new SqlField("provider_id", SqlDbType.VarChar, isNullable: true, maxLength: 5); }
protected override void BuildCreateTableIdentityAttribute1(SqlField field) => StringBuilder.Append("GENERATED ALWAYS AS IDENTITY");
public Business_unit_parameters() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); parameter_name = new SqlField("parameter_name", SqlDbType.VarChar, maxLength: 255); parameter_value = new SqlField("parameter_value", SqlDbType.VarChar, isNullable: true, maxLength: 255); }
public Business_unit_pos_terminal() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); start_date = new SqlField("start_date", SqlDbType.DateTime); term_type_cd_id = new SqlField("term_type_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.TERMINAL_TYPE); terminal_name = new SqlField("terminal_name", SqlDbType.VarChar, maxLength: 15); authentication_code = new SqlField("authentication_code", SqlDbType.VarChar, isNullable: true, maxLength: 50); check_reader_type_cd_id = new SqlField("check_reader_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.CHECK_READER_TYPE); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); generated_auth_key = new SqlField("generated_auth_key", SqlDbType.VarChar, isNullable: true, maxLength: 50); group_name = new SqlField("group_name", SqlDbType.VarChar, isNullable: true, maxLength: 30); last_check_number = new SqlField("last_check_number", SqlDbType.BigInt, isNullable: true); last_report_time = new SqlField("last_report_time", SqlDbType.DateTime, isNullable: true); pinpad_type_cd_id = new SqlField("pinpad_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.POS_PINPAD_TYPE); terminal_alias = new SqlField("terminal_alias", SqlDbType.VarChar, isNullable: true, maxLength: 50); terminal_connection_type_cd_id = new SqlField("terminal_connection_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.NETWORK_CONNECTION_TYPE); }
internal static ParameterAccessor GetParameter(Type type, IDataContext dataContext, SqlField field) { var exprParam = Expression.Parameter(typeof(Expression), "expr"); Expression getter = Expression.Convert( Expression.Property( Expression.Convert(exprParam, typeof(ConstantExpression)), ReflectionHelper.Constant.Value), type); var descriptor = field.ColumnDescriptor; var dbValueLambda = descriptor.GetDbParamLambda(); Expression?valueGetter; Expression?dbDataTypeExpression; valueGetter = InternalExtensions.ApplyLambdaToExpression(dbValueLambda, getter); if (typeof(DataParameter).IsSameOrParentOf(valueGetter.Type)) { dbDataTypeExpression = Expression.Call(Expression.Constant(field.ColumnDescriptor.GetDbDataType(false)), DbDataType.WithSetValuesMethodInfo, Expression.PropertyOrField(valueGetter, nameof(DataParameter.DbDataType))); valueGetter = Expression.PropertyOrField(valueGetter, nameof(DataParameter.Value)); } else { var dbDataType = field.ColumnDescriptor.GetDbDataType(true).WithSystemType(valueGetter.Type); dbDataTypeExpression = Expression.Constant(dbDataType); } var param = ExpressionBuilder.CreateParameterAccessor( dataContext, valueGetter, getter, dbDataTypeExpression, valueGetter, exprParam, Expression.Parameter(typeof(object[]), "ps"), Expression.Parameter(typeof(IDataContext), "ctx"), field.Name.Replace('.', '_')); return(param); }
public VirtualField([NotNull] SqlField field) { Field = field ?? throw new ArgumentNullException(nameof(field)); }
public Rule() { rule_name = new SqlField("rule_name", SqlDbType.VarChar, maxLength: 100); rule_type_cd_id = new SqlField("rule_type_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.RULE_TYPE); run_location_cd_id = new SqlField("run_location_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.RULE_RUN_LOCATION); is_exclude_from_cache = new SqlField("is_exclude_from_cache", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); rule_class = new SqlField("rule_class", SqlDbType.VarChar, isNullable: true, maxLength: 255); rule_display_name = new SqlField("rule_display_name", SqlDbType.VarChar, isNullable: true, maxLength: 256); trigger_cd_id = new SqlField("trigger_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.RULE_TYPE); }
protected override void BuildCreateTableIdentityAttribute1(SqlField field) { StringBuilder.Append("AUTO_INCREMENT"); }
public override QueryField GetField(SqlField field) { return(OriginalQuery.GetField(field)); }
private IQueryElement ConvertInternal(IQueryElement element, Func <IQueryElement, IQueryElement> action) { if (element == null) { return(null); } IQueryElement newElement; if (_visitedElements.TryGetValue(element, out newElement)) { return(newElement); } switch (element.ElementType) { case EQueryElementType.SqlFunction: { var func = (ISqlFunction)element; var parms = Convert(func.Parameters, action); if (parms != null && !ReferenceEquals(parms, func.Parameters)) { newElement = new SqlFunction(func.SystemType, func.Name, func.Precedence, parms); } break; } case EQueryElementType.SqlExpression: { var expr = (ISqlExpression)element; var parameter = Convert(expr.Parameters, action); if (parameter != null && !ReferenceEquals(parameter, expr.Parameters)) { newElement = new SqlExpression(expr.SystemType, expr.Expr, expr.Precedence, parameter); } break; } case EQueryElementType.SqlBinaryExpression: { var bexpr = (ISqlBinaryExpression)element; var expr1 = (IQueryExpression)ConvertInternal(bexpr.Expr1, action); var expr2 = (IQueryExpression)ConvertInternal(bexpr.Expr2, action); if (expr1 != null && !ReferenceEquals(expr1, bexpr.Expr1) || expr2 != null && !ReferenceEquals(expr2, bexpr.Expr2)) { newElement = new SqlBinaryExpression(bexpr.SystemType, expr1 ?? bexpr.Expr1, bexpr.Operation, expr2 ?? bexpr.Expr2, bexpr.Precedence); } break; } case EQueryElementType.SqlTable: { var table = (ISqlTable)element; var fields1 = ToArray(table.Fields); var fields2 = Convert(fields1, action, f => new SqlField(f)); var targs = table.TableArguments == null ? null : Convert(table.TableArguments, action); var fe = fields2 == null || ReferenceEquals(fields1, fields2); var ta = ReferenceEquals(table.TableArguments, targs); if (!fe || !ta) { if (fe) { fields2 = fields1; for (var i = 0; i < fields2.Length; i++) { var field = fields2[i]; fields2[i] = new SqlField(field); _visitedElements[field] = fields2[i]; } } newElement = new SqlTable(table, fields2, targs ?? table.TableArguments); } break; } case EQueryElementType.Column: { var col = (IColumn)element; var expr = (IQueryExpression)ConvertInternal(col.Expression, action); IQueryElement parent; _visitedElements.TryGetValue(col.Parent, out parent); if (parent != null || expr != null && !ReferenceEquals(expr, col.Expression)) { newElement = new Column(parent == null ? col.Parent : (ISelectQuery)parent, expr ?? col.Expression, col.Alias); } break; } case EQueryElementType.TableSource: { var table = (ITableSource)element; var source = (ISqlTableSource)ConvertInternal(table.Source, action); var joins = Convert(table.Joins, action); if (source != null && !ReferenceEquals(source, table.Source) || joins != null && !ReferenceEquals(table.Joins, joins)) { newElement = new TableSource(source ?? table.Source, table.Alias, joins ?? table.Joins); } break; } case EQueryElementType.JoinedTable: { var join = (IJoinedTable)element; var table = (ITableSource)ConvertInternal(join.Table, action); var cond = (ISearchCondition)ConvertInternal(join.Condition, action); if (table != null && !ReferenceEquals(table, join.Table) || cond != null && !ReferenceEquals(cond, join.Condition)) { newElement = new JoinedTable(join.JoinType, table ?? join.Table, join.IsWeak, cond ?? join.Condition); } break; } case EQueryElementType.SearchCondition: { var sc = (ISearchCondition)element; var conds = Convert(sc.Conditions, action); if (conds != null && !ReferenceEquals(sc.Conditions, conds)) { newElement = new SearchCondition(conds); } break; } case EQueryElementType.Condition: { var c = (Condition)element; var p = (ISqlPredicate)ConvertInternal(c.Predicate, action); if (p != null && !ReferenceEquals(c.Predicate, p)) { newElement = new Condition(c.IsNot, p, c.IsOr); } break; } case EQueryElementType.ExprPredicate: { var p = (IExpr)element; var e = (IQueryExpression)ConvertInternal(p.Expr1, action); if (e != null && !ReferenceEquals(p.Expr1, e)) { newElement = new Expr(e, p.Precedence); } break; } case EQueryElementType.NotExprPredicate: { var p = (INotExpr)element; var e = (IQueryExpression)ConvertInternal(p.Expr1, action); if (e != null && !ReferenceEquals(p.Expr1, e)) { newElement = new NotExpr(e, p.IsNot, p.Precedence); } break; } case EQueryElementType.ExprExprPredicate: { var p = (IExprExpr)element; var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action); var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action); if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2)) { newElement = new ExprExpr(e1 ?? p.Expr1, p.EOperator, e2 ?? p.Expr2); } break; } case EQueryElementType.LikePredicate: { var p = (ILike)element; var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action); var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action); var es = (IQueryExpression)ConvertInternal(p.Escape, action); if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2) || es != null && !ReferenceEquals(p.Escape, es)) { newElement = new Like(e1 ?? p.Expr1, p.IsNot, e2 ?? p.Expr2, es ?? p.Escape); } break; } case EQueryElementType.HierarhicalPredicate: { var p = (IHierarhicalPredicate)element; var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action); var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action); if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2)) { newElement = new HierarhicalPredicate(e1 ?? p.Expr1, e2 ?? p.Expr2, p.Flow); } break; } case EQueryElementType.BetweenPredicate: { var p = (IBetween)element; var e1 = (IQueryExpression)ConvertInternal(p.Expr1, action); var e2 = (IQueryExpression)ConvertInternal(p.Expr2, action); var e3 = (IQueryExpression)ConvertInternal(p.Expr3, action); if (e1 != null && !ReferenceEquals(p.Expr1, e1) || e2 != null && !ReferenceEquals(p.Expr2, e2) || e3 != null && !ReferenceEquals(p.Expr3, e3)) { newElement = new Between(e1 ?? p.Expr1, p.IsNot, e2 ?? p.Expr2, e3 ?? p.Expr3); } break; } case EQueryElementType.IsNullPredicate: { var p = (IIsNull)element; var e = (IQueryExpression)ConvertInternal(p.Expr1, action); if (e != null && !ReferenceEquals(p.Expr1, e)) { newElement = new IsNull(e, p.IsNot); } break; } case EQueryElementType.InSubQueryPredicate: { var p = (IInSubQuery)element; var e = (IQueryExpression)ConvertInternal(p.Expr1, action); var q = (ISelectQuery)ConvertInternal(p.SubQuery, action); if (e != null && !ReferenceEquals(p.Expr1, e) || q != null && !ReferenceEquals(p.SubQuery, q)) { newElement = new InSubQuery(e ?? p.Expr1, p.IsNot, q ?? p.SubQuery); } break; } case EQueryElementType.InListPredicate: { var p = (IInList)element; var e = (IQueryExpression)ConvertInternal(p.Expr1, action); var v = Convert(p.Values, action); if (e != null && !ReferenceEquals(p.Expr1, e) || v != null && !ReferenceEquals(p.Values, v)) { newElement = new InList(e ?? p.Expr1, p.IsNot, v ?? p.Values); } break; } case EQueryElementType.FuncLikePredicate: { var p = (IFuncLike)element; var f = (ISqlFunction)ConvertInternal(p.Function, action); if (f != null && !ReferenceEquals(p.Function, f)) { newElement = new FuncLike(f); } break; } case EQueryElementType.SetExpression: { var s = (ISetExpression)element; var c = (IQueryExpression)ConvertInternal(s.Column, action); var e = (IQueryExpression)ConvertInternal(s.Expression, action); if (c != null && !ReferenceEquals(s.Column, c) || e != null && !ReferenceEquals(s.Expression, e)) { newElement = new SetExpression(c ?? s.Column, e ?? s.Expression); } break; } case EQueryElementType.InsertClause: { var s = (IInsertClause)element; var t = s.Into != null ? (ISqlTable)ConvertInternal(s.Into, action) : null; var i = Convert(s.Items, action); if (t != null && !ReferenceEquals(s.Into, t) || i != null && !ReferenceEquals(s.Items, i)) { var sc = new InsertClause { Into = t ?? s.Into }; (i ?? s.Items).ForEach(node => sc.Items.AddLast(node.Value)); sc.WithIdentity = s.WithIdentity; newElement = sc; } break; } case EQueryElementType.UpdateClause: { var s = (IUpdateClause)element; var t = s.Table != null ? (ISqlTable)ConvertInternal(s.Table, action) : null; var i = Convert(s.Items, action); var k = Convert(s.Keys, action); if (t != null && !ReferenceEquals(s.Table, t) || i != null && !ReferenceEquals(s.Items, i) || k != null && !ReferenceEquals(s.Keys, k)) { var sc = new UpdateClause { Table = t ?? s.Table }; (i ?? s.Items).ForEach(node => sc.Items.AddLast(node.Value)); (k ?? s.Keys).ForEach(node => sc.Keys.AddLast(node.Value)); newElement = sc; } break; } case EQueryElementType.DeleteClause: { var s = (IDeleteClause)element; var t = s.Table != null ? (ISqlTable)ConvertInternal(s.Table, action) : null; if (t != null && !ReferenceEquals(s.Table, t)) { newElement = new DeleteClause { Table = t }; } break; } case EQueryElementType.CreateTableStatement: { var s = (ICreateTableStatement)element; var t = s.Table != null ? (ISqlTable)ConvertInternal(s.Table, action) : null; if (t != null && !ReferenceEquals(s.Table, t)) { newElement = new CreateTableStatement { Table = t, IsDrop = s.IsDrop }; } break; } case EQueryElementType.SelectClause: { var sc = (ISelectClause)element; var cols = Convert(sc.Columns, action); var take = (IQueryExpression)ConvertInternal(sc.TakeValue, action); var skip = (IQueryExpression)ConvertInternal(sc.SkipValue, action); IQueryElement parent; _visitedElements.TryGetValue(sc.SelectQuery, out parent); if (parent != null || cols != null && !ReferenceEquals(sc.Columns, cols) || take != null && !ReferenceEquals(sc.TakeValue, take) || skip != null && !ReferenceEquals(sc.SkipValue, skip)) { newElement = new SelectClause(sc.IsDistinct, take ?? sc.TakeValue, skip ?? sc.SkipValue, cols ?? sc.Columns); ((ISelectClause)newElement).SetSqlQuery((ISelectQuery)parent); } break; } case EQueryElementType.FromClause: { var fc = (IFromClause)element; var ts = Convert(fc.Tables, action); IQueryElement parent; _visitedElements.TryGetValue(fc.SelectQuery, out parent); if (parent != null || ts != null && !ReferenceEquals(fc.Tables, ts)) { newElement = new FromClause(ts ?? fc.Tables); ((IFromClause)newElement).SetSqlQuery((ISelectQuery)parent); } break; } case EQueryElementType.WhereClause: { var wc = (IWhereClause)element; var cond = (ISearchCondition)ConvertInternal(wc.Search, action); IQueryElement parent; _visitedElements.TryGetValue(wc.SelectQuery, out parent); if (parent != null || cond != null && !ReferenceEquals(wc.Search, cond)) { newElement = new WhereClause(cond ?? wc.Search); ((IWhereClause)newElement).SetSqlQuery((ISelectQuery)parent); } break; } case EQueryElementType.GroupByClause: { var gc = (IGroupByClause)element; var es = Convert(gc.Items, action); IQueryElement parent; _visitedElements.TryGetValue(gc.SelectQuery, out parent); if (parent != null || es != null && !ReferenceEquals(gc.Items, es)) { newElement = new GroupByClause(es ?? gc.Items); ((IGroupByClause)newElement).SetSqlQuery((ISelectQuery)parent); } break; } case EQueryElementType.OrderByClause: { var oc = (IOrderByClause)element; var es = Convert(oc.Items, action); IQueryElement parent; _visitedElements.TryGetValue(oc.SelectQuery, out parent); if (parent != null || es != null && !ReferenceEquals(oc.Items, es)) { newElement = new OrderByClause(es ?? oc.Items); ((IOrderByClause)newElement).SetSqlQuery((ISelectQuery)parent); } break; } case EQueryElementType.OrderByItem: { var i = (IOrderByItem)element; var e = (IQueryExpression)ConvertInternal(i.Expression, action); if (e != null && !ReferenceEquals(i.Expression, e)) { newElement = new OrderByItem(e, i.IsDescending); } break; } case EQueryElementType.Union: { var u = (IUnion)element; var q = (ISelectQuery)ConvertInternal(u.SelectQuery, action); if (q != null && !ReferenceEquals(u.SelectQuery, q)) { newElement = new Union(q, u.IsAll); } break; } case EQueryElementType.SqlQuery: { var q = (ISelectQuery)element; IQueryElement parent = null; var doConvert = false; if (q.ParentSelect != null) { if (!_visitedElements.TryGetValue(q.ParentSelect, out parent)) { doConvert = true; parent = q.ParentSelect; } } if (!doConvert) { doConvert = null != FindFirstOrDefault <IQueryElement>(q, e => { if (_visitedElements.ContainsKey(e) && _visitedElements[e] != e) { return(true); } var ret = action(e); if (ret != null && !ReferenceEquals(e, ret)) { _visitedElements.Add(e, ret); return(true); } return(false); }); } if (!doConvert) { break; } var nq = new SelectQuery { EQueryType = q.EQueryType }; _visitedElements.Add(q, nq); var fc = (IFromClause)ConvertInternal(q.From, action) ?? q.From; var sc = (ISelectClause)ConvertInternal(q.Select, action) ?? q.Select; var ic = q.IsInsert ? ((IInsertClause)ConvertInternal(q.Insert, action) ?? q.Insert) : null; var uc = q.IsUpdate ? ((IUpdateClause)ConvertInternal(q.Update, action) ?? q.Update) : null; var dc = q.IsDelete ? ((IDeleteClause)ConvertInternal(q.Delete, action) ?? q.Delete) : null; var wc = (IWhereClause)ConvertInternal(q.Where, action) ?? q.Where; var gc = (IGroupByClause)ConvertInternal(q.GroupBy, action) ?? q.GroupBy; var hc = (IWhereClause)ConvertInternal(q.Having, action) ?? q.Having; var oc = (IOrderByClause)ConvertInternal(q.OrderBy, action) ?? q.OrderBy; var us = q.HasUnion ? Convert(q.Unions, action) : q.Unions; var ps = new List <ISqlParameter>(q.Parameters.Count); foreach (var p in q.Parameters) { IQueryElement e; if (_visitedElements.TryGetValue(p, out e)) { if (e == null) { ps.Add(p); } else { var sqlParameter = e as ISqlParameter; if (sqlParameter != null) { ps.Add(sqlParameter); } } } } nq.Init(ic, uc, dc, sc, fc, wc, gc, hc, oc, us, (ISelectQuery)parent, q.CreateTable, q.IsParameterDependent, ps); _visitedElements[q] = action(nq) ?? nq; return(nq); } } newElement = newElement == null ? action(element) : (action(newElement) ?? newElement); _visitedElements.Add(element, newElement); return(newElement); }
static ISqlExpression GetColumn(QueryData data, SqlField 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.Add(field); return q.Select.Columns[idx]; } } } return null; }
protected override void BuildCreateTableNullAttribute(SqlField field, DefaulNullable defaulNullable) { if (!field.CanBeNull) StringBuilder.Append("NOT NULL"); }
public Rule_assignment() { attached_to_id = new SqlField("attached_to_id", SqlDbType.BigInt); attached_to_type_cd_id = new SqlField("attached_to_type_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.SYSTEM_OBJECT_TYPE); start_date = new SqlField("start_date", SqlDbType.DateTime); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); rule_id = new SqlField("rule_id", SqlDbType.BigInt, isNullable: true); rule_id_old = new SqlField("rule_id_old", SqlDbType.VarChar, isNullable: true, maxLength: 100); }
void Init(MappingSchema mappingSchema) { _mappingSchema = mappingSchema; var objectMapper = mappingSchema.GetObjectMapper(ObjectType); foreach (var field in SqlTable.Fields) { var mapper = objectMapper[field.Value.PhysicalName]; var column = new Column(this, field.Value, mapper); Fields.Add(column); _columns.Add(field.Value.Name, column); } foreach (var a in objectMapper.Associations) { _associations.Add(a.MemberAccessor.Name, a); } InheritanceMapping = objectMapper.InheritanceMapping; if (InheritanceMapping.Count > 0) { InheritanceDiscriminators = new List <string>(InheritanceMapping.Count); foreach (var mapping in InheritanceMapping) { string discriminator = null; foreach (MemberMapper mm in mappingSchema.GetObjectMapper(mapping.Type)) { if (mm.MapMemberInfo.SqlIgnore == false) { if (!_columns.ContainsKey(mm.MemberName)) { var field = new SqlField(mm.Type, mm.MemberName, mm.Name, mm.MapMemberInfo.Nullable, int.MinValue, null, mm); SqlTable.Fields.Add(field); var column = new Column(this, field, null); Fields.Add(column); _columns.Add(field.Name, column); } if (mm.MapMemberInfo.IsInheritanceDiscriminator) { discriminator = mm.MapMemberInfo.Name; } } } InheritanceDiscriminators.Add(discriminator); } var dname = InheritanceDiscriminators.FirstOrDefault(s => s != null); if (dname == null) { throw new LinqException("Inheritance Discriminator is not defined for the '{0}' hierarchy.", ObjectType); } for (var i = 0; i < InheritanceDiscriminators.Count; i++) { if (InheritanceDiscriminators[i] == null) { InheritanceDiscriminators[i] = dname; } } } }
static SelectQuery.TableSource FindField(SqlField field, SelectQuery.TableSource table) { if (field.Table == table.Source) return table; foreach (var @join in table.Joins) { var t = FindField(field, @join.Table); if (t != null) return @join.Table; } return null; }
public Settlement_config() { business_unit_party_id = new SqlField("business_unit_party_id", SqlDbType.BigInt); check_group_id = new SqlField("check_group_id", SqlDbType.SmallInt); settlement_method_cd_id = new SqlField("settlement_method_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.SETTLEMENT_METHOD); attached_to_id = new SqlField("attached_to_id", SqlDbType.BigInt, isNullable: true); attached_to_type_cd_id = new SqlField("attached_to_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.SYSTEM_OBJECT_TYPE); auto_close_criteria = new SqlField("auto_close_criteria", SqlDbType.VarChar, isNullable: true, maxLength: 500); auto_closeout_time = new SqlField("auto_closeout_time", SqlDbType.VarChar, isNullable: true, maxLength: 30); bank_number = new SqlField("bank_number", SqlDbType.VarChar, isNullable: true, maxLength: 44); check_pay_to_name = new SqlField("check_pay_to_name", SqlDbType.VarChar, isNullable: true, maxLength: 250); checking_account_number = new SqlField("checking_account_number", SqlDbType.VarChar, isNullable: true, maxLength: 54); is_auto_closeout = new SqlField("is_auto_closeout", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); is_check_per_order = new SqlField("is_check_per_order", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); is_check_per_order_pos = new SqlField("is_check_per_order_pos", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); is_close_children_on_auto_closeout = new SqlField("is_close_children_on_auto_closeout", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); is_close_prior_business_day = new SqlField("is_close_prior_business_day", SqlDbType.Char, isNullable: true, maxLength: 1, isFlag: true); no_closeout_dates = new SqlField("no_closeout_dates", SqlDbType.VarChar, isNullable: true, maxLength: 100); prior_day_time_offset_minutes = new SqlField("prior_day_time_offset_minutes", SqlDbType.Int, isNullable: true); report_group_id = new SqlField("report_group_id", SqlDbType.SmallInt, isNullable: true); report_template_id = new SqlField("report_template_id", SqlDbType.BigInt, isNullable: true); settlement_report_cd_id = new SqlField("settlement_report_cd_id", SqlDbType.BigInt, isNullable: true); }
protected override SqlExpression VisitField(SqlField expr) { // нужно вытащить имя источника поля string sourceName = null; if (!_nameMap.TryGetValue(expr.Source, out sourceName)) { sourceName = "T" + _nameMap.Count; _nameMap[expr.Source] = sourceName; } if (!String.IsNullOrEmpty(sourceName)) { WriteName(sourceName); _builder.Append('.'); } WriteName(expr.Name); return expr; }
public Template() { name = new SqlField("name", SqlDbType.VarChar, maxLength: 250); start_date = new SqlField("start_date", SqlDbType.DateTime); template_category_cd_id = new SqlField("template_category_cd_id", SqlDbType.BigInt, codeType: SystemCodeType.TEMPLATE_CATEGORY); template_text = new SqlField("template_text", SqlDbType.Text); description = new SqlField("description", SqlDbType.VarChar, isNullable: true, maxLength: 250); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); template_type_cd_id = new SqlField("template_type_cd_id", SqlDbType.BigInt, isNullable: true, codeType: SystemCodeType.TEMPLATE_TYPE); }
public Terminal_id() { business_unit_merchant_number_id = new SqlField("business_unit_merchant_number_id", SqlDbType.BigInt); start_date = new SqlField("start_date", SqlDbType.DateTime); terminal_id = new SqlField("terminal_id", SqlDbType.VarChar, maxLength: 20); business_unit_pos_terminal_id = new SqlField("business_unit_pos_terminal_id", SqlDbType.BigInt, isNullable: true); end_date = new SqlField("end_date", SqlDbType.DateTime, isNullable: true); }
public Terminal_user() { admin_user_id = new SqlField("admin_user_id", SqlDbType.BigInt); business_unit_pos_terminal_id = new SqlField("business_unit_pos_terminal_id", SqlDbType.BigInt); }
public Business_unit_batch_receipt_config() { name = new SqlField("name", SqlDbType.VarChar, maxLength: 50); party_id = new SqlField("party_id", SqlDbType.BigInt); seq_no = new SqlField("seq_no", SqlDbType.SmallInt); config = new SqlField("config", SqlDbType.Image, isNullable: true); }
protected override void BuildCreateTableIdentityAttribute2(SqlField field) { StringBuilder.Append("IDENTITY"); }
protected override IBuildContext BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo) { var mergeContext = (MergeContext)builder.BuildSequence(new BuildInfo(buildInfo, methodCall.Arguments[0])); var kind = MergeKind.Merge; if (methodCall.IsSameGenericMethod(MergeWithOutputInto)) { kind = MergeKind.MergeWithOutputInto; } else if (methodCall.IsSameGenericMethod(MergeWithOutput)) { kind = MergeKind.MergeWithOutput; } if (kind != MergeKind.Merge) { var objectType = methodCall.Method.GetGenericArguments()[0]; var actionField = SqlField.FakeField(new DbDataType(typeof(string)), "$action", false); var insertedTable = SqlTable.Inserted(objectType); var deletedTable = SqlTable.Deleted(objectType); mergeContext.Merge.Output = new SqlOutputClause() { InsertedTable = insertedTable, DeletedTable = deletedTable, }; var selectQuery = new SelectQuery(); var actionFieldContext = new SingleExpressionContext(null, builder, actionField, selectQuery); var deletedTableContext = new TableBuilder.TableContext(builder, selectQuery, deletedTable); var insertedTableConext = new TableBuilder.TableContext(builder, selectQuery, insertedTable); if (kind == MergeKind.MergeWithOutput) { var outputExpression = (LambdaExpression)methodCall.Arguments[1].Unwrap(); var outputContext = new MergeOutputContext( buildInfo.Parent, outputExpression, mergeContext, actionFieldContext, deletedTableContext, insertedTableConext ); return(outputContext); } else { var outputExpression = (LambdaExpression)methodCall.Arguments[2].Unwrap(); var outputTable = methodCall.Arguments[1]; var destination = builder.BuildSequence(new BuildInfo(buildInfo, outputTable, new SelectQuery())); UpdateBuilder.BuildSetterWithContext( builder, buildInfo, outputExpression, destination, mergeContext.Merge.Output.OutputItems, actionFieldContext, deletedTableContext, insertedTableConext ); mergeContext.Merge.Output.OutputTable = ((TableBuilder.TableContext)destination).SqlTable; } } return(mergeContext); }