Support special table names - Fix #165 (#166)

This commit is contained in:
TechnicallyCoded 2023-07-16 00:36:12 +02:00 committed by GitHub
parent 5678934b0e
commit c3602ee5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -7,7 +7,7 @@
<groupId>me.SuperRonanCraft</groupId>
<artifactId>BetterRTP</artifactId>
<packaging>jar</packaging>
<version>3.6.10</version>
<version>3.6.11</version>
<!-- Upload patches to https://repo.ronanplugins.com/#/ -->

View File

@ -51,8 +51,12 @@ public class DatabaseCooldowns extends SQLite {
}
public void removePlayer(UUID uuid, World world) {
String sql = "DELETE FROM " + world.getName() + " WHERE "
+ COLUMNS.UUID.name + " = ?";
// Create SQL query string with backtick-ed table name to allow for special characters
String sql = String.format(
"DELETE FROM `%s` WHERE %s = ?",
world.getName(),
COLUMNS.UUID.name
);
List<Object> params = new ArrayList<Object>() {{
add(uuid.toString());
}};
@ -65,7 +69,12 @@ public class DatabaseCooldowns extends SQLite {
ResultSet rs = null;
try {
conn = getSQLConnection();
ps = conn.prepareStatement("SELECT * FROM " + world.getName() + " WHERE " + COLUMNS.UUID.name + " = ?");
// Create prepared statement with backtick-ed table name to allow for special characters
ps = conn.prepareStatement(String.format(
"SELECT * FROM `%s` WHERE %s = ?",
world.getName(),
COLUMNS.UUID.name
));
ps.setString(1, uuid.toString());
rs = ps.executeQuery();