Merge pull request #166 from mlus-asuka/1.20.1-dev
SQL syntax fix about Database name
This commit is contained in:
commit
4e4ad80a95
|
|
@ -58,12 +58,12 @@ public class PlayerSync {
|
||||||
String dbName = JdbcConfig.DATABASE_NAME.get();
|
String dbName = JdbcConfig.DATABASE_NAME.get();
|
||||||
|
|
||||||
// Step 1: Create the database using a connection that does not select a database.
|
// Step 1: Create the database using a connection that does not select a database.
|
||||||
JDBCsetUp.executeUpdateWithoutDatabase("CREATE DATABASE IF NOT EXISTS " + dbName);
|
JDBCsetUp.executeUpdateWithoutDatabase("CREATE DATABASE IF NOT EXISTS `" + dbName + "`");
|
||||||
|
|
||||||
// Step 2: Explicitly select the database on a connection obtained without default database.
|
// Step 2: Explicitly select the database on a connection obtained without default database.
|
||||||
try (Connection conn = JDBCsetUp.getConnection(false);
|
try (Connection conn = JDBCsetUp.getConnection(false);
|
||||||
Statement st = conn.createStatement()) {
|
Statement st = conn.createStatement()) {
|
||||||
st.execute("USE " + dbName);
|
st.execute("USE `" + dbName + "`");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error("Error selecting database " + dbName, e);
|
LOGGER.error("Error selecting database " + dbName, e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
@ -72,7 +72,7 @@ public class PlayerSync {
|
||||||
// Step 3: Create and alter tables using fully qualified names.
|
// Step 3: Create and alter tables using fully qualified names.
|
||||||
// Create player_data table
|
// Create player_data table
|
||||||
JDBCsetUp.executeUpdate(
|
JDBCsetUp.executeUpdate(
|
||||||
"CREATE TABLE IF NOT EXISTS " + dbName + ".`player_data` (" +
|
"CREATE TABLE IF NOT EXISTS `" + dbName + "`.`player_data` (" +
|
||||||
"`uuid` char(36) NOT NULL," +
|
"`uuid` char(36) NOT NULL," +
|
||||||
"`inventory` mediumblob," +
|
"`inventory` mediumblob," +
|
||||||
"`armor` blob," +
|
"`armor` blob," +
|
||||||
|
|
@ -105,7 +105,7 @@ public class PlayerSync {
|
||||||
}
|
}
|
||||||
if (columnCount < 14) {
|
if (columnCount < 14) {
|
||||||
JDBCsetUp.executeUpdate(
|
JDBCsetUp.executeUpdate(
|
||||||
"ALTER TABLE " + dbName + ".player_data " +
|
"ALTER TABLE `" + dbName + "`.`player_data` " +
|
||||||
"ADD COLUMN left_hand blob, " +
|
"ADD COLUMN left_hand blob, " +
|
||||||
"ADD COLUMN cursors blob;"
|
"ADD COLUMN cursors blob;"
|
||||||
);
|
);
|
||||||
|
|
@ -113,7 +113,7 @@ public class PlayerSync {
|
||||||
|
|
||||||
// Create server_info table
|
// Create server_info table
|
||||||
JDBCsetUp.executeUpdate(
|
JDBCsetUp.executeUpdate(
|
||||||
"CREATE TABLE IF NOT EXISTS " + dbName + ".server_info (" +
|
"CREATE TABLE IF NOT EXISTS `" + dbName + "`.`server_info` (" +
|
||||||
"`id` INT NOT NULL," +
|
"`id` INT NOT NULL," +
|
||||||
"`enable` boolean NOT NULL," +
|
"`enable` boolean NOT NULL," +
|
||||||
"`last_update` BIGINT NOT NULL," +
|
"`last_update` BIGINT NOT NULL," +
|
||||||
|
|
@ -126,7 +126,7 @@ public class PlayerSync {
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
int data_version = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
int data_version = SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
||||||
JDBCsetUp.executeUpdate("""
|
JDBCsetUp.executeUpdate("""
|
||||||
INSERT INTO %s.server_info
|
INSERT INTO `%s`.`server_info`
|
||||||
(
|
(
|
||||||
id,
|
id,
|
||||||
enable,
|
enable,
|
||||||
|
|
@ -156,7 +156,7 @@ public class PlayerSync {
|
||||||
// Create curios table if the Curios mod is loaded
|
// Create curios table if the Curios mod is loaded
|
||||||
if (ModList.get().isLoaded("curios")) {
|
if (ModList.get().isLoaded("curios")) {
|
||||||
JDBCsetUp.executeUpdate(
|
JDBCsetUp.executeUpdate(
|
||||||
"CREATE TABLE IF NOT EXISTS " + dbName + ".curios (" +
|
"CREATE TABLE IF NOT EXISTS `" + dbName + "`.`curios` (" +
|
||||||
"uuid CHAR(36) NOT NULL, curios_item BLOB, PRIMARY KEY (uuid)" +
|
"uuid CHAR(36) NOT NULL, curios_item BLOB, PRIMARY KEY (uuid)" +
|
||||||
")"
|
")"
|
||||||
);
|
);
|
||||||
|
|
@ -165,7 +165,7 @@ public class PlayerSync {
|
||||||
// Create backpack_data table
|
// Create backpack_data table
|
||||||
if (ModList.get().isLoaded("sophisticatedbackpacks")) {
|
if (ModList.get().isLoaded("sophisticatedbackpacks")) {
|
||||||
JDBCsetUp.executeUpdateWithoutDatabase(
|
JDBCsetUp.executeUpdateWithoutDatabase(
|
||||||
"CREATE TABLE IF NOT EXISTS " + dbName + ".backpack_data (" +
|
"CREATE TABLE IF NOT EXISTS `" + dbName + "`.`backpack_data` (" +
|
||||||
"uuid CHAR(36) NOT NULL, backpack_nbt MEDIUMBLOB, PRIMARY KEY (uuid)" +
|
"uuid CHAR(36) NOT NULL, backpack_nbt MEDIUMBLOB, PRIMARY KEY (uuid)" +
|
||||||
");"
|
");"
|
||||||
);
|
);
|
||||||
|
|
@ -185,7 +185,7 @@ public class PlayerSync {
|
||||||
String dataType = rsAdvCol.getString("DATA_TYPE");
|
String dataType = rsAdvCol.getString("DATA_TYPE");
|
||||||
if (!"mediumblob".equalsIgnoreCase(dataType)) {
|
if (!"mediumblob".equalsIgnoreCase(dataType)) {
|
||||||
LOGGER.info("Altering player_data table to modify 'advancements' column from {} to MEDIUMBLOB.", dataType);
|
LOGGER.info("Altering player_data table to modify 'advancements' column from {} to MEDIUMBLOB.", dataType);
|
||||||
JDBCsetUp.executeUpdateWithoutDatabase("ALTER TABLE " + dbName + ".player_data MODIFY COLUMN advancements MEDIUMBLOB");
|
JDBCsetUp.executeUpdateWithoutDatabase("ALTER TABLE `" + dbName + "`.`player_data` MODIFY COLUMN advancements MEDIUMBLOB");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rsAdvCol.close();
|
rsAdvCol.close();
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,7 @@ public class VanillaSync {
|
||||||
|
|
||||||
// SQL Operation for player data
|
// SQL Operation for player data
|
||||||
if (init) {
|
if (init) {
|
||||||
JDBCsetUp.executeUpdate("INSERT INTO player_data (uuid,armor,inventory,enderchest,advancements,effects,xp,food_level,health,score,left_hand,cursors,online) VALUES ('" + player_uuid + "','" + equipment + "','" + inventoryMap + "','" + ender_chest + "','" + advancements + "','" + effectMap + "','" + XP + "','" + food_level + "','" + health + "','" + score + "','" + left_hand + "','" + cursors + "',online=true)");
|
JDBCsetUp.executeUpdate("INSERT INTO player_data (uuid,armor,inventory,enderchest,advancements,effects,xp,food_level,health,score,left_hand,cursors,online) VALUES ('" + player_uuid + "','" + equipment + "','" + inventoryMap + "','" + ender_chest + "','" + json + "','" + effectMap + "','" + XP + "','" + food_level + "','" + health + "','" + score + "','" + left_hand + "','" + cursors + "',online=true)");
|
||||||
} else {
|
} else {
|
||||||
JDBCsetUp.executeUpdate("UPDATE player_data SET inventory = '" + inventoryMap + "',armor='" + equipment + "' ,xp='" + XP + "',effects='" + effectMap + "',enderchest='" + ender_chest + "',score='" + score + "',food_level='" + food_level + "',health='" + health + "',advancements='" + json + "',left_hand='" + left_hand + "',cursors='" + cursors + "' WHERE uuid = '" + player_uuid + "'");
|
JDBCsetUp.executeUpdate("UPDATE player_data SET inventory = '" + inventoryMap + "',armor='" + equipment + "' ,xp='" + XP + "',effects='" + effectMap + "',enderchest='" + ender_chest + "',score='" + score + "',food_level='" + food_level + "',health='" + health + "',advancements='" + json + "',left_hand='" + left_hand + "',cursors='" + cursors + "' WHERE uuid = '" + player_uuid + "'");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class JDBCsetUp {
|
||||||
// Ensure that the connection uses the desired database by explicitly issuing "USE dbName"
|
// Ensure that the connection uses the desired database by explicitly issuing "USE dbName"
|
||||||
if (selectDatabase && dbName != null && !dbName.isEmpty()) {
|
if (selectDatabase && dbName != null && !dbName.isEmpty()) {
|
||||||
try (Statement st = conn.createStatement()) {
|
try (Statement st = conn.createStatement()) {
|
||||||
st.execute("USE " + dbName);
|
st.execute("USE `" + dbName + "`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return conn;
|
return conn;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user