public void GenerateTextForGroupByExpression(ISqlCommandBuilder commandBuilder, Expression expression)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("expression", expression);

            GenerateTextForNonSelectExpression(commandBuilder, expression);
        }
    public BinaryExpressionTextGenerator (ISqlCommandBuilder commandBuilder, ExpressionTreeVisitor expressionVisitor)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("expressionVisitor", expressionVisitor);

      _commandBuilder = commandBuilder;
      _expressionVisitor = expressionVisitor;

      _simpleOperatorRegistry = new Dictionary<ExpressionType, string>
                                {
                                    { ExpressionType.Add, "+" },           
                                    { ExpressionType.AddChecked, "+" },    
                                    { ExpressionType.And, "&" },           
                                    { ExpressionType.AndAlso, "AND" },     
                                    { ExpressionType.Divide, "/" },        
                                    { ExpressionType.ExclusiveOr, "^" },   
                                    { ExpressionType.GreaterThan, ">" },   
                                    { ExpressionType.GreaterThanOrEqual, ">=" }, 
                                    { ExpressionType.LessThan, "<" },            
                                    { ExpressionType.LessThanOrEqual, "<=" },    
                                    { ExpressionType.Modulo, "%" },              
                                    { ExpressionType.Multiply, "*" },            
                                    { ExpressionType.MultiplyChecked, "*" },     
                                    { ExpressionType.Or, "|" },                  
                                    { ExpressionType.OrElse, "OR" },             
                                    { ExpressionType.Subtract, "-" },            
                                    { ExpressionType.SubtractChecked, "-" },     
                                    { ExpressionType.Equal, "=" },
                                    { ExpressionType.NotEqual, "<>" }            
                                };
    }
Exemplo n.º 3
0
        public Migrator(
            [NotNull] IMigrationsAssembly migrationsAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] ISqlGenerator sqlGenerator,
            [NotNull] ILogger<Migrator> logger,
            [NotNull] IDatabaseProviderServices providerServices)
        {
            Check.NotNull(migrationsAssembly, nameof(migrationsAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(providerServices, nameof(providerServices));

            _migrationsAssembly = migrationsAssembly;
            _historyRepository = historyRepository;
            _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _sqlCommandBuilder = sqlCommandBuilder;
            _sqlCommandBuilder = sqlCommandBuilder;
            _connection = connection;
            _sqlGenerator = sqlGenerator;
            _logger = logger;
            _activeProvider = providerServices.InvariantName;
        }
Exemplo n.º 4
0
        public async Task Delete(object primaryKey)
        {
            _sqlCommandBuilder = AutofacModule.Container.Resolve <ISqlCommandBuilder>();
            var deleteQuery = _sqlCommandBuilder.BuildDeleteQuery <T>(primaryKey);

            await this.Database.Delete(deleteQuery);
        }
Exemplo n.º 5
0
        //Uses a transaction
        public async Task Delete(Expression <Func <T, bool> > expression)
        {
            _sqlCommandBuilder = AutofacModule.Container.Resolve <ISqlCommandBuilder>();
            var deleteQuery = _sqlCommandBuilder.BuildDeleteQuery <T>(expression);

            await this.Database.Delete(deleteQuery);
        }
Exemplo n.º 6
0
        //uses transaction
        public async Task Update(T entity)
        {
            _sqlCommandBuilder = AutofacModule.Container.Resolve <ISqlCommandBuilder>();
            var updateQuery = _sqlCommandBuilder.BuildUpdateQuery <T>(entity);

            await this.Database.Update(updateQuery);
        }
        public virtual void GenerateTextForOuterSelectExpression(ISqlCommandBuilder commandBuilder, Expression expression)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("expression", expression);

            SqlGeneratingOuterSelectExpressionVisitor.GenerateSql(expression, commandBuilder, this);
        }
        public virtual void GenerateTextForFromTable(ISqlCommandBuilder commandBuilder, SqlTable table, bool isFirstTable)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("table", table);

            SqlTableAndJoinTextGenerator.GenerateSql(table, commandBuilder, this, isFirstTable);
        }
Exemplo n.º 9
0
        public Migrator(
            [NotNull] IMigrationsAssembly migrationsAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] ISqlGenerator sqlGenerator,
            [NotNull] ILogger <Migrator> logger,
            [NotNull] IDatabaseProviderServices providerServices)
        {
            Check.NotNull(migrationsAssembly, nameof(migrationsAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(providerServices, nameof(providerServices));

            _migrationsAssembly     = migrationsAssembly;
            _historyRepository      = historyRepository;
            _databaseCreator        = (IRelationalDatabaseCreator)databaseCreator;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            _sqlCommandBuilder      = sqlCommandBuilder;
            _sqlCommandBuilder      = sqlCommandBuilder;
            _connection             = connection;
            _sqlGenerator           = sqlGenerator;
            _logger         = logger;
            _activeProvider = providerServices.InvariantName;
        }
    public virtual void GenerateTextForFromTable (ISqlCommandBuilder commandBuilder, SqlTable table, bool isFirstTable)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("table", table);

      SqlTableAndJoinTextGenerator.GenerateSql (table, commandBuilder, this, isFirstTable);
    }
    public virtual void GenerateTextForOuterSelectExpression (ISqlCommandBuilder commandBuilder, Expression expression)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("expression", expression);

      SqlGeneratingOuterSelectExpressionVisitor.GenerateSql (expression, commandBuilder, this);
    }
    public virtual void GenerateTextForJoinCondition (ISqlCommandBuilder commandBuilder, Expression expression)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("expression", expression);

      GenerateTextForNonSelectExpression (commandBuilder, expression);
    }
Exemplo n.º 13
0
 public ADORelationalMapper(
     IDataMapper dataMapper,
     ISqlCommandBuilder commandBuilder)
 {
     this.dataMapper     = dataMapper;
     this.commandBuilder = commandBuilder;
 }
Exemplo n.º 14
0
        private ISqlCommandBuilder GetCommandBuilder(SqlOperation operation)
        {
            ISqlCommandBuilder result = null;

            switch (operation)
            {
            case SqlOperation.Insert:
                result = _insertCommandBuilder;
                break;

            case SqlOperation.Update:
                result = _updateCommandBuilder;
                break;

            case SqlOperation.Delete:
                result = _deleteCommandBuilder;
                break;

            case SqlOperation.Upsert:
                result = _upsertCommandBuilder;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(operation), operation, $"Sql operation {operation} is not supported");
            }
            return(result);
        }
        public BinaryExpressionTextGenerator(ISqlCommandBuilder commandBuilder, ExpressionVisitor expressionVisitor)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("expressionVisitor", expressionVisitor);

            _commandBuilder    = commandBuilder;
            _expressionVisitor = expressionVisitor;

            _simpleOperatorRegistry = new Dictionary <ExpressionType, string>
            {
                { ExpressionType.Add, "+" },
                { ExpressionType.AddChecked, "+" },
                { ExpressionType.And, "&" },
                { ExpressionType.AndAlso, "AND" },
                { ExpressionType.Divide, "/" },
                { ExpressionType.ExclusiveOr, "^" },
                { ExpressionType.GreaterThan, ">" },
                { ExpressionType.GreaterThanOrEqual, ">=" },
                { ExpressionType.LessThan, "<" },
                { ExpressionType.LessThanOrEqual, "<=" },
                { ExpressionType.Modulo, "%" },
                { ExpressionType.Multiply, "*" },
                { ExpressionType.MultiplyChecked, "*" },
                { ExpressionType.Or, "|" },
                { ExpressionType.OrElse, "OR" },
                { ExpressionType.Subtract, "-" },
                { ExpressionType.SubtractChecked, "-" },
                { ExpressionType.Equal, "=" },
                { ExpressionType.NotEqual, "<>" }
            };
        }
Exemplo n.º 16
0
        protected virtual void BuildSelectPart(
            SqlStatement sqlStatement,
            ISqlCommandBuilder commandBuilder,
            bool isOutermostStatement)
        {
            ArgumentUtility.CheckNotNull("sqlStatement", sqlStatement);
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);

            commandBuilder.Append("SELECT ");

            if (!(sqlStatement.SelectProjection is AggregationExpression))
            {
                BuildDistinctPart(sqlStatement, commandBuilder);
                BuildTopPart(sqlStatement, commandBuilder);
            }

            if (isOutermostStatement)
            {
                _stage.GenerateTextForOuterSelectExpression(commandBuilder, sqlStatement.SelectProjection);
            }
            else
            {
                _stage.GenerateTextForSelectExpression(commandBuilder, sqlStatement.SelectProjection);
            }
        }
Exemplo n.º 17
0
 protected virtual void BuildDistinctPart(SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
 {
     if (sqlStatement.IsDistinctQuery)
     {
         commandBuilder.Append("DISTINCT ");
     }
 }
 public TestableSqlGeneratingOuterSelectExpressionVisitor(
     ISqlCommandBuilder commandBuilder,
     ISqlGenerationStage stage,
     SetOperationsMode setOperationsMode)
     : base(commandBuilder, stage, setOperationsMode)
 {
 }
Exemplo n.º 19
0
 protected ExtendedSqlGeneratingOuterSelectExpressionVisitor(
     ISqlCommandBuilder commandBuilder,
     ISqlGenerationStage stage,
     SetOperationsMode setOperationsMode)
     : base(commandBuilder, stage, setOperationsMode)
 {
 }
Exemplo n.º 20
0
 private static void GenerateSqlForJoins(SqlTableBase sqlTable, ISqlCommandBuilder commandBuilder, IJoinInfoVisitor visitor)
 {
     foreach (var joinedTable in sqlTable.JoinedTables)
     {
         GenerateTextForSqlJoinedTable(visitor, joinedTable, commandBuilder);
         GenerateSqlForJoins(joinedTable, commandBuilder, visitor);
     }
 }
        public override void Generate(ISqlCommandBuilder commandBuilder, ExpressionTreeVisitor textGeneratingExpressionVisitor, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("textGeneratingExpressionVisitor", textGeneratingExpressionVisitor);
            ArgumentUtility.CheckNotNull("stage", stage);

            textGeneratingExpressionVisitor.VisitList(_expressions, textGeneratingExpressionVisitor.VisitExpression);
        }
    public override void Generate (ISqlCommandBuilder commandBuilder, ExpressionTreeVisitor textGeneratingExpressionVisitor, ISqlGenerationStage stage)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("textGeneratingExpressionVisitor", textGeneratingExpressionVisitor);
      ArgumentUtility.CheckNotNull ("stage", stage);

      textGeneratingExpressionVisitor.VisitList (_expressions, textGeneratingExpressionVisitor.VisitExpression);
    }
Exemplo n.º 23
0
        protected SqlTableAndJoinTextGenerator(ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("stage", stage);

            _commandBuilder = commandBuilder;
            _stage          = stage;
        }
    public override void Generate (ISqlCommandBuilder commandBuilder, ExpressionTreeVisitor textGeneratingExpressionVisitor, ISqlGenerationStage stage)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("textGeneratingExpressionVisitor", textGeneratingExpressionVisitor);
      ArgumentUtility.CheckNotNull ("stage", stage);

      commandBuilder.Append (_sqlText);
    }
 private static void GenerateSqlForJoins (SqlTableBase sqlTable, ISqlCommandBuilder commandBuilder, IJoinInfoVisitor visitor)
 {
   foreach (var joinedTable in sqlTable.JoinedTables)
   {
     GenerateTextForSqlJoinedTable (visitor, joinedTable, commandBuilder);
     GenerateSqlForJoins (joinedTable, commandBuilder, visitor);
   }
 }
        public override void Generate(ISqlCommandBuilder commandBuilder, ExpressionVisitor textGeneratingExpressionVisitor, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("textGeneratingExpressionVisitor", textGeneratingExpressionVisitor);
            ArgumentUtility.CheckNotNull("stage", stage);

            commandBuilder.Append(_sqlText);
        }
Exemplo n.º 27
0
        public static void GenerateSql(SqlTable sqlTable, ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage, bool isFirstTable)
        {
            ArgumentUtility.CheckNotNull("sqlTable", sqlTable);
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("stage", stage);

            GenerateTextForSqlTable(new SqlTableAndJoinTextGenerator(commandBuilder, stage), sqlTable, commandBuilder, isFirstTable);
            GenerateSqlForJoins(sqlTable, commandBuilder, new SqlTableAndJoinTextGenerator(commandBuilder, stage));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Query the table without a where clause.
        /// Note that that method will return all of the records without a filter.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <T> > Query()
        {
            _sqlCommandBuilder = AutofacModule.Container.Resolve <ISqlCommandBuilder>();
            var sqlQuery = _sqlCommandBuilder.BuildReadQuery <T>();

            var results = await this.Database.Query <T>(sqlQuery);

            return(results);
        }
Exemplo n.º 29
0
        //uses transaction
        public async Task <T> Add(T entity)
        {
            _sqlCommandBuilder = AutofacModule.Container.Resolve <ISqlCommandBuilder>();
            var insertQuery = _sqlCommandBuilder.BuildInsertQuery <T>(entity);

            entity = await this.Database.Insert(entity, insertQuery);

            return(entity);
        }
    public static void GenerateSql (SqlTable sqlTable, ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage, bool isFirstTable)
    {
      ArgumentUtility.CheckNotNull ("sqlTable", sqlTable);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("stage", stage);

      GenerateTextForSqlTable (new SqlTableAndJoinTextGenerator (commandBuilder, stage), sqlTable, commandBuilder, isFirstTable);
      GenerateSqlForJoins (sqlTable, commandBuilder, new SqlTableAndJoinTextGenerator (commandBuilder, stage));
    }
Exemplo n.º 31
0
 protected virtual void BuildTopPart(SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
 {
     if (sqlStatement.TopExpression != null)
     {
         commandBuilder.Append("TOP (");
         _stage.GenerateTextForTopExpression(commandBuilder, sqlStatement.TopExpression);
         commandBuilder.Append(") ");
     }
 }
 public TestDatabaseCreator(
     ISqlServerConnection connection,
     IMigrationsModelDiffer modelDiffer,
     IMigrationsSqlGenerator sqlGenerator,
     IModel model,
     ISqlCommandBuilder sqlCommandBuilder)
     : base(connection, modelDiffer, sqlGenerator, model, sqlCommandBuilder)
 {
 }
Exemplo n.º 33
0
        protected SqlGeneratingExpressionVisitor(ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("stage", stage);

            _commandBuilder = commandBuilder;
            _binaryExpressionTextGenerator = new BinaryExpressionTextGenerator(commandBuilder, this);
            _stage = stage;
        }
        public virtual void GenerateTextForOuterSqlStatement(ISqlCommandBuilder commandBuilder, SqlStatement sqlStatement)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("sqlStatement", sqlStatement);

            var sqlStatementTextGenerator = new SqlStatementTextGenerator(this);

            sqlStatementTextGenerator.Build(sqlStatement, commandBuilder, true);
        }
        public override void GenerateTextForOuterSelectExpression(
            ISqlCommandBuilder commandBuilder,
            Expression expression,
            SetOperationsMode setOperationsMode)
        {
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("expression", expression);

            ExtendedSqlGeneratingOuterSelectExpressionVisitor.GenerateSql(expression, commandBuilder, this, setOperationsMode);
        }
        public SqlServerSequenceValueGeneratorFactory(
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] ISqlServerUpdateSqlGenerator sqlGenerator)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _sqlCommandBuilder = sqlCommandBuilder;
            _sqlGenerator = sqlGenerator;
        }
Exemplo n.º 37
0
 public RepositoryQuery(ISqlSyntaxSign sqlsyntaxsign,
                        IMapper <T, U> mapper,
                        ISqlCommandBuilder sqlcommandbuilder,
                        ISqlCommandExecutor <T> sqlcommandexecutor, ISqlCommandExecutorBulk sqlcommandexecutorbulk)
     : this(sqlcommandexecutor, sqlcommandexecutorbulk,
            mapper,
            sqlcommandbuilder,
            new SqlBuilderQuery(sqlsyntaxsign))
 {
 }
Exemplo n.º 38
0
 public RepositoryQuery(IReader <T> reader, IMapper <T, U> mapper,
                        ISqlSyntaxSign sqlsyntaxsign,
                        ISqlCommandBuilder sqlcommandbuilder,
                        ISqlCreator sqlcreator)
     : this(sqlsyntaxsign,
            mapper,
            sqlcommandbuilder,
            new SqlCommandExecutor <T>(sqlcreator, reader), new SqlCommandExecutorBulk(sqlcreator))
 {
 }
Exemplo n.º 39
0
    public virtual void GenerateTextForOuterSqlStatement (ISqlCommandBuilder commandBuilder, SqlStatement sqlStatement)
    {
      Assert.That (sqlStatement.SelectProjection, Is.TypeOf (typeof (SqlEntityDefinitionExpression)));
      Assert.That (sqlStatement.SelectProjection.Type, Is.EqualTo (typeof (int)));
      Assert.That (((SqlEntityDefinitionExpression) sqlStatement.SelectProjection).TableAlias, Is.EqualTo ("c"));
      Assert.That (((SqlEntityDefinitionExpression) sqlStatement.SelectProjection).Name, Is.EqualTo ("CookTable"));

      commandBuilder.Append ("Value added by generation mixin");
      commandBuilder.SetInMemoryProjectionBody (Expression.Constant (null));
    }
Exemplo n.º 40
0
        public static void GenerateSql(Expression expression, ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
        {
            ArgumentUtility.CheckNotNull("expression", expression);
            ArgumentUtility.CheckNotNull("commandBuilder", commandBuilder);
            ArgumentUtility.CheckNotNull("stage", stage);

            var visitor = new SqlGeneratingExpressionVisitor(commandBuilder, stage);

            visitor.VisitExpression(expression);
        }
        public RelationalSqlExecutor(
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] IRelationalConnection connection)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));

            _sqlCommandBuilder = sqlCommandBuilder;
            _connection = connection;
        }
    public new static void GenerateSql (Expression expression, ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
    {
      ArgumentUtility.CheckNotNull ("expression", expression);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("stage", stage);

      EnsureNoCollectionExpression (expression);

      var visitor = new SqlGeneratingOuterSelectExpressionVisitor (commandBuilder, stage);
      visitor.VisitExpression (expression);
    }
        public SqliteDatabaseCreator(
            [NotNull] IRelationalConnection connection,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IModel model,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder)
            : base(model, connection, modelDiffer, migrationsSqlGenerator)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));

            _sqlCommandBuilder = sqlCommandBuilder;
        }
    private static void GenerateTextForSqlJoinedTable (IJoinInfoVisitor visitor, SqlJoinedTable joinedTable, ISqlCommandBuilder commandBuilder)
    {
      ArgumentUtility.CheckNotNull ("joinedTable", joinedTable);

      // TODO RMLNQSQL-4: This check can be removed.
      if (joinedTable.JoinSemantics == JoinSemantics.Inner)
        throw new NotSupportedException ("SqlJoinedTables with INNER JoinSemantics are currently not supported. (RMLNQSQL-4)");

      commandBuilder.Append (" LEFT OUTER JOIN ");

      joinedTable.JoinInfo.Accept (visitor);
    }
    public virtual void Build (
        SqlStatement sqlStatement, 
        ISqlCommandBuilder commandBuilder, 
        bool isOutermostStatement)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      BuildSelectPart (sqlStatement, commandBuilder, isOutermostStatement);
      BuildFromPart (sqlStatement, commandBuilder);
      BuildWherePart (sqlStatement, commandBuilder);
      BuildGroupByPart (sqlStatement, commandBuilder);
      BuildOrderByPart (sqlStatement, commandBuilder);
    }
Exemplo n.º 46
0
        public HistoryRepository(
            [NotNull] IDatabaseCreator databaseCreator,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] IRelationalAnnotationProvider annotations,
            [NotNull] ISqlGenerator sqlGenerator)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(annotations, nameof(annotations));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _databaseCreator = (IRelationalDatabaseCreator)databaseCreator;
            _sqlCommandBuilder = sqlCommandBuilder;
            _connection = connection;
            _modelDiffer = modelDiffer;
            _migrationsSqlGenerator = migrationsSqlGenerator;
            SqlGenerator = sqlGenerator;

            var relationalOptions = RelationalOptionsExtension.Extract(options);
            TableName = relationalOptions?.MigrationsHistoryTableName ?? DefaultTableName;
            TableSchema = relationalOptions.MigrationsHistoryTableSchema;
            _model = new LazyRef<IModel>(
                () =>
                {
                    var modelBuilder = new ModelBuilder(new ConventionSet());
                    modelBuilder.Entity<HistoryRow>(
                        x =>
                        {
                            ConfigureTable(x);
                            x.ToTable(TableName, TableSchema);
                        });

                    return modelBuilder.Model;
                });
            var entityType = new LazyRef<IEntityType>(() => _model.Value.FindEntityType(typeof(HistoryRow)));
            _migrationIdColumnName = new LazyRef<string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.MigrationId))).ColumnName);
            _productVersionColumnName = new LazyRef<string>(
                () => annotations.For(entityType.Value.FindProperty(nameof(HistoryRow.ProductVersion))).ColumnName);
        }
        public SqlServerQuerySqlGeneratorFactory(
            [NotNull] IRelationalCommandBuilderFactory commandBuilderFactory,
            [NotNull] ISqlGenerator sqlGenerator,
            [NotNull] IParameterNameGeneratorFactory parameterNameGeneratorFactory,
            [NotNull] ISqlCommandBuilder sqlCommandBuilder)
        {
            Check.NotNull(commandBuilderFactory, nameof(commandBuilderFactory));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));
            Check.NotNull(parameterNameGeneratorFactory, nameof(parameterNameGeneratorFactory));
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));

            _commandBuilderFactory = commandBuilderFactory;
            _sqlGenerator = sqlGenerator;
            _parameterNameGeneratorFactory = parameterNameGeneratorFactory;
            _sqlCommandBuilder = sqlCommandBuilder;
        }
        public RawSqlQueryGenerator(
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] SelectExpression selectExpression,
            [NotNull] string sql,
            [NotNull] object[] parameters)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));
            Check.NotNull(selectExpression, nameof(selectExpression));
            Check.NotNull(sql, nameof(sql));
            Check.NotNull(parameters, nameof(parameters));

            _sqlCommandBuilder = sqlCommandBuilder;
            _selectExpression = selectExpression;
            _sql = sql;
            _inputParameters = parameters;
        }
        public SqliteRelationalConnection(
            [NotNull] ISqlCommandBuilder sqlCommandBuilder,
            [NotNull] IDbContextOptions options,
            // ReSharper disable once SuggestBaseTypeForParameter
            [NotNull] ILogger<SqliteRelationalConnection> logger)
            : base(options, logger)
        {
            Check.NotNull(sqlCommandBuilder, nameof(sqlCommandBuilder));

            _sqlCommandBuilder = sqlCommandBuilder;

            var optionsExtension = options.Extensions.OfType<SqliteOptionsExtension>().FirstOrDefault();
            if (optionsExtension != null)
            {
                _enforceForeignKeys = optionsExtension.EnforceForeignKeys;
            }
        }
    protected virtual void BuildFromPart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      if (sqlStatement.SqlTables.Count > 0)
      {
        commandBuilder.Append (" FROM ");

        bool isFirstTable = true;
        foreach (var sqlTable in sqlStatement.SqlTables)
        {
          _stage.GenerateTextForFromTable (commandBuilder, sqlTable, isFirstTable);
          isFirstTable = false;
        }
      }
    }
    protected virtual void BuildSelectPart (
        SqlStatement sqlStatement,
        ISqlCommandBuilder commandBuilder,
        bool isOutermostStatement)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      commandBuilder.Append ("SELECT ");

      if (!(sqlStatement.SelectProjection is AggregationExpression))
      {
        BuildDistinctPart (sqlStatement, commandBuilder);
        BuildTopPart (sqlStatement, commandBuilder);
      }

      if (isOutermostStatement)
        _stage.GenerateTextForOuterSelectExpression (commandBuilder, sqlStatement.SelectProjection);
      else
        _stage.GenerateTextForSelectExpression (commandBuilder, sqlStatement.SelectProjection);
    }
    private static void GenerateTextForSqlTable (ITableInfoVisitor visitor, SqlTable sqlTable, ISqlCommandBuilder commandBuilder, bool isFirstTable)
    {
      if (sqlTable.JoinSemantics == JoinSemantics.Left)
      {
        if (isFirstTable)
          commandBuilder.Append ("(SELECT NULL AS [Empty]) AS [Empty]");
        commandBuilder.Append (" OUTER APPLY ");
      }
      else
      {
        if (!isFirstTable)
        {
          commandBuilder.Append (" CROSS ");
          if (sqlTable.TableInfo is ResolvedSimpleTableInfo)
            commandBuilder.Append ("JOIN ");
          else
            commandBuilder.Append ("APPLY ");
        }
      }

      sqlTable.TableInfo.Accept (visitor);
    }
    protected virtual void BuildWherePart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      if ((sqlStatement.WhereCondition != null))
      {
        commandBuilder.Append (" WHERE ");

        _stage.GenerateTextForWhereExpression (commandBuilder, sqlStatement.WhereCondition);
      }
    }
 public TestableSqlTableAndJoinTextGenerator (ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
     : base(commandBuilder, stage)
 {
   
 }
 protected virtual void BuildDistinctPart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
 {
   if (sqlStatement.IsDistinctQuery)
     commandBuilder.Append ("DISTINCT ");
 }
 protected virtual void BuildTopPart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
 {
   if (sqlStatement.TopExpression != null)
   {
     commandBuilder.Append ("TOP (");
     _stage.GenerateTextForTopExpression (commandBuilder, sqlStatement.TopExpression);
     commandBuilder.Append (") ");
   }
 }
    protected virtual void BuildOrderByPart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      if (sqlStatement.Orderings.Count > 0)
      {
        commandBuilder.Append (" ORDER BY ");
        commandBuilder.AppendSeparated (", ", sqlStatement.Orderings, _stage.GenerateTextForOrdering);
      }
    }
    protected virtual void BuildGroupByPart (SqlStatement sqlStatement, ISqlCommandBuilder commandBuilder)
    {
      ArgumentUtility.CheckNotNull ("sqlStatement", sqlStatement);
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);

      if (sqlStatement.GroupByExpression != null)
      {
        commandBuilder.Append (" GROUP BY ");

        _stage.GenerateTextForGroupByExpression (commandBuilder, sqlStatement.GroupByExpression);
      }
    }
 protected SqlGeneratingOuterSelectExpressionVisitor (ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
     : base (commandBuilder, stage)
 {
 }
    protected SqlTableAndJoinTextGenerator (ISqlCommandBuilder commandBuilder, ISqlGenerationStage stage)
    {
      ArgumentUtility.CheckNotNull ("commandBuilder", commandBuilder);
      ArgumentUtility.CheckNotNull ("stage", stage);

      _commandBuilder = commandBuilder;
      _stage = stage;
    }