From e68bcf8abc7ed85c92d23981e9f1e9febb6dfa54 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Mon, 10 Aug 2015 16:18:14 -0500 Subject: [PATCH] Fix PreparedStatement bug in ScoreDB with null string fields. This was causing deleteScoreStmt to always fail. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/db/ScoreDB.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/itdelatrisu/opsu/db/ScoreDB.java b/src/itdelatrisu/opsu/db/ScoreDB.java index 42ffe50d..34891987 100644 --- a/src/itdelatrisu/opsu/db/ScoreDB.java +++ b/src/itdelatrisu/opsu/db/ScoreDB.java @@ -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); @@ -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); @@ -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); @@ -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); } /**