protected override OeAsyncEnumerator ExecuteScalar(Object dataContext, String sql, IReadOnlyList <KeyValuePair <String, Object> > parameters, Type returnType) { var dbContext = (DbContext)dataContext; var connection = dbContext.GetService <IRelationalConnection>(); var commandBuilderFactory = dbContext.GetService <IRelationalCommandBuilderFactory>(); IRelationalCommandBuilder commandBuilder = commandBuilderFactory.Create(); commandBuilder.Append(sql); var parameterNameGenerator = dbContext.GetService <IParameterNameGeneratorFactory>().Create(); var sqlHelper = dbContext.GetService <ISqlGenerationHelper>(); var parameterValues = new Dictionary <String, Object>(parameters.Count); for (int i = 0; i < parameters.Count; i++) { String invariantName = parameterNameGenerator.GenerateNext(); String name = sqlHelper.GenerateParameterName(invariantName); commandBuilder.AddParameter(invariantName, name); parameterValues.Add(invariantName, parameters[i].Value); } IRelationalCommand command = commandBuilder.Build(); Task <Object> scalarTask = command.ExecuteScalarAsync(connection, parameterValues); return(new OeScalarAsyncEnumeratorAdapter(scalarTask, CancellationToken.None)); }
/// <summary> /// 结束命令 /// </summary> /// <param name="suppressTransaction">事务抑制</param> /// <returns></returns> public override MigrationCommandListBuilder EndCommand(bool suppressTransaction = false) { if (_commandBuilder.GetLength() != 0) { _commands.Add(new OracleMigrationCommand(_commandBuilder.Build(), suppressTransaction)); _commandBuilder = _commandBuilderFactory.Create(); } return(this); }
/// <summary> /// Ends the building of the current command and adds it to the list of built commands. /// The next call to one of the builder methods will start building a new command. /// </summary> /// <param name="suppressTransaction"> /// Indicates whether or not transactions should be suppressed while executing the built command. /// </param> /// <returns> This builder so that additional calls can be chained. </returns> public virtual MigrationCommandListBuilder EndCommand(bool suppressTransaction = false) { if (_commandBuilder.CommandTextLength != 0) { _commands.Add(new MigrationCommand(_commandBuilder.Build(), suppressTransaction)); _commandBuilder = _dependencies.CommandBuilderFactory.Create(); } return(this); }
public virtual RelationalCommandListBuilder EndCommand() { if (_commandBuilder.GetLength() != 0) { _commands.Add(_commandBuilder.Build()); _commandBuilder = _commandBuilderFactory.Create(); } return(this); }
public virtual IRelationalCommand GenerateSql(IReadOnlyDictionary <string, object> parameterValues) { Check.NotNull(parameterValues, nameof(parameterValues)); _relationalCommandBuilder = _relationalCommandBuilderFactory.Create(); _parameterNameGenerator = _parameterNameGeneratorFactory.Create(); _parametersValues = parameterValues; Visit(SelectExpression); return(_relationalCommandBuilder.Build()); }
/// <summary> /// Relational command from the read only expression /// </summary> /// <param name="IReadOnlyDictionary<string"></param> /// <param name="parameterValues"></param> /// <returns></returns> public IRelationalCommand GenerateSql([NotNull] IReadOnlyDictionary <string, object> parameterValues) { Check.NotNull(parameterValues, nameof(parameterValues)); _commandBuilder = Dependencies.CommandBuilderFactory.Create(); _parameterNameGenerator = Dependencies.ParameterNameGeneratorFactory.Create(); _parametersValues = parameterValues; // TODO: null comparison transformation Visit(ReadOnlyExpression); return(_commandBuilder.Build()); }
public virtual IRelationalCommand GetCommand(SelectExpression selectExpression) { _relationalCommandBuilder = _relationalCommandBuilderFactory.Create(); if (selectExpression.IsNonComposedFromSql()) { GenerateFromSql((FromSqlExpression)selectExpression.Tables[0]); } else { VisitSelect(selectExpression); } return(_relationalCommandBuilder.Build()); }
public virtual IRelationalCommand GetCommand( SelectExpression selectExpression, IReadOnlyDictionary <string, object> parameterValues, IDiagnosticsLogger <DbLoggerCategory.Database.Command> commandLogger) { _relationalCommandBuilder = _relationalCommandBuilderFactory.Create(); //_parameterNameGenerator = Dependencies.ParameterNameGeneratorFactory.Create(); _parametersValues = parameterValues; VisitSelect(selectExpression); return(_relationalCommandBuilder.Build()); }
public virtual IRelationalCommand GetCommand([NotNull] SelectExpression selectExpression) { Check.NotNull(selectExpression, nameof(selectExpression)); _relationalCommandBuilder = _relationalCommandBuilderFactory.Create(); GenerateTagsHeaderComment(selectExpression); if (selectExpression.IsNonComposedFromSql()) { GenerateFromSql((FromSqlExpression)selectExpression.Tables[0]); } else { VisitSelect(selectExpression); } return(_relationalCommandBuilder.Build()); }
private IRelationalCommand CreateCommand(Object dataContext, String sql, IReadOnlyList <KeyValuePair <String, Object> > parameters, out Dictionary <String, Object> parameterValues) { var dbContext = (DbContext)dataContext; var commandBuilderFactory = dbContext.GetService <IRelationalCommandBuilderFactory>(); IRelationalCommandBuilder commandBuilder = commandBuilderFactory.Create(); commandBuilder.Append(sql); var parameterNameGenerator = dbContext.GetService <IParameterNameGeneratorFactory>().Create(); var sqlHelper = dbContext.GetService <ISqlGenerationHelper>(); parameterValues = new Dictionary <String, Object>(parameters.Count); for (int i = 0; i < parameters.Count; i++) { String invariantName = parameterNameGenerator.GenerateNext(); String name = sqlHelper.GenerateParameterName(invariantName); commandBuilder.AddParameter(invariantName, name); parameterValues.Add(invariantName, GetParameterCore(parameters[i], name, i)); } return(commandBuilder.Build()); }
public static Expression VisitSelect(IZackQuerySqlGenerator sqlGenerator, ISqlGenerationHelper _sqlGenerationHelper, SelectExpression selectExpression) { if (BatchUtils.IsNonComposedSetOperation(selectExpression)) { sqlGenerator.P_GenerateSetOperation((SetOperationBase)selectExpression.Tables[0]); return(selectExpression); } IRelationalCommandBuilder Sql = sqlGenerator.P_Sql; IDisposable disposable = null; if (selectExpression.Alias != null) { Sql.AppendLine("("); disposable = sqlGenerator.P_Sql.Indent(); } Sql.Append("SELECT "); if (selectExpression.IsDistinct) { Sql.Append("DISTINCT "); } sqlGenerator.P_GenerateTop(selectExpression); if (selectExpression.Projection.Any()) { BatchUtils.GenerateList(selectExpression.Projection, Sql, delegate(ProjectionExpression e) { var oldSQL = Sql.Build().CommandText; //zack's code sqlGenerator.Visit(e); string column = BatchUtils.Diff(oldSQL, Sql.Build().CommandText); //zack's code sqlGenerator.ProjectionSQL.Add(column); //zack's code }); } else { Sql.Append("1"); sqlGenerator.ProjectionSQL.Add("1"); //zack's code } if (selectExpression.Tables.Any()) { Sql.AppendLine().Append("FROM "); BatchUtils.GenerateList(selectExpression.Tables, Sql, delegate(TableExpressionBase e) { sqlGenerator.Visit(e); }, delegate(IRelationalCommandBuilder sql) { sql.AppendLine(); }); } else { sqlGenerator.P_GeneratePseudoFromClause(); } if (selectExpression.Predicate != null) { Sql.AppendLine().Append("WHERE "); var oldSQL = Sql.Build().CommandText; //zack's code sqlGenerator.Visit(selectExpression.Predicate); sqlGenerator.PredicateSQL = BatchUtils.Diff(oldSQL, Sql.Build().CommandText); //zack's code } if (selectExpression.GroupBy.Count > 0) { Sql.AppendLine().Append("GROUP BY "); BatchUtils.GenerateList(selectExpression.GroupBy, Sql, delegate(SqlExpression e) { sqlGenerator.Visit(e); }); } if (selectExpression.Having != null) { Sql.AppendLine().Append("HAVING "); sqlGenerator.Visit(selectExpression.Having); } sqlGenerator.P_GenerateOrderings(selectExpression); sqlGenerator.P_GenerateLimitOffset(selectExpression); if (selectExpression.Alias != null) { disposable.Dispose(); Sql.AppendLine().Append(")" + sqlGenerator.P_AliasSeparator + _sqlGenerationHelper.DelimitIdentifier(selectExpression.Alias)); } return(selectExpression); }
public int ExecuteNonQuery <TEntity>(SqlStatementKind statementKind, IEntityModel model, TEntity entity, IEntityMapping entityMapping) where TEntity : class { var command = _commandBuilder.Build(statementKind, model, entity, entityMapping); return(Connection.ExecuteNonQuery(command.Sql, command.Parameters.ToDictionary())); }