void ISqlElement.Render(RenderContext context) { if (context.Mode == RenderMode.Nested) { switch (Target) { case Column column: context.WriteIdentifier(column.Name); break; default: context.Render(Target); break; } context.Write(" = "); context.Render(Value); } else { using (context.EnterChildMode(RenderMode.Nested)) { context.Write("SET "); context.Render(Target); context.Write(" = "); context.Render(Value); context.Write(';'); } } }
void ISqlElement.Render(RenderContext context) { using (context.EnterChildMode(RenderMode.Nested)) { if (Left is null || Right is null) { // A value is null, get the non-null value var value = Left ?? Right; if (value is null) { throw new InvalidCommandException("Both sides of a condition operation cannot be null."); } // Note that we are supporting binary operators Equal and NotEqual below to allow // automatic conversion of null to IS NULL or IS NOT NULL clauses. switch (OperationType) { case OperationType.Equal: case OperationType.IsNull: context.Render(value); context.Write(" IS NULL"); return; case OperationType.NotEqual: case OperationType.IsNotNull: context.Render(value); context.Write(" IS NOT NULL"); return; case OperationType.Exists: context.Write("EXISTS "); context.Render(value); return; case OperationType.NotExists: context.Write("NOT EXISTS "); context.Render(value); return; default: throw new InvalidCommandException($"The binary operator '{OperationType}' requires two arguments."); } }
void ISqlElement.Render(RenderContext context) { var output = OutputType.None; if (_returning?.Any() == true) { output = context.Dialect.OutputType; if (output == OutputType.None) { throw new InvalidCommandException("This dialect does not support return clauses in delete statements."); } } using (context.EnterChildMode(RenderMode.Nested)) { context.Write("DELETE FROM "); context.Render(_from.Value); // OUTPUT statements are rendered before where clauses if (output == OutputType.Output) { context.WriteLine(); context.Write("OUTPUT "); context.RenderDelimited(_returning); } if (Where != null) { context.WriteLine(); context.Write("WHERE "); context.Render(Where.Value); } // RETURNING statements are rendered after where clauses if (output == OutputType.Returning) { context.WriteLine(); context.Write("RETURNING "); context.RenderDelimited(_returning); } context.Write(';'); } }
void ISqlElement.Render(RenderContext context) { using (context.EnterChildMode(RenderMode.Nested)) { context.Render(Left); switch (Symbol) { case ArithmeticOperator.Add: context.Write(" + "); break; case ArithmeticOperator.Subtract: context.Write(" - "); break; case ArithmeticOperator.Multiply: context.Write(" * "); break; case ArithmeticOperator.Divide: context.Write(" / "); break; case ArithmeticOperator.Modulo: context.Write(" % "); break; case ArithmeticOperator.BitShiftLeft: context.Write(" << "); break; case ArithmeticOperator.BitShiftRight: context.Write(" >> "); break; default: break; } context.Render(Right); } }