public override string WriteCreateTable(SQTable table) { // create the table StringBuilder sb = new StringBuilder(); sb.AppendLine("CREATE TABLE " + table.Name); sb.AppendLine("("); for (int i = 0; i < table.Columns.Count; i++) { SQColumn col = table.Columns[i]; sb.AppendLine((i > 0 ? "\t," : "\t") + GetCreateColumnText(col)); if (col.IsPrimary) { sb.AppendLine("\t,PRIMARY KEY (" + col.Name + ")"); } } sb.AppendLine(")"); sb.AppendLine("ENGINE=INNODB"); return(sb.ToString()); }
public override string WriteRemoveColumn(SQColumn col) { return(string.Format("ALTER TABLE dbo.{0} DROP COLUMN {1}", col.Table.Name, col.Name)); }
public virtual void RenameColumn(SQColumn col, string oldName) { ExecuteQuery(WriteRenameColumn(col, oldName)); }
public virtual void RemoveColumn(SQColumn col) { ExecuteQuery(WriteRemoveColumn(col)); }
public abstract string WriteAddForeignKey(SQColumn from, SQColumn to);
public abstract string WriteAddColumn(SQColumn col);
public SchemaColumn(SchemaTable table, List <SchemaHintColumn> hints, PropertyInfo pi) { Table = table; Hints = hints; Property = pi; SQDataTypes?datatype = GetDataTypeForType(pi.PropertyType); SQColumn res = new SQColumn() { Name = pi.Name }; res.Table = table.Table; if (datatype.HasValue) { res.DataType = datatype.Value; } bool ignore = false; foreach (SchemaHintColumn colHint in hints) { if (colHint._Ignore.HasValue) { ignore = colHint._Ignore.Value; } if (colHint.ColumnName != null) { res.Name = colHint.ColumnName; } if (colHint._IsIdentity.HasValue) { res.IsIdentity = colHint._IsIdentity.Value; } if (colHint._IsPrimary.HasValue) { res.IsPrimary = colHint._IsPrimary.Value; } if (colHint._Length.HasValue) { res.Length = colHint._Length.Value; } if (colHint._Precision.HasValue) { res.Precision = colHint._Precision.Value; } if (colHint._Scale.HasValue) { res.Scale = colHint._Scale.Value; } if (colHint._DataType.HasValue) { res.DataType = colHint._DataType.Value; } if (colHint._Serialization.HasValue) { Serialization = colHint._Serialization.Value; if (Serialization == SerializationTypes.SerializeBinary) { res.DataType = SQDataTypes.Bytes; } else if (Serialization == SerializationTypes.SerializeJSON || Serialization == SerializationTypes.SerializeXML) { res.DataType = SQDataTypes.String; } } if (colHint._Nullable.HasValue) { res.Nullable = colHint._Nullable.Value; } } if (!datatype.HasValue || ignore) { return; } Column = res; }
public override void RenameColumn(SQColumn col, string oldName) { ExecuteUpdateTable(WriteRenameColumn(col, oldName)); }
public SQColumn GetForeignKeyColumn(SQColumn local) { return(_Adapter.GetForeignKeyColumn(local)); }
private string GetCreateColumnText(SQColumn col) { return(string.Format("{0} {1} {2} NULL {3}", GetSafeObjectName(col.Name), GetSQLNameForType(col), col.Nullable ? "" : "NOT", col.IsIdentity ? "AUTO_INCREMENT" : "")); }
public override string WriteRemoveColumn(SQColumn col) { return("ALTER TABLE `" + col.Table.Name + "` DROP `" + col.Name + "`"); }
public override string WriteAddForeignKey(SQColumn from, SQColumn to) { return(string.Format("ALTER TABLE {0} ADD FOREIGN KEY ({1}) REFERENCES {2}({3});", from.Table.Name, from.Name, to.Table.Name, to.Name)); }
private string GetCreateColumnText(SQColumn col) { return(string.Format("{0} {1} {2} NULL {3}", col.Name, GetSQLNameForType(col), col.Nullable ? "" : "NOT", col.IsIdentity ? "IDENTITY(1, 1)" : "")); }
public override string WriteRenameColumn(SQColumn col, string oldName) { return(string.Format("EXECUTE sp_rename N'dbo.{0}.{1}', N'{2}', 'COLUMN'", col.Table.Name, oldName, col.Name)); }
public override void AddForeignKey(SQColumn from, SQColumn to) { ExecuteUpdateTable(WriteAddForeignKey(from, to)); }
public void AddColumn(SQColumn col) { _Adapter.AddColumn(col); }
public override void RemoveColumn(SQColumn col) { ExecuteUpdateTable(WriteRemoveColumn(col)); }
public void RemoveColumn(SQColumn col) { _Adapter.RemoveColumn(col); }
public override SQColumn GetForeignKeyColumn(SQColumn local) { throw new NotImplementedException(); }
public void RenameColumn(SQColumn col, string oldName) { _Adapter.RenameColumn(col, oldName); }
public virtual void AddColumn(SQColumn col) { ExecuteQuery(WriteAddColumn(col)); }
public void AddForeignKey(SQColumn from, SQColumn to) { _Adapter.AddForeignKey(from, to); }
// TODO: GetIndex, AddIndex public virtual void AddForeignKey(SQColumn from, SQColumn to) { ExecuteQuery(WriteAddForeignKey(from, to)); }
public override string WriteRemoveColumn(SQColumn col) { return("ALTER TABLE " + GetSafeObjectName(col.Table.Name) + " DROP `" + col.Name + "`"); }
public abstract SQColumn GetForeignKeyColumn(SQColumn local);
public override string WriteRenameColumn(SQColumn col, string oldName) { return("ALTER TABLE " + GetSafeObjectName(col.Table.Name) + " CHANGE COLUMN `" + oldName + "` " + GetCreateColumnText(col)); }
public abstract string WriteRemoveColumn(SQColumn col);
public override string WriteAddColumn(SQColumn col) { throw new NotImplementedException(); }
public abstract string WriteRenameColumn(SQColumn col, string oldName);
public override string WriteAddColumn(SQColumn col) { return(string.Format("ALTER TABLE dbo.{0} ADD {1}", col.Table.Name, GetCreateColumnText(col))); }