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)
|
||||
return;
|
||||
|
||||
databaseQuery.executeQuery(connection);
|
||||
databaseQuery.execute(connection);
|
||||
}
|
||||
if (!connection.getAutoCommit()) {
|
||||
connection.commit();
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
"uuid VARCHAR(36) NOT NULL, " +
|
||||
"PRIMARY KEY (uuid)" +
|
||||
")";
|
||||
DatabaseQuery databaseQuery = new DatabaseQuery(userTable);
|
||||
databaseQuery.execute(getDatabaseConnection().get());
|
||||
addDatabaseQuery(new DatabaseQuery(userTable), false);
|
||||
}
|
||||
|
||||
public DatabaseConnection getDatabaseConnection() {
|
||||
|
|
@ -101,7 +100,7 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
if (queue) {
|
||||
databaseQueue.databaseQueryQueue().offer(databaseQuery);
|
||||
} else {
|
||||
databaseQuery.executeQuery(getDatabaseConnection().get());
|
||||
databaseQuery.execute(getDatabaseConnection().get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,9 +141,21 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
|
||||
@Override
|
||||
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(
|
||||
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