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
2 changed files with 13 additions and 4 deletions

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();