Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ordinal order of columns for mysql #140

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Web/Managers/DbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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, "
Expand Down Expand Up @@ -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;
Expand All @@ -425,7 +425,7 @@ public static List<DbTable> GetTableParents(DbTable table)
queue.Push(table);

HashSet<DbTable> parents = new HashSet<DbTable>();

while (queue.Any())
{
var curr = queue.Pop();
Expand Down