/// <summary>
        /// Gets the structure of a source
        /// </summary>
        /// <param name="connectionInfo">Source to use</param>
        /// <returns>The source structure</returns>
        public async Task <ISource?> GetSourceStructureAsync(IConnection connectionInfo)
        {
            if (connectionInfo is null)
            {
                return(null);
            }
            var DatabaseName   = connectionInfo.DatabaseName ?? string.Empty;
            var DatabaseSource = new Connection(Configuration, connectionInfo.Factory, connectionInfo.ConnectionString.RemoveInitialCatalog(), "Name");

            if (!await SourceExistsAsync(DatabaseName, DatabaseSource).ConfigureAwait(false))
            {
                return(null);
            }
            var Temp = new Source(DatabaseName);

            Batch.CreateBatch(connectionInfo);
            for (int i = 0, QueryBuildersLength = QueryBuilders.Length; i < QueryBuildersLength; i++)
            {
                var Builder = QueryBuilders[i];
                Batch.AddQuery(CommandType.Text, Builder.GetCommand());
            }

            var Results = await Batch.ExecuteAsync().ConfigureAwait(false);

            for (int x = 0, QueryBuildersLength = QueryBuilders.Length; x < QueryBuildersLength; ++x)
            {
                var Builder = QueryBuilders[x];
                Builder.FillSource(Results[x], Temp);
            }
            return(Temp);
        }
Ejemplo n.º 2
0
        public void AddQueryWithParameters()
        {
            var Configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection()
                                .Build();
            var Instance = new Batch(new Connection(Configuration,
                                                    SqlClientFactory.Instance,
                                                    "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
                                                    "DATABASE NAME")
                                     );

            Instance.AddQuery((x, y, z) => { }, 10, "SELECT * FROM TestUsers WHERE UserID=@0", CommandType.Text, 1);
            Assert.NotNull(Instance);
            Assert.Equal("SELECT * FROM TestUsers WHERE UserID=1", Instance.ToString());
        }
Ejemplo n.º 3
0
        public void AddQuery()
        {
            var Configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection()
                                .Build();
            var Instance = new Batch(new Connection(Configuration,
                                                    SqlClientFactory.Instance,
                                                    "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",
                                                    "DATABASE NAME"),
                                     Canister.Builder.Bootstrapper.Resolve <ObjectPool <StringBuilder> >(),
                                     Canister.Builder.Bootstrapper.Resolve <DynamoFactory>(), null
                                     );

            Instance.AddQuery((___, __, _) => { }, 10, false, "SELECT * FROM TestUsers", CommandType.Text);
            Assert.NotNull(Instance);
            Assert.Equal("SELECT * FROM TestUsers", Instance.ToString());
        }
        /// <summary>
        /// Sets up the specified source.
        /// </summary>
        /// <param name="schemaChanges">The schema changes.</param>
        /// <param name="connection">The connection.</param>
        public async Task SetupAsync(string[] schemaChanges, IConnection connection)
        {
            if (connection is null || schemaChanges is null)
            {
                return;
            }
            var DatabaseConnectionString = connection.ConnectionString.RemoveInitialCatalog();

            Batch.CreateBatch(connection);
            for (var x = 0; x < schemaChanges.Length; ++x)
            {
                if (schemaChanges[x].IndexOf("CREATE DATABASE", System.StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    await OneOffQueries.CreateBatch(connection.Factory, DatabaseConnectionString)
                    .AddQuery(CommandType.Text, schemaChanges[x])
                    .ExecuteAsync().ConfigureAwait(false);
                }
                else if (schemaChanges[x].IndexOf("CREATE TRIGGER", System.StringComparison.InvariantCultureIgnoreCase) >= 0 || schemaChanges[x].IndexOf("CREATE FUNCTION", System.StringComparison.InvariantCultureIgnoreCase) >= 0 || schemaChanges[x].IndexOf("CREATE SCHEMA", System.StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    if (Batch.Count > 0)
                    {
                        await Batch.ExecuteAsync().ConfigureAwait(false);

                        Batch.CreateBatch();
                    }
                    Batch.AddQuery(CommandType.Text, schemaChanges[x]);
                    if (x < schemaChanges.Length - 1)
                    {
                        await Batch.ExecuteAsync().ConfigureAwait(false);

                        Batch.CreateBatch();
                    }
                }
                else
                {
                    Batch.AddQuery(CommandType.Text, schemaChanges[x]);
                }
            }
            await Batch.ExecuteAsync().ConfigureAwait(false);
        }