diff --git a/Plan/src/main/java/com/djrapitops/plan/database/sql/Select.java b/Plan/src/main/java/com/djrapitops/plan/database/sql/Select.java index 229c329b0..571f955ab 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/sql/Select.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/sql/Select.java @@ -22,4 +22,8 @@ public class Select extends WhereParser { Log.debug(parser.toString()); return parser; } + + public static Select all(String table) { + return new Select("SELECT * FROM " + table); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java index ee3acf084..5215aaa84 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/SecurityTable.java @@ -8,6 +8,8 @@ package main.java.com.djrapitops.plan.database.tables; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.data.WebUser; import main.java.com.djrapitops.plan.database.databases.SQLDB; +import main.java.com.djrapitops.plan.database.sql.Insert; +import main.java.com.djrapitops.plan.database.sql.Select; import main.java.com.djrapitops.plan.database.sql.Sql; import main.java.com.djrapitops.plan.database.sql.TableSqlParser; @@ -22,15 +24,12 @@ import java.util.List; */ public class SecurityTable extends Table { - private final String columnUser; - private final String columnSaltedHash; - private final String columnPermLevel; + private final String columnUser = "username"; + private final String columnSaltedHash = "salted_pass_hash"; + private final String columnPermLevel = "permission_level"; public SecurityTable(SQLDB db, boolean usingMySQL) { super("plan_security", db, usingMySQL); - columnUser = "username"; - columnSaltedHash = "salted_pass_hash"; - columnPermLevel = "permission_level"; } @Override @@ -71,11 +70,10 @@ public class SecurityTable extends Table { public void addNewUser(String user, String saltPassHash, int permLevel) throws SQLException { PreparedStatement statement = null; try { - statement = prepareStatement("INSERT INTO " + tableName + " (" - + columnUser + ", " - + columnSaltedHash + ", " - + columnPermLevel - + ") VALUES (?, ?, ?)"); + statement = prepareStatement(Insert.values(tableName, + columnUser, + columnSaltedHash, + columnPermLevel)); statement.setString(1, user); statement.setString(2, saltPassHash); statement.setInt(3, permLevel); @@ -94,7 +92,7 @@ public class SecurityTable extends Table { PreparedStatement statement = null; ResultSet set = null; try { - statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUser + "=?)"); + statement = prepareStatement(Select.all(tableName).where(columnUser + "=?").toString()); statement.setString(1, user); set = statement.executeQuery(); if (set.next()) { @@ -113,7 +111,7 @@ public class SecurityTable extends Table { PreparedStatement statement = null; ResultSet set = null; try { - statement = prepareStatement("SELECT * FROM " + tableName); + statement = prepareStatement(Select.all(tableName).toString()); set = statement.executeQuery(); List list = new ArrayList<>(); while (set.next()) {