Skip to content

Commit

Permalink
Fix PreparedStatement bug in ScoreDB with null string fields.
Browse files Browse the repository at this point in the history
This was causing deleteScoreStmt to always fail.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Aug 10, 2015
1 parent 4195bb1 commit e68bcf8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/itdelatrisu/opsu/db/ScoreDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public static void init() {
"timestamp = ? AND MID = ? AND MSID = ? AND title = ? AND artist = ? AND " +
"creator = ? AND version = ? AND hit300 = ? AND hit100 = ? AND hit50 = ? AND " +
"geki = ? AND katu = ? AND miss = ? AND score = ? AND combo = ? AND perfect = ? AND mods = ? AND " +
"replay = ? AND playerName = ?"
"(replay = ? OR (replay IS NULL AND ? IS NULL)) AND " +
"(playerName = ? OR (playerName IS NULL AND ? IS NULL))"
// TODO: extra playerName checks not needed if name is guaranteed not null
);
} catch (SQLException e) {
ErrorHandler.error("Failed to prepare score statements.", e, true);
Expand Down Expand Up @@ -222,6 +224,7 @@ public static void addScore(ScoreData data) {
try {
setStatementFields(insertStmt, data);
insertStmt.setString(18, data.replayString);
insertStmt.setString(19, data.playerName);
insertStmt.executeUpdate();
} catch (SQLException e) {
ErrorHandler.error("Failed to save score to database.", e, true);
Expand All @@ -238,6 +241,10 @@ public static void deleteScore(ScoreData data) {

try {
setStatementFields(deleteScoreStmt, data);
deleteScoreStmt.setString(18, data.replayString);
deleteScoreStmt.setString(19, data.replayString);
deleteScoreStmt.setString(20, data.playerName);
deleteScoreStmt.setString(21, data.playerName);
deleteScoreStmt.executeUpdate();
} catch (SQLException e) {
ErrorHandler.error("Failed to delete score from database.", e, true);
Expand Down Expand Up @@ -289,8 +296,6 @@ private static void setStatementFields(PreparedStatement stmt, ScoreData data)
stmt.setInt(15, data.combo);
stmt.setBoolean(16, data.perfect);
stmt.setInt(17, data.mods);
stmt.setString(18, data.replayString);
stmt.setString(19, data.playerName);
}

/**
Expand Down

0 comments on commit e68bcf8

Please # to comment.