90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DbMigrate {
|
|
public class SqlTable {
|
|
public string TableName { get; set; }
|
|
public string CreateTableSql { get; set; }
|
|
public string OriginalSql { get; set; }
|
|
public ColumnCollection Columns { get; set; }
|
|
public Dictionary<string, string> Indexes { get; set; }
|
|
public Dictionary<string, string> Triggers { get; set; }
|
|
|
|
|
|
|
|
public SqlTable() {
|
|
initTable();
|
|
}
|
|
|
|
public SqlTable(string sql) {
|
|
initTable();
|
|
OriginalSql = sql;
|
|
this.ParseSql(sql);
|
|
}
|
|
|
|
private void initTable() {
|
|
Columns = new ColumnCollection();
|
|
Indexes = new Dictionary<string, string>();
|
|
Triggers = new Dictionary<string, string>();
|
|
CreateTableSql = "";
|
|
}
|
|
|
|
public string FullSql() {
|
|
StringBuilder sb = new StringBuilder();
|
|
//sb.AppendLine("-- Create Table " + TableName);
|
|
sb.AppendLine(CreateTableSql);
|
|
|
|
if (Indexes.Count > 0) {
|
|
sb.AppendLine("\r\n-- Create Indexes");
|
|
foreach (string index in Indexes.Keys) {
|
|
sb.AppendLine(Indexes[index]);
|
|
}
|
|
}
|
|
|
|
if (Triggers.Count > 0) {
|
|
sb.AppendLine("\r\n-- Create Triggers");
|
|
foreach (string trigger in Triggers.Keys) {
|
|
sb.AppendLine(Triggers[trigger]);
|
|
}
|
|
}
|
|
|
|
sb.AppendLine();
|
|
return sb.ToString();
|
|
}
|
|
|
|
public string[] GetColumnNames() {
|
|
return Columns.GetColumnNames();
|
|
}
|
|
|
|
public bool HasColumn(string columnName) {
|
|
return Columns.Contains(columnName);
|
|
}
|
|
|
|
public string[] GetTriggerNames() {
|
|
return Triggers.Keys.ToArray();
|
|
}
|
|
|
|
public string[] GetTriggers() {
|
|
return Triggers.Values.ToArray();
|
|
}
|
|
|
|
public bool HasTrigger(string triggerName) {
|
|
return Triggers.ContainsKey(triggerName);
|
|
}
|
|
|
|
public bool HasIndex(string indexName) {
|
|
return Indexes.ContainsKey(indexName);
|
|
}
|
|
|
|
public string[] GetIndexNames() {
|
|
return Indexes.Keys.ToArray();
|
|
}
|
|
|
|
public string[] GetIndexes() {
|
|
return Indexes.Values.ToArray();
|
|
}
|
|
|
|
}
|
|
}
|