Esempio n. 1
0
        protected virtual void OnRenameIndexesTables(IndexesTableNames oldIndexesTableNames, IndexesTableNames newIndexesTableNames, string oldStructureTableName, string newStructureTableName)
        {
            using (var cmd = CreateSpCommand("sp_rename"))
            {
                for (var i = 0; i < oldIndexesTableNames.All.Length; i++)
                {
                    var oldTableName = oldIndexesTableNames[i];
                    var newTableName = newIndexesTableNames[i];

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", oldTableName),
                                                  new DacParameter("newname", newTableName),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", string.Format("FK_{0}_{1}", oldTableName, oldStructureTableName)),
                                                  new DacParameter("newname", string.Format("FK_{0}_{1}", newTableName, newStructureTableName)),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", string.Format("{0}.IX_{1}_Q", newTableName, oldTableName)),
                                                  new DacParameter("newname", string.Format("IX_{0}_Q", newTableName)),
                                                  new DacParameter("objtype", "INDEX"));
                    cmd.ExecuteNonQuery();
                }
            }
        }
Esempio n. 2
0
        public virtual void RenameStructureSet(string oldStructureName, string newStructureName)
        {
            EnsureValidDbObjectName(oldStructureName);
            EnsureValidDbObjectName(newStructureName);

            var oldStructureTableName = DbSchemaInfo.GenerateStructureTableName(oldStructureName);
            var newStructureTableName = DbSchemaInfo.GenerateStructureTableName(newStructureName);

            var oldSpatialTableName = DbSchemaInfo.GenerateSpatialTableName(oldStructureName);
            var newSpatialTableName = DbSchemaInfo.GenerateSpatialTableName(newStructureName);

            var oldUniquesTableName = DbSchemaInfo.GenerateUniquesTableName(oldStructureName);
            var newUniquesTableName = DbSchemaInfo.GenerateUniquesTableName(newStructureName);

            var oldIndexesTableNames = new IndexesTableNames(oldStructureName);
            var newIndexesTableNames = new IndexesTableNames(newStructureName);

            if (TableExists(newStructureTableName))
            {
                throw new SisoDbException("There allready seems to exist tables for '{0}' in the database.".Inject(newStructureTableName));
            }

            OnBeforeRenameOfStructureSet(oldStructureTableName, oldSpatialTableName, oldUniquesTableName, oldIndexesTableNames);
            OnRenameStructureTable(oldStructureTableName, newStructureTableName);
            if (TableExists(oldSpatialTableName))
            {
                OnRenameSpatialTable(oldSpatialTableName, newSpatialTableName, oldStructureTableName, newStructureTableName);
            }
            OnRenameUniquesTable(oldUniquesTableName, newUniquesTableName, oldStructureTableName, newStructureTableName);
            OnRenameIndexesTables(oldIndexesTableNames, newIndexesTableNames, oldStructureTableName, newStructureTableName);
            OnAfterRenameOfStructureSet(newStructureTableName, newSpatialTableName, newUniquesTableName, newIndexesTableNames);
        }
Esempio n. 3
0
        protected override void OnRenameIndexesTables(IndexesTableNames oldIndexesTableNames, IndexesTableNames newIndexesTableNames, string oldStructureTableName, string newStructureTableName)
        {
            using (var cmd = CreateCommand(null))
            {
                for (var i = 0; i < oldIndexesTableNames.All.Length; i++)
                {
                    var oldTableName = oldIndexesTableNames[i];
                    var newTableName = newIndexesTableNames[i];

                    cmd.Parameters.Clear();
                    Driver.AddCommandParametersTo(cmd,
                                                  new DacParameter("objname", oldTableName),
                                                  new DacParameter("newname", newTableName),
                                                  new DacParameter("objtype", "OBJECT"));
                    cmd.CommandText = "sp_rename @objname=@objname, @newname=@newname, @objtype=@objtype";
                    cmd.ExecuteNonQuery();
                }
            }
        }
        protected virtual IndexInsertAction CreateIndexInsertActionGroup(IStructureSchema structureSchema, IndexesTableNames indexesTableNames, DataTypeCode dataTypeCode, IStructureIndex[] indexes)
        {
            var container = new IndexInsertAction {
                Data = indexes
            };

            switch (dataTypeCode)
            {
            case DataTypeCode.IntegerNumber:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.IntegersTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.IntegersTableName);
                }
                break;

            case DataTypeCode.FractalNumber:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.FractalsTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.FractalsTableName);
                }
                break;

            case DataTypeCode.Bool:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.BooleansTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.BooleansTableName);
                }
                break;

            case DataTypeCode.DateTime:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.DatesTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.DatesTableName);
                }
                break;

            case DataTypeCode.Guid:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new ValueTypeIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.GuidsTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfValueTypeIndex(data[0], indexesTableNames.GuidsTableName);
                }
                break;

            case DataTypeCode.String:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new StringIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.StringsTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.StringsTableName);
                }
                break;

            case DataTypeCode.Enum:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new StringIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.StringsTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.StringsTableName);
                }
                break;

            case DataTypeCode.Text:
                if (container.Data.Length > 1)
                {
                    container.Action = (data, dbClient) => dbClient.BulkInsertIndexes(new TextIndexesReader(new IndexStorageSchema(structureSchema, indexesTableNames.TextsTableName), data));
                }
                if (container.Data.Length == 1)
                {
                    container.Action = (data, dbClient) => dbClient.SingleInsertOfStringTypeIndex(data[0], indexesTableNames.TextsTableName);
                }
                break;

            default:
                container.Action = null;
                break;
            }

            return(container);
        }
Esempio n. 5
0
 protected virtual void OnAfterRenameOfStructureSet(string newStructureTableName, string newSpatialTableName, string newUniquesTableName, IndexesTableNames newIndexesTableNames)
 {
 }
Esempio n. 6
0
 protected virtual void OnBeforeRenameOfStructureSet(string oldStructureTableName, string oldSpatialTableName, string oldUniquesTableName, IndexesTableNames oldIndexesTableNames)
 {
 }
Esempio n. 7
0
        public static void should_not_have_column_in_any_indexestables(this ITestDbUtils db, IndexesTableNames tableNames, string columnName)
        {
            var columnsPerTable = tableNames.All
                                  .GroupBy(t => t)
                                  .Select(t => new { Name = t.Key, HasRowId = db.GetColumns(t.Key).Any(c => c.Name == columnName) }).ToArray();

            columnsPerTable.Count(v => v.HasRowId).ShouldEqual(0);
        }
Esempio n. 8
0
        protected override void OnAfterRenameOfStructureSet(string newStructureTableName, string newSpatialTableName, string newUniquesTableName, IndexesTableNames newIndexesTableNames)
        {
            var addFkContraintSqlFormat = SqlStatements.GetSql("AddFkContraintAgainstStructureId");

            if (TableExists(newSpatialTableName))
            {
                ExecuteNonQuery(addFkContraintSqlFormat.Inject(newSpatialTableName, newStructureTableName));
            }
            ExecuteNonQuery(addFkContraintSqlFormat.Inject(newUniquesTableName, newStructureTableName));

            foreach (var newIndexTableName in newIndexesTableNames.All)
            {
                ExecuteNonQuery(addFkContraintSqlFormat.Inject(newIndexTableName, newStructureTableName));
            }
        }
Esempio n. 9
0
        protected override void OnBeforeRenameOfStructureSet(string oldStructureTableName, string oldSpatialTableName, string oldUniquesTableName, IndexesTableNames oldIndexesTableNames)
        {
            var dropFkContraintSqlFormat = SqlStatements.GetSql("DropFkContraint");

            if (TableExists(oldSpatialTableName))
            {
                ExecuteNonQuery(dropFkContraintSqlFormat.Inject(oldSpatialTableName, oldStructureTableName));
            }
            ExecuteNonQuery(dropFkContraintSqlFormat.Inject(oldUniquesTableName, oldStructureTableName));

            foreach (var oldIndexTableName in oldIndexesTableNames.All)
            {
                ExecuteNonQuery(dropFkContraintSqlFormat.Inject(oldIndexTableName, oldStructureTableName));
            }
        }
Esempio n. 10
0
        private void DropIndexesTables(IDbCommand cmd, IndexesTableStatuses statuses, IndexesTableNames names)
        {
            var sqlDropTableFormat = SqlStatements.GetSql("DropTable");

            if (statuses.IntegersTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.IntegersTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.FractalsTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.FractalsTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.BooleansTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.BooleansTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.DatesTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.DatesTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.GuidsTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.GuidsTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.StringsTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.StringsTableName);
                cmd.ExecuteNonQuery();
            }

            if (statuses.TextsTableExists)
            {
                cmd.CommandText = sqlDropTableFormat.Inject(names.TextsTableName);
                cmd.ExecuteNonQuery();
            }
        }
		public IndexesTableStatuses(IndexesTableNames names)
		{
			Names = names;
		}