Fix saving into sql
This commit is contained in:
parent
bacc44b2b9
commit
d1872f6e95
|
|
@ -42,7 +42,7 @@ public class DatabaseQueue extends BukkitRunnable {
|
||||||
if (databaseQuery == null)
|
if (databaseQuery == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
databaseQuery.executeQuery(connection);
|
databaseQuery.execute(connection);
|
||||||
}
|
}
|
||||||
if (!connection.getAutoCommit()) {
|
if (!connection.getAutoCommit()) {
|
||||||
connection.commit();
|
connection.commit();
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
"uuid VARCHAR(36) NOT NULL, " +
|
"uuid VARCHAR(36) NOT NULL, " +
|
||||||
"PRIMARY KEY (uuid)" +
|
"PRIMARY KEY (uuid)" +
|
||||||
")";
|
")";
|
||||||
DatabaseQuery databaseQuery = new DatabaseQuery(userTable);
|
addDatabaseQuery(new DatabaseQuery(userTable), false);
|
||||||
databaseQuery.execute(getDatabaseConnection().get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseConnection getDatabaseConnection() {
|
public DatabaseConnection getDatabaseConnection() {
|
||||||
|
|
@ -101,7 +100,7 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
if (queue) {
|
if (queue) {
|
||||||
databaseQueue.databaseQueryQueue().offer(databaseQuery);
|
databaseQueue.databaseQueryQueue().offer(databaseQuery);
|
||||||
} else {
|
} else {
|
||||||
databaseQuery.executeQuery(getDatabaseConnection().get());
|
databaseQuery.execute(getDatabaseConnection().get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,9 +141,21 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(@NotNull User user) throws Exception {
|
public void save(@NotNull User user) throws Exception {
|
||||||
String sql = "INSERT INTO users WHERE uuid = ?"; // upsert query
|
// might not be the best way if new fields are added...
|
||||||
|
// split into multiple tables - users, userdata, userhomes, ... ?
|
||||||
|
String sql = "INSERT INTO users" +
|
||||||
|
"(uuid)" + // columns
|
||||||
|
"VALUES (?)" + // data
|
||||||
|
"ON DUPLICATE KEY UPDATE " + // data
|
||||||
|
"uuid = ?";
|
||||||
addDatabaseQuery(
|
addDatabaseQuery(
|
||||||
new DatabaseQuery(sql, ps -> ps.setString(1, user.getUUID().toString())), true
|
new DatabaseQuery(sql, new DatabaseQuery.DatabaseTask() {
|
||||||
|
@Override
|
||||||
|
public void edit(PreparedStatement ps) throws SQLException {
|
||||||
|
ps.setString(1, user.getUUID().toString());
|
||||||
|
ps.setString(2, user.getUUID().toString());
|
||||||
|
}
|
||||||
|
}), true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user