Add project files.
This commit is contained in:
97
Model/Table.cs
Normal file
97
Model/Table.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DbTools.Model {
|
||||
internal class Table {
|
||||
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 Table() {
|
||||
initTable();
|
||||
}
|
||||
|
||||
public Table(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("-- BEGIN TABLE " + TableName + " --");
|
||||
sb.AppendLine(CreateTableSql);
|
||||
|
||||
if (Indexes.Count > 0) {
|
||||
sb.AppendLine("\r\n-- INDEXES --");
|
||||
foreach (string index in Indexes.Keys) {
|
||||
sb.AppendLine(Indexes[index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Triggers.Count > 0) {
|
||||
sb.AppendLine("\r\n-- TRIGGERS --");
|
||||
foreach (string trigger in Triggers.Keys) {
|
||||
sb.AppendLine(Triggers[trigger]);
|
||||
}
|
||||
}
|
||||
|
||||
sb.AppendLine("-- END TABLE " + TableName + " --");
|
||||
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 HasTriggers() {
|
||||
return Triggers.Count > 0;
|
||||
}
|
||||
|
||||
public bool HasIndex(string indexName) {
|
||||
return Indexes.ContainsKey(indexName);
|
||||
}
|
||||
|
||||
public bool HasIndexes() {
|
||||
return Indexes.Count > 0;
|
||||
}
|
||||
|
||||
public string[] GetIndexNames() {
|
||||
return Indexes.Keys.ToArray();
|
||||
}
|
||||
|
||||
public string[] GetIndexes() {
|
||||
return Indexes.Values.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user