Added test app
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -205,13 +206,30 @@ namespace DbTools.Model {
|
||||
cmd.CommandText = "select * from sqlite_master";
|
||||
using (var reader = cmd.ExecuteReader()) {
|
||||
while (reader.Read()) {
|
||||
if (reader["tbl_name"]?.ToString() == "sqlite_sequence") { continue; }
|
||||
if (reader["tbl_name"]?.ToString() == "sqlite_sequence" || string.IsNullOrEmpty(reader["sql"]?.ToString())) { continue; }
|
||||
string recordType = reader["type"]?.ToString();
|
||||
|
||||
if (recordType == "table") {
|
||||
string sql = reader["sql"]?.ToString();
|
||||
string tableName = reader["tbl_name"]?.ToString();
|
||||
Match m = Regex.Match(sql, "CREATE TABLE \\S+ \\((.*)\\)", RegexOptions.Singleline);
|
||||
if (!m.Success) {
|
||||
Trace.TraceWarning("Unable to match regex on table " + tableName);
|
||||
continue;
|
||||
}
|
||||
|
||||
string tableSql = "";
|
||||
int startIndex = m.Groups[1].Index;
|
||||
int length = m.Groups[1].Length;
|
||||
string columns = Regex.Replace(m.Groups[1].Value, "\\s{2,}", " ");
|
||||
columns = Regex.Replace(columns.Replace(", ", ",").Replace(",\n", ","), ",(?!\\d+\\))", ",\r\n\t");
|
||||
tableSql += sql.Substring(0, startIndex) + "\r\n\t" +
|
||||
columns.Trim() + "\r\n" +
|
||||
sql.Substring(startIndex + length) + ";";
|
||||
|
||||
Table table = new Table() {
|
||||
TableName = reader["tbl_name"]?.ToString(),
|
||||
CreateTableSql = reader["sql"]?.ToString(),
|
||||
CreateTableSql = tableSql,
|
||||
};
|
||||
Tables.Add(table);
|
||||
} else if (recordType == "index") {
|
||||
|
||||
Reference in New Issue
Block a user