Ejemplo n.º 1
0
        private static void DropTables(StorageDriver driver, IEnumerable <Table> tables, ISqlExecutor executor)
        {
            var statements = BreakEvery(tables
                                        .Select(t => driver.Compile(SqlDdl.Drop(t)).GetCommandText()), 25);

            executor.ExecuteMany(statements);
        }
Ejemplo n.º 2
0
        private void DropAllTables(Schema schema, bool extractCatalogAfterDropping)
        {
            var batch       = SqlDml.Batch();
            var foreignKeys = schema.Tables.SelectMany(el => el.TableConstraints.OfType <ForeignKey>());

            foreach (var foreignKey in foreignKeys)
            {
                batch.Add(SqlDdl.Alter(foreignKey.Table, SqlDdl.DropConstraint(foreignKey)));
            }
            foreach (var view in schema.Views)
            {
                batch.Add(SqlDdl.Drop(view));
                schema.Tables.Remove(schema.Tables[view.Name]);
            }
            foreach (var table in schema.Tables)
            {
                batch.Add(SqlDdl.Drop(table));
            }
            if (batch.Count <= 0)
            {
                return;
            }
            var sqlCommand = SqlConnection.CreateCommand();

            sqlCommand.CommandText = SqlDriver.Compile(batch).GetCommandText();
            sqlCommand.ExecuteNonQuery();
            if (extractCatalogAfterDropping)
            {
                Catalog = SqlDriver.ExtractCatalog(SqlConnection);
            }
        }
        public void Test177()
        {
            Sequence        s    = schema.CreateSequence("Generator177");
            SqlDropSequence drop = SqlDdl.Drop(s);

            Console.Write(Compile(drop));
        }
        private void ClearSchema(SqlDriver driver)
        {
            using (var connection = driver.CreateConnection()) {
                connection.Open();
                try {
                    var schema      = driver.ExtractSchema(connection, SpecialSchemaAlias);
                    var foreignKeys = schema.Tables
                                      .Select(t => new {
                        Table       = t,
                        ForeignKeys = t.TableConstraints.OfType <ForeignKey>()
                    });
                    foreach (var dropConstraintText in from foreignKeyInfo in foreignKeys
                             from foreignKey in foreignKeyInfo.ForeignKeys
                             select driver.Compile(SqlDdl.Alter(foreignKeyInfo.Table, SqlDdl.DropConstraint(foreignKey))).GetCommandText())
                    {
                        using (var command = connection.CreateCommand(dropConstraintText))
                            command.ExecuteNonQuery();
                    }

                    foreach (var table in schema.Tables)
                    {
                        var dropTableText = driver.Compile(SqlDdl.Drop(table, true)).GetCommandText();
                        using (var command = connection.CreateCommand(dropTableText))
                            command.ExecuteNonQuery();
                    }
                }
                finally {
                    connection.Close();
                }
            }
        }
Ejemplo n.º 5
0
        private static void DropSequences(StorageDriver driver, IEnumerable <Sequence> sequences, ISqlExecutor executor)
        {
            var statements = BreakEvery(sequences
                                        .Select(s => driver.Compile(SqlDdl.Drop(s)).GetCommandText()), 25).ToChainedBuffer();

            executor.ExecuteMany(statements);
        }
Ejemplo n.º 6
0
        private void ExecuteDropView(SqlConnection connection, View view)
        {
            var createViewQuery = SqlDdl.Drop(view);

            using (var command = connection.CreateCommand(createViewQuery))
                command.ExecuteNonQuery();
        }
Ejemplo n.º 7
0
        private void ExecuteDropTable(SqlConnection connection, Table table)
        {
            var createTableQuery = SqlDdl.Drop(table);

            using (var command = connection.CreateCommand(createTableQuery))
                command.ExecuteNonQuery();
        }
Ejemplo n.º 8
0
        public void TableDeletionTest()
        {
            var defaultSchema = GetSchema();

            var table          = defaultSchema.Tables[TableName];
            var dropTableQuery = SqlDdl.Drop(table);

            TestQueryNamesReadable(dropTableQuery, defaultSchema);
        }
Ejemplo n.º 9
0
        private static Task DropTablesAsync(
            StorageDriver driver, IEnumerable <Table> tables, ISqlExecutor executor, CancellationToken token)
        {
            var statements = tables
                             .Select(t => driver.Compile(SqlDdl.Drop(t)).GetCommandText())
                             .ToList();

            return(executor.ExecuteManyAsync(statements, token));
        }
Ejemplo n.º 10
0
        public void Test161()
        {
            var   t     = Catalog.Schemas["main"].Tables["customer"];
            Index index = t.CreateIndex("MegaIndex196");

            index.CreateIndexColumn(t.TableColumns[0]);
            SqlDropIndex drop = SqlDdl.Drop(index);

            Console.Write(Compile(drop));
        }
Ejemplo n.º 11
0
        public void TableDeletionUnreadableNamesTest()
        {
            var defaultSchema = GetSchema();

            defaultSchema.Catalog.MakeNamesUnreadable();

            var table          = defaultSchema.Tables[TableName];
            var dropTableQuery = SqlDdl.Drop(table);

            TestQueryNamesUnreadable(dropTableQuery, defaultSchema);
        }
Ejemplo n.º 12
0
        protected void EnsureTableNotExists(Schema schema, string tableName)
        {
            var table = schema.Tables[tableName];

            if (table == null)
            {
                return;
            }
            ExecuteNonQuery(SqlDdl.Drop(table));
            schema.Tables.Remove(table);
        }
Ejemplo n.º 13
0
 protected override void TestFixtureTearDown()
 {
     if (schema != null)
     {
         Table t = schema.Tables[TableName];
         if (t != null)
         {
             ExecuteNonQuery(SqlDdl.Drop(t));
         }
     }
     base.TestFixtureTearDown();
 }
Ejemplo n.º 14
0
        private void DropDomain()
        {
            var schema = ExtractCatalog().DefaultSchema;
            var domain = schema.Domains["test_type"];

            if (domain == null)
            {
                return;
            }
            var commandText = Driver.Compile(SqlDdl.Drop(domain)).GetCommandText();

            ExecuteNonQuery(commandText);
        }
        /// <summary>
        /// Builds the descriptor of a temporary table.
        /// </summary>
        /// <param name="modelMapping">Model mapping.</param>
        /// <param name="name">The name of the temporary table.</param>
        /// <param name="source">The source.</param>
        /// <param name="fieldNames">The names of field in temporary table.</param>
        /// <returns>Built descriptor.</returns>
        public TemporaryTableDescriptor BuildDescriptor(ModelMapping modelMapping, string name, TupleDescriptor source, string[] fieldNames)
        {
            EnsureTemporaryTablesSupported();

            var hasColumns = source.Count > 0;

            // TODO: split this method to a set of various simple virtual methods
            var driver = Handlers.StorageDriver;

            var catalog   = new Catalog(modelMapping.TemporaryTableDatabase);
            var schema    = catalog.CreateSchema(modelMapping.TemporaryTableSchema);
            var collation = modelMapping.TemporaryTableCollation != null
        ? new Collation(schema, modelMapping.TemporaryTableCollation)
        : null;

            if (fieldNames == null)
            {
                fieldNames = BuildFieldNames(source);
            }

            var typeMappings = source
                               .Select(driver.GetTypeMapping)
                               .ToArray();

            // table
            var table    = CreateTemporaryTable(schema, name, source, typeMappings, fieldNames, collation);
            var tableRef = SqlDml.TableRef(table);

            // select statement
            var queryStatement = MakeUpSelectQuery(tableRef, hasColumns);

            // insert statement
            var storeRequestBindings = new List <PersistParameterBinding>();
            var insertStatement      = MakeUpInsertQuery(tableRef, typeMappings, storeRequestBindings, hasColumns);
            var result = new TemporaryTableDescriptor(name)
            {
                TupleDescriptor = source,
                QueryStatement  = queryStatement,
                CreateStatement = driver.Compile(SqlDdl.Create(table)).GetCommandText(),
                DropStatement   = driver.Compile(SqlDdl.Drop(table)).GetCommandText(),
                StoreRequest    = new PersistRequest(Handlers.StorageDriver, insertStatement, storeRequestBindings),
                ClearRequest    = new PersistRequest(Handlers.StorageDriver, SqlDml.Delete(tableRef), null)
            };

            result.StoreRequest.Prepare();
            result.ClearRequest.Prepare();

            return(result);
        }
Ejemplo n.º 16
0
        protected override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            catalog = ExtractCatalog();
            schema  = catalog.DefaultSchema;
            Table t = schema.Tables[TableName];

            if (t != null)
            {
                ExecuteNonQuery(SqlDdl.Drop(t));
                schema.Tables.Remove(t);
            }

            CreateTable();
        }
Ejemplo n.º 17
0
        public void FreeTextCreateTest()
        {
            var table    = Catalog.Schemas["Person"].Tables["Address"];
            var ftindex  = table.CreateFullTextIndex(string.Empty);
            var ftColumn = ftindex.CreateIndexColumn(table.Columns[1]);

            ftColumn.Languages.Add(new Language("English"));
            ftindex.UnderlyingUniqueIndex = "PK_Address_AddressID";
            var createIndex = SqlDdl.Create(ftindex);

            Console.WriteLine(sqlDriver.Compile(createIndex).GetCommandText());

            var dropIndex = SqlDdl.Drop(ftindex);

            Console.WriteLine(sqlDriver.Compile(dropIndex).GetCommandText());
        }
Ejemplo n.º 18
0
        private void DropSchema(Catalog catalog)
        {
            var schema    = catalog.DefaultSchema;
            var dropBatch = SqlDml.Batch();

            foreach (var constraint in schema.Tables.Where(t => t.TableConstraints.Count != 0).SelectMany(t => t.TableConstraints.OfType <ForeignKey>()))
            {
                if (dropBatch.Count > 31)
                {
                    ExecuteBatch(dropBatch);
                    dropBatch = SqlDml.Batch();
                }
                dropBatch.Add(SqlDdl.Alter(constraint.Table, SqlDdl.DropConstraint(constraint)));
            }

            foreach (var view in schema.Views)
            {
                if (dropBatch.Count > 31)
                {
                    ExecuteBatch(dropBatch);
                    dropBatch = SqlDml.Batch();
                }
                dropBatch.Add(SqlDdl.Drop(view));
                schema.Tables.Remove(schema.Tables[view.Name]);
            }

            foreach (var schemaTable in schema.Tables)
            {
                if (dropBatch.Count > 31)
                {
                    ExecuteBatch(dropBatch);
                    dropBatch = SqlDml.Batch();
                }
                dropBatch.Add(SqlDdl.Drop(schemaTable));
            }

            if (dropBatch.Count != 0)
            {
                ExecuteBatch(dropBatch);
            }
        }
Ejemplo n.º 19
0
        private void DropExistingMetadataTables(Schema schema, MetadataMapping mapping)
        {
            var assemblyTable  = schema.Tables[mapping.Assembly];
            var extensionTable = schema.Tables[mapping.Extension];
            var typeTable      = schema.Tables[mapping.Type];

            if (assemblyTable != null)
            {
                Execute(SqlDdl.Drop(assemblyTable));
                schema.Tables.Remove(assemblyTable);
            }
            if (extensionTable != null)
            {
                Execute(SqlDdl.Drop(extensionTable));
                schema.Tables.Remove(extensionTable);
            }
            if (typeTable != null)
            {
                Execute(SqlDdl.Drop(typeTable));
                schema.Tables.Remove(typeTable);
            }
        }
        public void Test152()
        {
            SqlDropSchema drop = SqlDdl.Drop(schema);

            Console.Write(Compile(drop));
        }
        public void Test151()
        {
            SqlDropTable drop = SqlDdl.Drop(schema.Tables["customer"]);

            Console.Write(Compile(drop));
        }
Ejemplo n.º 22
0
        public void Test151()
        {
            SqlDropTable drop = SqlDdl.Drop(Catalog.Schemas["main"].Tables["customer"]);

            Console.Write(Compile(drop));
        }
Ejemplo n.º 23
0
        public void Test152()
        {
            SqlDropSchema drop = SqlDdl.Drop(Catalog.Schemas["main"]);

            Assert.Throws <NotSupportedException>(() => Console.Write(Compile(drop)));
        }