Skip to content

Commit

Permalink
Lazy fix database issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fd committed Feb 18, 2017
1 parent 64272a6 commit c94a837
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/fluddokt/opsu/fake/GameOpsu.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

public class GameOpsu extends com.badlogic.gdx.Game {

public final static String VERSION = "0.15.0a";
public final static String VERSION = "0.15.0b";
public StateBasedGame sbg;

Stage stage;
Expand Down
23 changes: 11 additions & 12 deletions src/itdelatrisu/opsu/db/BeatmapDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/

package itdelatrisu.opsu.db;
import fluddokt.opsu.fake.*;
import itdelatrisu.opsu.Utils;
import java.io.IOException;

import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.beatmap.BeatmapParser;
import itdelatrisu.opsu.options.Options;


import java.io.IOException;
//import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand All @@ -37,10 +37,9 @@
import java.util.List;
import java.util.Map;

//import org.newdawn.slick.util.Log;


import fluddokt.opsu.fake.*;
/*
import org.newdawn.slick.util.Log;
*/

/**
* Handles connections and queries with the cached beatmap database.
Expand Down Expand Up @@ -208,16 +207,16 @@ private static void createDatabase() {
"md5hash TEXT, stars REAL, " +
"dateAdded INTEGER, favorite BOOLEAN, playCount INTEGER, lastPlayed INTEGER, localOffset INTEGER, " +
"video TEXT, videoOffset INTEGER" +
");\n" +
"); " +
"CREATE TABLE IF NOT EXISTS info (" +
"key TEXT NOT NULL UNIQUE, value TEXT" +
");\n" +
"CREATE INDEX IF NOT EXISTS idx ON beatmaps (dir, file);\n" +
"); " +
"CREATE INDEX IF NOT EXISTS idx ON beatmaps (dir, file); " +

// extra optimizations
"PRAGMA locking_mode = EXCLUSIVE;\n" +
"PRAGMA locking_mode = EXCLUSIVE; " +
"PRAGMA journal_mode = WAL;";
for (String sqlStmt : sql.split(";\n")){
for (String sqlStmt : sql.split(";")){
System.out.println("OsuDB SQLExec :"+sqlStmt+" "+stmt.execute(sqlStmt));
}

Expand Down
17 changes: 10 additions & 7 deletions src/itdelatrisu/opsu/db/ScoreDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
*/

package itdelatrisu.opsu.db;
import fluddokt.opsu.fake.Log;
import itdelatrisu.opsu.Utils;
import java.io.IOException;

import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.ScoreData;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.beatmap.Beatmap;
import itdelatrisu.opsu.options.Options;
import itdelatrisu.opsu.user.User;
import itdelatrisu.opsu.user.UserList;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -107,7 +107,6 @@ public static void init() {
if (connection == null)
return;


// run any database updates
updateDatabase();

Expand Down Expand Up @@ -168,7 +167,7 @@ private static void createDatabase() {
"mods INTEGER, " +
"replay TEXT, " +
"playerName TEXT"+
");\n" +
");" +
"CREATE TABLE IF NOT EXISTS users (" +
"name TEXT NOT NULL UNIQUE, " +
"score INTEGER, accuracy REAL, " +
Expand All @@ -177,9 +176,9 @@ private static void createDatabase() {
");" +
"CREATE TABLE IF NOT EXISTS info (" +
"key TEXT NOT NULL UNIQUE, value TEXT" +
");\n " +
"); " +
"CREATE INDEX IF NOT EXISTS idx ON scores (MID, MSID, title, artist, creator, version);";
for (String sqlStmt : sql.split(";\n")){
for (String sqlStmt : sql.split(";")){
System.out.println("ScoreDB SQLExec :"+sqlStmt+" "+stmt.execute(sqlStmt));
//stmt.e
}
Expand Down Expand Up @@ -231,7 +230,11 @@ private static void updateDatabase() {

// apply updates
for (String query : getUpdateQueries(version))
try {
stmt.executeUpdate(query);
} catch (SQLException e) {
Log.warn("Failed to update score database.", e);
}

// update version
if (infoExists) {
Expand Down

0 comments on commit c94a837

Please sign in to comment.