private string GenerateSqlStatementConcrete(HistoryOperation migrationOperation)
        {
            SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder();

            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(SQLiteDmlBuilder.GenerateInsertSql((DbInsertCommandTree)commandTree, out parameters, true));
                    break;

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

                case DbCommandTreeKind.Update:
                    ddlBuilder.AppendSql(SQLiteDmlBuilder.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());
        }
        private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperation)
        {
            SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder();

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

            ColumnModel column = migrationOperation.Column;

            ddlBuilder.AppendIdentifier(column.Name);

            TypeUsage storeType = ProviderManifest.GetStoreType(column.TypeUsage);

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

            //DEFAULT VALUE
            if (column.DefaultValue != null)
            {
                if (column.DefaultValue is DateTime defaultValue)
                {
                    var format = "yyyy-MM-dd HH:mm:ss.ffffff";
                    if (defaultValue.Kind == DateTimeKind.Utc)
                    {
                        format += 'Z';
                    }
                    ddlBuilder.AppendSql($" DEFAULT '{defaultValue.ToString(format)}'");
                }
            }
            ddlBuilder.AppendNewLine();

            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 3
0
        private string GenerateSqlStatementConcrete(DropTableOperation migrationOperation)
        {
            var ddlBuilder = new SQLiteDdlBuilder();

            ddlBuilder.AppendSql("DROP TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 4
0
        private string GenerateSqlStatementConcrete(CreateTableOperation migrationOperation)
        {
            SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder();

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

            bool   first = true;
            string autoincrementColumnName = null;

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

                ddlBuilder.AppendSql(" ");
                ddlBuilder.AppendIdentifier(column.Name);
                ddlBuilder.AppendSql(" ");
                if (column.IsIdentity)
                {
                    autoincrementColumnName = column.Name;
                    ddlBuilder.AppendSql(" integer constraint ");
                    ddlBuilder.AppendIdentifier(ddlBuilder.CreateConstraintName("PK", migrationOperation.Name));
                    ddlBuilder.AppendSql(" primary key autoincrement");
                    ddlBuilder.AppendNewLine();
                }
                else
                {
                    TypeUsage storeTypeUsage = ProviderManifest.GetStoreType(column.TypeUsage);
                    ddlBuilder.AppendType(storeTypeUsage, column.IsNullable ?? true, column.IsIdentity);
                    if (!String.IsNullOrEmpty(column.DefaultValueSql))
                    {
                        ddlBuilder.AppendSql(" DEFAULT ");
                        ddlBuilder.AppendSql(column.DefaultValueSql);
                    }
                    ddlBuilder.AppendNewLine();
                }
            }

            if (migrationOperation.PrimaryKey != null && autoincrementColumnName == null)
            {
                ddlBuilder.AppendSql(",");
                ddlBuilder.AppendSql(GenerateSqlStatementConcrete(migrationOperation.PrimaryKey));
            }

            ddlBuilder.AppendSql(")");

            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 5
0
        private string GenerateSqlStatementConcrete(DropPrimaryKeyOperation migrationOperation)
        {
            var ddlBuilder = new SQLiteDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            ddlBuilder.AppendSql(" DROP CONSTRAINT ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            return(ddlBuilder.GetCommandText());
        }
        private string GenerateSqlStatementConcrete(DropIndexOperation migrationOperation)
        {
            SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder();

            ddlBuilder.AppendSql("DROP INDEX ");
            ddlBuilder.AppendIdentifier(SQLiteProviderManifestHelper.GetFullIdentifierName(migrationOperation.Table, migrationOperation.Name));
            ddlBuilder.AppendSql(" ON ");
            ddlBuilder.AppendIdentifier(migrationOperation.Table);
            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 7
0
        private string GenerateSqlStatementConcrete(RenameTableOperation migrationOperation)
        {
            var ddlBuilder = new SQLiteDdlBuilder();

            ddlBuilder.AppendSql("ALTER TABLE ");
            ddlBuilder.AppendIdentifier(migrationOperation.Name);
            ddlBuilder.AppendSql(" RENAME TO ");
            ddlBuilder.AppendIdentifier(migrationOperation.NewName);

            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 8
0
        private string GenerateSqlStatementConcrete(AddPrimaryKeyOperation migrationOperation)
        {
            // Actually primary key creation is supported only during table creation

            var ddlBuilder = new SQLiteDdlBuilder();

            ddlBuilder.AppendSql(" PRIMARY KEY (");
            ddlBuilder.AppendIdentifierList(migrationOperation.Columns);
            ddlBuilder.AppendSql(")");
            return(ddlBuilder.GetCommandText());
        }
Ejemplo n.º 9
0
        private string GenerateSqlStatementConcrete(AddColumnOperation migrationOperation)
        {
            var ddlBuilder = new SQLiteDdlBuilder();

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

            var column = migrationOperation.Column;

            ddlBuilder.AppendIdentifier(column.Name);
            ddlBuilder.AppendSql(" ");
            var storeType = this.ProviderManifest.GetStoreType(column.TypeUsage);

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

            return(ddlBuilder.GetCommandText());
        }
        private string GenerateSqlStatementConcrete(CreateIndexOperation migrationOperation)
        {
            SQLiteDdlBuilder ddlBuilder = new SQLiteDdlBuilder();

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

            return(ddlBuilder.GetCommandText());
        }