From e1da5aa7bcd1e7c167f43a0e7415cec8558a3221 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Wed, 20 May 2020 20:25:41 +0200 Subject: [PATCH 1/4] Missing backtick from RegionManager Group table. Group is a reserved keyword in MySQL 8. Requires backtick. Missed this from previous commit. Version 8 would error on table creation. --- TShockAPI/DB/RegionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index eaf8f1ba..ee62b8d3 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -51,7 +51,7 @@ namespace TShockAPI.DB new SqlColumn("WorldID", MySqlDbType.VarChar, 50) { Unique = true }, new SqlColumn("UserIds", MySqlDbType.Text), new SqlColumn("Protected", MySqlDbType.Int32), - new SqlColumn("Groups", MySqlDbType.Text), + new SqlColumn("`Groups`", MySqlDbType.Text), new SqlColumn("Owner", MySqlDbType.VarChar, 50), new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" } ); From a8366c6fbaf5cdf96230b9d8bc5a582be0869484 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Wed, 20 May 2020 20:28:56 +0200 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0563d49..8d890326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder) * Make sqlite db path configurable. (@AxeelAnder) +* Make TShock database MySQL 8 compatible by backticking `Group` column name in Region table. ## TShock 4.4.0 (Pre-release 4) * Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro) From 5706eaf1385a3b0d7c8ce10b3b196c37c9159feb Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Sun, 24 May 2020 02:02:50 +0200 Subject: [PATCH 3/4] Fix SQL incompatibility. This is the real fix for MySql8 compatibility, without breaking SQL. This will not affect current databases, all that happens is that we actually escape all column names on the table creation query. This should be standarized along the whole query builder. --- TShockAPI/DB/IQueryBuilder.cs | 8 ++++---- TShockAPI/DB/RegionManager.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/DB/IQueryBuilder.cs b/TShockAPI/DB/IQueryBuilder.cs index 825a2e4a..19af36a9 100644 --- a/TShockAPI/DB/IQueryBuilder.cs +++ b/TShockAPI/DB/IQueryBuilder.cs @@ -192,12 +192,12 @@ namespace TShockAPI.DB var columns = table.Columns.Select( c => - "{0} {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), + "`{0}` {1} {2} {3} {4} {5}".SFormat(c.Name, DbTypeToString(c.Type, c.Length), c.Primary ? "PRIMARY KEY" : "", c.AutoIncrement ? "AUTO_INCREMENT" : "", c.NotNull ? "NOT NULL" : "", c.DefaultCurrentTimestamp ? "DEFAULT CURRENT_TIMESTAMP" : "")); - var uniques = table.Columns.Where(c => c.Unique).Select(c => c.Name); + var uniques = table.Columns.Where(c => c.Unique).Select(c => $"`{c.Name}`"); return "CREATE TABLE {0} ({1} {2})".SFormat(EscapeTableName(table.Name), string.Join(", ", columns), uniques.Count() > 0 ? ", UNIQUE({0})".SFormat(string.Join(", ", uniques)) @@ -299,7 +299,7 @@ namespace TShockAPI.DB var create = CreateTable(to); // combine all columns in the 'from' variable excluding ones that aren't in the 'to' variable. // exclude the ones that aren't in 'to' variable because if the column is deleted, why try to import the data? - var columns = string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => c.Name)); + var columns = string.Join(", ", from.Columns.Where(c => to.Columns.Any(c2 => c2.Name == c.Name)).Select(c => $"`{c.Name}`")); var insert = "INSERT INTO {0} ({1}) SELECT {1} FROM {2}".SFormat(escapedTable, columns, tmpTable); var drop = "DROP TABLE {0}".SFormat(tmpTable); return "{0}; {1}; {2}; {3};".SFormat(alter, create, insert, drop); @@ -396,7 +396,7 @@ namespace TShockAPI.DB if (0 == wheres.Count) return string.Empty; - return "WHERE {0}".SFormat(string.Join(", ", wheres.Select(v => v.Name + " = " + v.Value))); + return "WHERE {0}".SFormat(string.Join(", ", wheres.Select(v => $"{v.Name}" + " = " + v.Value))); } } } diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs index ee62b8d3..eaf8f1ba 100644 --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -51,7 +51,7 @@ namespace TShockAPI.DB new SqlColumn("WorldID", MySqlDbType.VarChar, 50) { Unique = true }, new SqlColumn("UserIds", MySqlDbType.Text), new SqlColumn("Protected", MySqlDbType.Int32), - new SqlColumn("`Groups`", MySqlDbType.Text), + new SqlColumn("Groups", MySqlDbType.Text), new SqlColumn("Owner", MySqlDbType.VarChar, 50), new SqlColumn("Z", MySqlDbType.Int32){ DefaultValue = "0" } ); From 3e8a2cfb411a0888d9a3fba8adff1e2c52f5d508 Mon Sep 17 00:00:00 2001 From: Patrikkk Date: Sun, 24 May 2020 02:04:54 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d890326..62a10221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes * Update player spawn related things to 1.4. `Terraria.Player.Spawn` method now has a required argument, `PlayerSpawnContext context`. (@AxeelAnder) * Make sqlite db path configurable. (@AxeelAnder) -* Make TShock database MySQL 8 compatible by backticking `Group` column name in Region table. +* Make TShock database MySQL 8 compatible by escaping column names in our IQueryBuilder code. (Name `Groups` is a reserved element in this version, which is used in our `Region` table.) ## TShock 4.4.0 (Pre-release 4) * Debug logging now provides ConsoleDebug and ILog has been updated to support the concept of debug logs. Debug logs are now controlled by `config.json` instead of by preprocessor debug flag. (@hakusaro)