public override SqlFragment Visit(DbArithmeticExpression expression) { if (expression.ExpressionKind == DbExpressionKind.UnaryMinus) { ListFragment f = new ListFragment(); f.Append("-("); f.Append(expression.Arguments[0].Accept(this)); f.Append(")"); return(f); } string op = String.Empty; switch (expression.ExpressionKind) { case DbExpressionKind.Divide: op = "/"; break; case DbExpressionKind.Minus: op = "-"; break; case DbExpressionKind.Modulo: op = "%"; break; case DbExpressionKind.Multiply: op = "*"; break; case DbExpressionKind.Plus: op = "+"; break; default: throw new NotSupportedException(); } return(VisitBinaryExpression(expression.Arguments[0], expression.Arguments[1], op)); }
protected SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = new SelectStatement(); Debug.Assert(returning is DbNewInstanceExpression); VisitNewInstanceExpression(select, returning as DbNewInstanceExpression); select.From = (InputFragment)tree.Target.Expression.Accept(this); ListFragment where = new ListFragment(); where.Append(" row_count() > 0"); EntitySetBase table = ((DbScanExpression)tree.Target.Expression).Target; bool foundIdentity = false; foreach (EdmMember keyMember in table.ElementType.KeyMembers) { SqlFragment value; if (!values.TryGetValue(keyMember, out value)) { if (foundIdentity) { throw new NotSupportedException(); } foundIdentity = true; value = new LiteralFragment("last_insert_id()"); } where.Append(String.Format(" AND `{0}`=", keyMember)); where.Append(value); } select.Where = where; return(select); }
protected override SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); EntitySetBase table = ((DbScanExpression)tree.Target.Expression).Target; bool foundIdentity = false; where.Append(" row_count() > 0"); foreach (EdmMember keyMember in table.ElementType.KeyMembers) { SqlFragment value; if (!values.TryGetValue(keyMember, out value)) { if (foundIdentity) throw new NotSupportedException(); foundIdentity = true; PrimitiveTypeKind type = ((PrimitiveType)keyMember.TypeUsage.EdmType.BaseType).PrimitiveTypeKind; if ((type == PrimitiveTypeKind.Byte) || (type == PrimitiveTypeKind.SByte) || (type == PrimitiveTypeKind.Int16) || (type == PrimitiveTypeKind.Int32) || (type == PrimitiveTypeKind.Int64)) { value = new LiteralFragment("last_insert_id()"); } else if (keyMember.TypeUsage.EdmType.BaseType.Name == "Guid") value = new LiteralFragment(string.Format("ANY(SELECT guid FROM tmpIdentity_{0})", (table as MetadataItem).MetadataProperties["Table"].Value)); } where.Append(String.Format(" AND `{0}`=", keyMember)); where.Append(value); } select.Where = where; return select; }
protected virtual SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); EntitySetBase table = ((DbScanExpression)tree.Target.Expression).Target; bool foundIdentity = false; where.Append(" row_count() > 0"); foreach (EdmMember keyMember in table.ElementType.KeyMembers) { SqlFragment value; if (!values.TryGetValue(keyMember, out value)) { if (foundIdentity) throw new NotSupportedException(); foundIdentity = true; value = new LiteralFragment("last_insert_id()"); } where.Append(String.Format(" AND `{0}`=", keyMember)); where.Append(value); } select.Where = where; return select; }
protected virtual SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); EntitySetBase table = ((DbScanExpression)tree.Target.Expression).Target; bool foundIdentity = false; where.Append(" row_count() > 0"); foreach (EdmMember keyMember in table.ElementType.KeyMembers) { SqlFragment value; if (!values.TryGetValue(keyMember, out value)) { if (foundIdentity) { throw new NotSupportedException(); } foundIdentity = true; if (keyMember.TypeUsage.EdmType.BaseType.Name.StartsWith("Int")) { value = new LiteralFragment("last_insert_id()"); } else if (keyMember.TypeUsage.EdmType.BaseType.Name == "Guid") { value = new LiteralFragment(string.Format("ANY(SELECT guid FROM tmpIdentity_{0})", (table as MetadataItem).MetadataProperties["Table"].Value)); } } where.Append(String.Format(" AND `{0}`=", keyMember)); where.Append(value); } select.Where = where; return(select); }
protected override SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); where.Append(" row_count() > 0 and "); where.Append( ((DbUpdateCommandTree)tree).Predicate.Accept(this) ); select.Where = where; return select; }
protected override SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); where.Append(" row_count() > 0 and "); where.Append(((System.Data.Common.CommandTrees.DbUpdateCommandTree)tree).Predicate.Accept(this)); select.Where = where; return(select); }
protected virtual SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = new SelectStatement(this); Debug.Assert(returning is DbNewInstanceExpression); VisitNewInstanceExpression(select, returning as DbNewInstanceExpression); select.From = (InputFragment)tree.Target.Expression.Accept(this); ListFragment where = new ListFragment(); select.Where = where; return(select); }
private SqlFragment UserDefinedFunction(DbFunctionExpression e) { FunctionFragment f = new FunctionFragment(); f.Name = Metadata.TryGetValueMetadataProperty <string>(e.Function, "StoreFunctionNameAttribute"); if (String.IsNullOrEmpty(f.Name)) { f.Name = e.Function.Name; } f.Quoted = !Metadata.TryGetValueMetadataProperty <bool>(e.Function, "BuiltInAttribute"); bool isFuncNiladic = Metadata.TryGetValueMetadataProperty <bool>(e.Function, "NiladicFunctionAttribute"); if (isFuncNiladic && e.Arguments.Count > 0) { throw new InvalidOperationException("Niladic functions cannot have parameters"); } ListFragment list = new ListFragment(); string delimiter = ""; foreach (DbExpression arg in e.Arguments) { if (delimiter.Length > 0) { list.Append(new LiteralFragment(delimiter)); } list.Append(arg.Accept(callingGenerator)); delimiter = ", "; } f.Argument = list; return(f); }
private SqlFragment UserDefinedFunction(DbFunctionExpression e) { FunctionFragment f = new FunctionFragment(); f.Name = Metadata.TryGetValueMetadataProperty<string>(e.Function, "StoreFunctionNameAttribute"); if (String.IsNullOrEmpty(f.Name)) f.Name = e.Function.Name; f.Quoted = !Metadata.TryGetValueMetadataProperty<bool>(e.Function, "BuiltInAttribute"); bool isFuncNiladic = Metadata.TryGetValueMetadataProperty<bool>(e.Function, "NiladicFunctionAttribute"); if (isFuncNiladic && e.Arguments.Count > 0) throw new InvalidOperationException("Niladic functions cannot have parameters"); ListFragment list = new ListFragment(); string delimiter = ""; foreach (DbExpression arg in e.Arguments) { if (delimiter.Length > 0) list.Append(new LiteralFragment(delimiter)); list.Append(arg.Accept(callingGenerator)); delimiter = ", "; } f.Argument = list; return f; }
public void Visit(ListFragment f) { }
protected override SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning) { SelectStatement select = base.GenerateReturningSql(tree, returning); ListFragment where = new ListFragment(); where.Append(" row_count() > 0 and "); #if EF6 where.Append( ((System.Data.Entity.Core.Common.CommandTrees.DbUpdateCommandTree)tree).Predicate.Accept(this) ); #else where.Append( ((System.Data.Common.CommandTrees.DbUpdateCommandTree)tree).Predicate.Accept(this) ); #endif select.Where = where; return select; }