Skip to content

Commit

Permalink
Fixed queries for tables that have a keyword as name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Bernau committed Dec 23, 2019
1 parent 8969f5e commit 9f8fcf8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
25 changes: 25 additions & 0 deletions MySQL-To-CSharp.sln
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions MySQL-To-CSharp/MySQL-To-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,5 @@
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="docs\MySqlCommand.xml" />
<Content Include="docs\MySqlCommandBuilder.xml" />
<Content Include="docs\MySqlConnection.xml" />
<Content Include="docs\MySqlConnectionStringBuilder.xml" />
<Content Include="docs\MySqlDataAdapter.xml" />
<Content Include="docs\MySqlDataReader.xml" />
<Content Include="docs\MySqlException.xml" />
<Content Include="docs\MySqlHelper.xml" />
<Content Include="docs\MySqlParameter.xml" />
<Content Include="docs\MySqlParameterCollection.xml" />
<Content Include="docs\MySqlTransaction.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions MySQL-To-CSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
// 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);
Expand All @@ -96,7 +96,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
// 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);
Expand All @@ -105,7 +105,7 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
// 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("}");
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9f8fcf8

Please sign in to comment.