From be193936ac41e17bf42d0a390e0899cf0ad3a8f9 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 4 Oct 2022 07:02:14 +0100 Subject: [PATCH] Use ordinal order of columns for mysql --- Web/Managers/DbManager.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Web/Managers/DbManager.cs b/Web/Managers/DbManager.cs index 6feeb12..549587a 100644 --- a/Web/Managers/DbManager.cs +++ b/Web/Managers/DbManager.cs @@ -172,7 +172,7 @@ private DbModel GetDbModel(DatabaseType type, DbConnection conn, int connectionI + " AND C.TABLE_NAME = PK.TABLE_NAME " + " AND C.COLUMN_NAME = PK.COLUMN_NAME " + "WHERE C.TABLE_SCHEMA = @schema " - + "ORDER BY C.TABLE_NAME, COLUMN_NAME;"; + + "ORDER BY C.TABLE_NAME, C.ORDINAL_POSITION;"; cmd = CreateCommand(type, conn, sql); cmd.Parameters.Add(new MySqlParameter("@schema", databaseName)); } @@ -276,7 +276,7 @@ private DbModel GetDbModel(DatabaseType type, DbConnection conn, int connectionI result.Tables.Add(currentTable); } - if (tableName == currentTable.Name) + if (tableName == currentTable.Name) { currentTable.Columns.Add(new QueryTree.Models.DbColumn { @@ -354,7 +354,7 @@ private static void SetDbForeignKeys(DbModel dbModel, DatabaseType type, DbConne break; case DatabaseType.SQLServer: { - string sql = "SELECT C.TABLE_SCHEMA AS CHILD_TABLE_SCHEMA, " + string sql = "SELECT C.TABLE_SCHEMA AS CHILD_TABLE_SCHEMA, " + " C.TABLE_NAME AS CHILD_TABLE_NAME, " + " C.COLUMN_NAME AS CHILD_COLUMN_NAME, " + " P.TABLE_SCHEMA AS PARENT_TABLE_SCHEMA, " @@ -405,11 +405,11 @@ private static void SetDbForeignKeys(DbModel dbModel, DatabaseType type, DbConne DbTable dbTable = null; if (column.IsPrimaryKey == false && column.Parent == null) { - dbTable = dbModel.Tables.FirstOrDefault(t => - t.Schema == table.Schema && + dbTable = dbModel.Tables.FirstOrDefault(t => + t.Schema == table.Schema && ((t.Name.ToLower() + "_id") == column.Name.ToLower()) || ((t.Name.ToLower() + "id") == column.Name.ToLower())); - + if (dbTable != null) { column.Parent = dbTable.Columns[0] as Models.DbColumn; @@ -425,7 +425,7 @@ public static List GetTableParents(DbTable table) queue.Push(table); HashSet parents = new HashSet(); - + while (queue.Any()) { var curr = queue.Pop();