Skip to content

Commit 9f8fcf8

Browse files
author
Kevin Bernau
committed
Fixed queries for tables that have a keyword as name
1 parent 8969f5e commit 9f8fcf8

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

MySQL-To-CSharp.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29424.173
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQL-To-CSharp", "MySQL-To-CSharp\MySQL-To-CSharp.csproj", "{8673C77C-EACF-4140-8357-1A2BEA96ED8E}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8673C77C-EACF-4140-8357-1A2BEA96ED8E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E46395F3-4E03-4361-8AE4-59C20466B060}
24+
EndGlobalSection
25+
EndGlobal

MySQL-To-CSharp/MySQL-To-CSharp.csproj

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,5 @@
5555
<None Include="App.config" />
5656
<None Include="packages.config" />
5757
</ItemGroup>
58-
<ItemGroup>
59-
<Content Include="docs\MySqlCommand.xml" />
60-
<Content Include="docs\MySqlCommandBuilder.xml" />
61-
<Content Include="docs\MySqlConnection.xml" />
62-
<Content Include="docs\MySqlConnectionStringBuilder.xml" />
63-
<Content Include="docs\MySqlDataAdapter.xml" />
64-
<Content Include="docs\MySqlDataReader.xml" />
65-
<Content Include="docs\MySqlException.xml" />
66-
<Content Include="docs\MySqlHelper.xml" />
67-
<Content Include="docs\MySqlParameter.xml" />
68-
<Content Include="docs\MySqlParameterCollection.xml" />
69-
<Content Include="docs\MySqlTransaction.xml" />
70-
</ItemGroup>
7158
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7259
</Project>

MySQL-To-CSharp/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
8686
// update query
8787
sb.AppendLine($"public string UpdateQuery()");
8888
sb.AppendLine("{");
89-
sb.Append($"return $\"UPDATE {table.Key} SET");
89+
sb.Append($"return $\"UPDATE `{table.Key}` SET");
9090
foreach (var column in table.Value)
9191
sb.Append($" {column.Name} = {{{column.Name.FirstCharUpper()}}},");
9292
sb.Remove(sb.ToString().LastIndexOf(','), 1);
@@ -96,7 +96,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
9696
// insert query
9797
sb.AppendLine($"public string InsertQuery()");
9898
sb.AppendLine("{");
99-
sb.Append($"return $\"INSERT INTO {table.Key} VALUES (");
99+
sb.Append($"return $\"INSERT INTO `{table.Key}` VALUES (");
100100
foreach (var column in table.Value)
101101
sb.Append($" {{{column.Name.FirstCharUpper()}}},");
102102
sb.Remove(sb.ToString().LastIndexOf(','), 1);
@@ -105,7 +105,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
105105
// delete query
106106
sb.AppendLine($"public string DeleteQuery()");
107107
sb.AppendLine("{");
108-
sb.AppendLine($"return $\"DELETE FROM {table.Key} WHERE {table.Value[0].Name} = {{{table.Value[0].Name.FirstCharUpper()}}};\";");
108+
sb.AppendLine($"return $\"DELETE FROM `{table.Key}` WHERE {table.Value[0].Name} = {{{table.Value[0].Name.FirstCharUpper()}}};\";");
109109
sb.AppendLine("}");
110110
}
111111

@@ -228,7 +228,7 @@ static void Main(string[] args)
228228
using (var cmd = con.CreateCommand())
229229
{
230230
// lul - is there a way to do this without this senseless statement?
231-
cmd.CommandText = $"SELECT * FROM {table.Key} LIMIT 0";
231+
cmd.CommandText = $"SELECT * FROM `{table.Key}` LIMIT 0";
232232
var reader = cmd.ExecuteReader();
233233
var schema = reader.GetSchemaTable();
234234
foreach (var column in table.Value)

0 commit comments

Comments
 (0)