From 012a0d173cffd48d892af1afc5a7ef8aaf233ed7 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Wed, 2 Aug 2023 18:31:04 +0200 Subject: [PATCH] Fix issues if there were too many migrations to run. Escape SQL values --- .../src/main/java/com/craftaro/core/database/DataManager.java | 2 +- .../main/java/com/craftaro/core/database/DataMigration.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/craftaro/core/database/DataManager.java b/Core/src/main/java/com/craftaro/core/database/DataManager.java index 4743ff4c..85222d07 100644 --- a/Core/src/main/java/com/craftaro/core/database/DataManager.java +++ b/Core/src/main/java/com/craftaro/core/database/DataManager.java @@ -188,7 +188,7 @@ public class DataManager { // Migrate the data for (DataMigration dataMigration : requiredMigrations) { - dataMigration.migrate(databaseConnector, getTablePrefix()); + dataMigration.migrate(connection, getTablePrefix()); } // Set the new current migration to be the highest migrated to diff --git a/Core/src/main/java/com/craftaro/core/database/DataMigration.java b/Core/src/main/java/com/craftaro/core/database/DataMigration.java index 268139ab..a4edc5d8 100644 --- a/Core/src/main/java/com/craftaro/core/database/DataMigration.java +++ b/Core/src/main/java/com/craftaro/core/database/DataMigration.java @@ -23,7 +23,7 @@ public abstract class DataMigration { this.revision = revision; } - public abstract void migrate(DatabaseConnector connector, String tablePrefix) throws SQLException; + public abstract void migrate(Connection connection, String tablePrefix) throws SQLException; /** * @return the revision number of this migration @@ -99,7 +99,7 @@ public abstract class DataMigration { if (value == null) { insertQuery.append("NULL"); } else if (value instanceof String || value instanceof Timestamp) { - insertQuery.append("'").append(value).append("'"); + insertQuery.append("'").append(value instanceof String ? ((String) value).replaceAll("'", "''") : value).append("'"); } else { insertQuery.append(value); }