Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-23 fix postgreSQL #24

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "org.lushplugins"
version = "3.3.0"
version = "3.3.1"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public JsonObject loadModuleUserDataJson(UUID uuid, String moduleId) {
assertJsonColumn(table, column);

try (Connection conn = conn();
PreparedStatement stmt = conn.prepareStatement(String.format("SELECT `%s` FROM `%s` WHERE uuid = ?;", column, table))
PreparedStatement stmt = conn.prepareStatement(String.format("SELECT %s FROM %s WHERE uuid = ?;", column, table))
) {
setUUIDToStatement(stmt, 1, uuid);

Expand Down Expand Up @@ -101,7 +101,7 @@ public void saveModuleUserData(UserDataModule.UserData userData) {
protected void assertTable(String table) {
try (Connection conn = conn();
PreparedStatement stmt = conn.prepareStatement(
String.format("CREATE TABLE IF NOT EXISTS `%s`(uuid CHAR(36) NOT NULL, PRIMARY KEY (uuid));", table))
String.format("CREATE TABLE IF NOT EXISTS %s(uuid CHAR(36) NOT NULL, PRIMARY KEY (uuid));", table))
) {
stmt.execute();
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class PostgreSQLStorage extends AbstractSQLStorage {
@Override
protected String getInsertOrUpdateStatement(String table, String column) {
return MessageFormat.format(
"INSERT INTO `{0}`(uuid, `{1}`) VALUES(?, ?) ON CONFLICT (uuid) DO UPDATE SET `{1}` = EXCLUDED.`{1}`;",
table, column
"INSERT INTO {0}(uuid, {1}) VALUES(?, ?) ON CONFLICT (uuid) DO UPDATE SET {1} = EXCLUDED.{1};",
table, column
);
}

Expand All @@ -48,13 +48,13 @@ protected void assertColumn(String table, String column, String type) {
assertTable(table);

try (Connection conn = conn();
PreparedStatement stmt = conn.prepareStatement(String.format("SELECT `%s` FROM `%s`", column, table))
PreparedStatement stmt = conn.prepareStatement(String.format("SELECT %s FROM %s", column, table))
) {
stmt.executeQuery();
} catch (SQLException assertException) {
if (Objects.equals(assertException.getSQLState(), "42703")) { // Undefined column error code
try (Connection conn = conn();
PreparedStatement stmt = conn.prepareStatement(String.format("ALTER TABLE `%s` ADD COLUMN `%s` %s;", table, column, type))
PreparedStatement stmt = conn.prepareStatement(String.format("ALTER TABLE %s ADD COLUMN %s %s;", table, column, type))
) {
stmt.execute();
} catch (SQLException alterException) {
Expand All @@ -66,6 +66,18 @@ protected void assertColumn(String table, String column, String type) {
}
}

@Override
protected void assertTable(String table) {
try (Connection conn = conn();
PreparedStatement stmt = conn.prepareStatement(
String.format("CREATE TABLE IF NOT EXISTS %s(uuid UUID NOT NULL, PRIMARY KEY (uuid));", table))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uuid is now of type UUID for PostgreSQL

) {
stmt.execute();
} catch (SQLException e) {
LushRewards.getInstance().getLogger().log(Level.SEVERE, "Failed to assert table: ", e);
}
}

@Override
protected String formatHeader(String string) {
return string.replace("-", "_");
Expand Down