Example #1
0
        private string GenerateSqlStatementConcrete(AddForeignKeyOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.DependentTable);
            ddlBuilder.AppendSql(" ADD CONSTRAINT ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name.Replace("dbo.", "").Replace("Jet.", ""));
            ddlBuilder.AppendSql(" FOREIGN KEY (");
            ddlBuilder.AppendIdentifierList(migrationOperation.DependentColumns);
            ddlBuilder.AppendSql(")");
            ddlBuilder.AppendSql(" REFERENCES ");
            ddlBuilder.AppendIdentifier(migrationOperation.PrincipalTable);
            ddlBuilder.AppendSql(" (");
            ddlBuilder.AppendIdentifierList(migrationOperation.PrincipalColumns);
            ddlBuilder.AppendSql(")");

            if (migrationOperation.CascadeDelete)
            {
                ddlBuilder.AppendSql(" ON DELETE CASCADE");
            }


            return(ddlBuilder.GetCommandText());
        }
Example #2
0
        private string GenerateSqlStatementConcrete(HistoryOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            foreach (DbModificationCommandTree commandTree in migrationOperation.CommandTrees)
            {
                List <DbParameter> parameters;
                // Take care because here we have several queries so we can't use parameters...
                switch (commandTree.CommandTreeKind)
                {
                case DbCommandTreeKind.Insert:
                    ddlBuilder.AppendSql(JetDmlBuilder.GenerateInsertSql((DbInsertCommandTree)commandTree, out parameters, true));
                    break;

                case DbCommandTreeKind.Delete:
                    ddlBuilder.AppendSql(JetDmlBuilder.GenerateDeleteSql((DbDeleteCommandTree)commandTree, out parameters, true));
                    break;

                case DbCommandTreeKind.Update:
                    ddlBuilder.AppendSql(JetDmlBuilder.GenerateUpdateSql((DbUpdateCommandTree)commandTree, out parameters, true));
                    break;

                case DbCommandTreeKind.Function:
                case DbCommandTreeKind.Query:
                default:
                    throw new InvalidOperationException(string.Format("Command tree of type {0} not supported in migration of history operations", commandTree.CommandTreeKind));
                }
                ddlBuilder.AppendSql(BATCHTERMINATOR);
            }

            return(ddlBuilder.GetCommandText());
        }
Example #3
0
        private string GenerateSqlStatementConcrete(DropTableOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("DROP TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            return(ddlBuilder.GetCommandText());
        }
Example #4
0
        private string GenerateSqlStatementConcrete(DropPrimaryKeyOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            ddlBuilder.AppendSql(" DROP CONSTRAINT ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            return(ddlBuilder.GetCommandText());
        }
Example #5
0
        private string GenerateSqlStatementConcrete(CreateIndexOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("CREATE ");
            if (migrationOperation.IsUnique)
            {
                ddlBuilder.AppendSql("UNIQUE ");
            }
            ddlBuilder.AppendSql("INDEX ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            ddlBuilder.AppendSql(" ON ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            ddlBuilder.AppendSql(" (");
            ddlBuilder.AppendIdentifierList(migrationOperation.Columns);
            ddlBuilder.AppendSql(")");

            return(ddlBuilder.GetCommandText());
        }
Example #6
0
        private string GenerateSqlStatementConcrete(AddPrimaryKeyOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            ddlBuilder.AppendSql(" ADD CONSTRAINT ");

            // respect name given to primary keys in migrations
            string pkName = migrationOperation.HasDefaultName ?
                            ddlBuilder.CreateConstraintName("PK", migrationOperation.Table) : // Take care because here names starts with "dbo."
                            migrationOperation.Name;

            ddlBuilder.AppendIdentifier(pkName);
            ddlBuilder.AppendSql(" PRIMARY KEY (");
            ddlBuilder.AppendIdentifierList(migrationOperation.Columns);
            ddlBuilder.AppendSql(")");
            return(ddlBuilder.GetCommandText());
        }
Example #7
0
        private string GenerateSqlStatementConcrete(AlterTableOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();


            foreach (ColumnModel column in migrationOperation.Columns)
            {
                ddlBuilder.AppendSql("ALTER TABLE ");
                ddlBuilder.AppendIdentifier(migrationOperation.Name);
                ddlBuilder.AppendSql(" ALTER COLUMN ");

                ddlBuilder.AppendIdentifier(column.Name);
                ddlBuilder.AppendSql(" ");
                TypeUsage storeType = JetProviderManifest.Instance.GetStoreType(column.TypeUsage);
                ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity);
                ddlBuilder.AppendSql(BATCHTERMINATOR);
            }

            return(ddlBuilder.GetCommandText());
        }
Example #8
0
        private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            ddlBuilder.AppendSql(" ADD COLUMN ");

            ColumnModel column = migrationOperation.Column;

            ddlBuilder.AppendIdentifier(column.Name);
            ddlBuilder.AppendSql(" ");
            TypeUsage storeType = JetProviderManifest.Instance.GetStoreType(column.TypeUsage);

            ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity);
            ddlBuilder.AppendNewLine();


            return(ddlBuilder.GetCommandText());
        }
Example #9
0
        private string GenerateSqlStatementConcrete(CreateTableOperation migrationOperation)
        {
            JetDdlBuilder ddlBuilder = new JetDdlBuilder();

            ddlBuilder.AppendSql("CREATE TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            ddlBuilder.AppendSql(" (");
            ddlBuilder.AppendNewLine();

            bool first = true;

            foreach (ColumnModel column in migrationOperation.Columns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    ddlBuilder.AppendSql(",");
                }

                ddlBuilder.AppendSql(" ");
                ddlBuilder.AppendIdentifier(column.Name);
                ddlBuilder.AppendSql(" ");
                TypeUsage storeTypeUsage = ProviderManifest.GetStoreType(column.TypeUsage);
                ddlBuilder.AppendType(storeTypeUsage, column.IsNullable ?? true, column.IsIdentity);
                ddlBuilder.AppendNewLine();
            }

            ddlBuilder.AppendSql(")");

            if (migrationOperation.PrimaryKey != null)
            {
                ddlBuilder.AppendSql(BATCHTERMINATOR);
                ddlBuilder.AppendSql(GenerateSqlStatementConcrete(migrationOperation.PrimaryKey));
            }

            return(ddlBuilder.GetCommandText());
        }