initial
This commit is contained in:
79
SqlTable.cs
Normal file
79
SqlTable.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
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 Dictionary<string, string> Columns { get; set; }
|
||||
public Dictionary<string, string> Indexes { get; set; }
|
||||
public Dictionary<string, string> Triggers { get; set; }
|
||||
|
||||
|
||||
|
||||
public SqlTable() {
|
||||
Columns = new Dictionary<string, string>();
|
||||
Indexes = new Dictionary<string, string>();
|
||||
Triggers = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public SqlTable(string sql) {
|
||||
OriginalSql = sql;
|
||||
this.ParseSql(sql);
|
||||
}
|
||||
|
||||
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.Keys.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetColumns() {
|
||||
return Columns.Values.ToArray();
|
||||
}
|
||||
|
||||
public bool HasColumn(string columnName) {
|
||||
return Columns.ContainsKey(columnName);
|
||||
}
|
||||
|
||||
public string[] GetTriggerNames() {
|
||||
return Triggers.Keys.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetTriggers() {
|
||||
return Triggers.Values.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetIndexNames() {
|
||||
return Indexes.Keys.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetIndexes() {
|
||||
return Indexes.Values.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user