feat(sql): support null
This commit is contained in:
parent
f31868ccf6
commit
69e6fd0583
2 changed files with 7 additions and 10 deletions
|
@ -9,10 +9,7 @@ import net.artelnatif.nicko.storage.Storage;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -43,8 +40,8 @@ public class SQLStorage extends Storage {
|
||||||
|
|
||||||
final PreparedStatement statement = connection.prepareStatement(sql);
|
final PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
statement.setBinaryStream(1, uuidToBin(uuid));
|
statement.setBinaryStream(1, uuidToBin(uuid));
|
||||||
statement.setString(2, profile.getName());
|
statement.setString(2, profile.getName() == null ? null : profile.getName());
|
||||||
statement.setString(3, profile.getSkin());
|
statement.setString(3, profile.getSkin() == null ? null : profile.getSkin());
|
||||||
statement.setString(4, profile.getLocale().getCode());
|
statement.setString(4, profile.getLocale().getCode());
|
||||||
statement.setBoolean(5, profile.isBungeecordTransfer());
|
statement.setBoolean(5, profile.isBungeecordTransfer());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
@ -90,13 +87,13 @@ public class SQLStorage extends Storage {
|
||||||
String skin = "";
|
String skin = "";
|
||||||
String locale = "";
|
String locale = "";
|
||||||
boolean bungeecord = false;
|
boolean bungeecord = false;
|
||||||
while(resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
name = resultSet.getString("name");
|
name = resultSet.getString("name");
|
||||||
skin = resultSet.getString("skin");
|
skin = resultSet.getString("skin");
|
||||||
locale = resultSet.getString("locale");
|
locale = resultSet.getString("locale");
|
||||||
bungeecord = resultSet.getBoolean("bungeecord");
|
bungeecord = resultSet.getBoolean("bungeecord");
|
||||||
}
|
}
|
||||||
|
|
||||||
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
||||||
return Optional.of(profile);
|
return Optional.of(profile);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -57,8 +57,8 @@ public class SQLStorageProvider implements StorageProvider {
|
||||||
|
|
||||||
String query = "CREATE TABLE IF NOT EXISTS %s.DATA " +
|
String query = "CREATE TABLE IF NOT EXISTS %s.DATA " +
|
||||||
"(uuid binary(16) NOT NULL," +
|
"(uuid binary(16) NOT NULL," +
|
||||||
"name varchar(16) NOT NULL," +
|
"name varchar(16)," +
|
||||||
"skin varchar(16) NOT NULL," +
|
"skin varchar(16)," +
|
||||||
"locale char(2) NOT NULL," +
|
"locale char(2) NOT NULL," +
|
||||||
"bungeecord boolean NOT NULL," +
|
"bungeecord boolean NOT NULL," +
|
||||||
"PRIMARY KEY (UUID))";
|
"PRIMARY KEY (UUID))";
|
||||||
|
|
Loading…
Reference in a new issue