From 9f8fcf8d528e1197fe7a0b18230e1a53ccc8f59e Mon Sep 17 00:00:00 2001 From: Kevin Bernau Date: Mon, 23 Dec 2019 15:25:03 +0100 Subject: [PATCH] Fixed queries for tables that have a keyword as name --- MySQL-To-CSharp.sln | 25 +++++++++++++++++++++++++ MySQL-To-CSharp/MySQL-To-CSharp.csproj | 13 ------------- MySQL-To-CSharp/Program.cs | 8 ++++---- 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 MySQL-To-CSharp.sln diff --git a/MySQL-To-CSharp.sln b/MySQL-To-CSharp.sln new file mode 100644 index 0000000..a6ac6f6 --- /dev/null +++ b/MySQL-To-CSharp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29424.173 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQL-To-CSharp", "MySQL-To-CSharp\MySQL-To-CSharp.csproj", "{8673C77C-EACF-4140-8357-1A2BEA96ED8E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E46395F3-4E03-4361-8AE4-59C20466B060} + EndGlobalSection +EndGlobal diff --git a/MySQL-To-CSharp/MySQL-To-CSharp.csproj b/MySQL-To-CSharp/MySQL-To-CSharp.csproj index d1f0c25..ec12fc6 100644 --- a/MySQL-To-CSharp/MySQL-To-CSharp.csproj +++ b/MySQL-To-CSharp/MySQL-To-CSharp.csproj @@ -55,18 +55,5 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/MySQL-To-CSharp/Program.cs b/MySQL-To-CSharp/Program.cs index e8daebd..88f1980 100644 --- a/MySQL-To-CSharp/Program.cs +++ b/MySQL-To-CSharp/Program.cs @@ -86,7 +86,7 @@ private static void DbToClasses(string dbName, Dictionary> // update query sb.AppendLine($"public string UpdateQuery()"); sb.AppendLine("{"); - sb.Append($"return $\"UPDATE {table.Key} SET"); + sb.Append($"return $\"UPDATE `{table.Key}` SET"); foreach (var column in table.Value) sb.Append($" {column.Name} = {{{column.Name.FirstCharUpper()}}},"); sb.Remove(sb.ToString().LastIndexOf(','), 1); @@ -96,7 +96,7 @@ private static void DbToClasses(string dbName, Dictionary> // insert query sb.AppendLine($"public string InsertQuery()"); sb.AppendLine("{"); - sb.Append($"return $\"INSERT INTO {table.Key} VALUES ("); + sb.Append($"return $\"INSERT INTO `{table.Key}` VALUES ("); foreach (var column in table.Value) sb.Append($" {{{column.Name.FirstCharUpper()}}},"); sb.Remove(sb.ToString().LastIndexOf(','), 1); @@ -105,7 +105,7 @@ private static void DbToClasses(string dbName, Dictionary> // delete query sb.AppendLine($"public string DeleteQuery()"); sb.AppendLine("{"); - sb.AppendLine($"return $\"DELETE FROM {table.Key} WHERE {table.Value[0].Name} = {{{table.Value[0].Name.FirstCharUpper()}}};\";"); + sb.AppendLine($"return $\"DELETE FROM `{table.Key}` WHERE {table.Value[0].Name} = {{{table.Value[0].Name.FirstCharUpper()}}};\";"); sb.AppendLine("}"); } @@ -228,7 +228,7 @@ static void Main(string[] args) using (var cmd = con.CreateCommand()) { // lul - is there a way to do this without this senseless statement? - cmd.CommandText = $"SELECT * FROM {table.Key} LIMIT 0"; + cmd.CommandText = $"SELECT * FROM `{table.Key}` LIMIT 0"; var reader = cmd.ExecuteReader(); var schema = reader.GetSchemaTable(); foreach (var column in table.Value)