Exemple #1
0
        public override IDbCommand ADD_column(DBConnection db, string tableName, DBColumn column)
        {
            SqlCommand command = new SqlCommand();

            command.CommandText =
                $"ALTER TABLE {ToRealTableName(db.Application, tableName)} ADD {ColumnToSql(db, column, true)}";

            return(command);
        }
Exemple #2
0
        public override IDbCommand UPDATE_column(DBConnection db, string tableName, DBColumn column)
        {
            MySqlCommand command = new MySqlCommand();

            command.CommandText =
                $"ALTER TABLE {ToRealTableName(db.Application, tableName)} MODIFY COLUMN {ColumnToSql(db, column, true)}";

            return(command);
        }
Exemple #3
0
        public override string ColumnToSql(DBConnection db, DBColumn column, bool includeDefault)
        {
            DBForeignKey foreignKey = (column.Tabloid as DBTable).ForeignKeys.SingleOrDefault(fk => fk.SourceColumn == column.Name);

            return
                ($"{AddQuote(column.Name)} " +
                 $"{DataType.FullDefinition(column.Type, Type, column.MaxLength)} " +
                 $"{(column.IsPrimary ? AutoIncrement : "")}" +
                 $"{(column.IsNullable ? " NULL" : " NOT NULL")}" +
                 $"{(includeDefault && !string.IsNullOrEmpty(column.DefaultValue) ? $" CONSTRAINT {DefaultName(db.Application, column.Tabloid.Name, column.Name)} DEFAULT {column.DefaultValue}" : "")}");
        }
Exemple #4
0
        /// <summary>
        /// Checks check & defaults if changed
        /// </summary>
        public void RefreshConstraints(DBColumn dbColumn, DbColumn designerColumn)
        {
            /// check
            #warning TODO: DbColumn.check

            /// default
            string defaultValue = designerColumn.RealDefaultValue(dbColumn.Type);
            if (string.IsNullOrEmpty(defaultValue) != (dbColumn.DefaultValue == null) || dbColumn.DefaultValue != defaultValue)
            {
                // drop old
                if (dbColumn.DefaultValue != null)
                {
                    _db.Commands.Enqueue(_db.CommandSet.DROP_default(_db, Name, dbColumn.Name));
                }

                // create new
                if (!string.IsNullOrWhiteSpace(defaultValue))
                {
                    _db.Commands.Enqueue(_db.CommandSet.ADD_default(_db, Name, dbColumn.Name, defaultValue));
                }
            }
        }
Exemple #5
0
        public override IDbCommand RENAME_column(DBConnection db, string tableName, string oldColumnName, DBColumn newColumn)
        {
            MySqlCommand command = new MySqlCommand();

            command.CommandText =
                $"ALTER TABLE {ToRealTableName(db.Application, tableName)} CHANGE COLUMN {AddQuote(oldColumnName)} {ColumnToSql(db, newColumn, true)}";

            return(command);
        }
Exemple #6
0
        public override IDbCommand RENAME_column(DBConnection db, string tableName, string oldColumnName, DBColumn newColumn)
        {
            SqlCommand command = new SqlCommand();

            command.CommandText =
                $"sp_rename '{ToRealTableName(db.Application, tableName, false)}.{oldColumnName}', '{newColumn.Name}', 'COLUMN';";

            return(command);
        }
Exemple #7
0
 public abstract IDbCommand RENAME_column(DBConnection db, string tableName, string oldColumnName, DBColumn newColumn);
Exemple #8
0
 public abstract IDbCommand UPDATE_column(DBConnection db, string tableName, DBColumn column);