protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns) { string priKey = null; for (int i = 0; i < columns.Length; i++) { ColumnDesc col = columns[i]; sql.Append(col.Column).Append(' ').Append(col.FormatType()); if (col.PrimaryKey) { priKey = col.Column; } if (col.AutoIncrement) { sql.Append(" AUTO_INCREMENT"); } if (col.NotNull) { sql.Append(" NOT NULL"); } if (i < columns.Length - 1) { sql.Append(','); } else if (priKey != null) { sql.Append(", PRIMARY KEY(").Append(priKey).Append(") "); } sql.AppendLine(); } }
/// <summary> Adds a new coloumn to the given table. </summary> /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks> public static void AddColumn(string table, ColumnDesc col, string colAfter) { ValidateName(table); string sql = Backend.AddColumnSql(table, col, colAfter); Execute(sql, null); }
public override void AddColumn(string table, ColumnDesc col, string colAfter) { ValidateTable(table); string syntax = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); Database.Execute(syntax); }
public override string AddColumnSql(string table, ColumnDesc col, string colAfter) { string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); if (colAfter.Length > 0) { sql += " AFTER " + colAfter; } return(sql); }
protected override void CreateTableColumns(StringBuilder sql, ColumnDesc[] columns) { string priKey = null; for (int i = 0; i < columns.Length; i++) { ColumnDesc col = columns[i]; sql.Append(col.Column).Append(' '); if (col.Type == ColumnType.Bool) { sql.Append("TINYINT"); } else { sql.Append(col.FormatType()); } // When the primary key isn't autoincrement, we use the same form as mysql // Otherwise we have to use sqlite's 'PRIMARY KEY AUTO_INCREMENT' form if (col.PrimaryKey) { if (!col.AutoIncrement) { priKey = col.Column; } else { sql.Append(" PRIMARY KEY"); } } if (col.AutoIncrement) { sql.Append(" AUTOINCREMENT"); } if (col.NotNull) { sql.Append(" NOT NULL"); } if (col.DefaultValue != null) { sql.Append(" DEFAULT ").Append(col.DefaultValue); } if (i < columns.Length - 1) { sql.Append(','); } else if (priKey != null) { sql.Append(", PRIMARY KEY(").Append(priKey).Append(") "); } sql.AppendLine(); } }
public override void AddColumn(string table, ColumnDesc col, string colAfter) { ValidateTable(table); string sql = "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); if (colAfter.Length > 0) { sql += " AFTER " + colAfter; } Database.Execute(sql, null); }
// == Higher level column functions == /// <summary> Adds a new coloumn to the given table. </summary> /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks> public abstract void AddColumn(string table, ColumnDesc col, string colAfter);
/// <summary> Returns SQL for adding a new coloumn to the given table. </summary> /// <remarks> Note colAfter is only a hint - some database backends ignore this. </remarks> public abstract string AddColumnSql(string table, ColumnDesc col, string colAfter);
public override string AddColumnSql(string table, ColumnDesc col, string colAfter) { return "ALTER TABLE `" + table + "` ADD COLUMN " + col.Column + " " + col.FormatType(); }