Fixes BatchUpdateException: Subquery returns more than 1 row (#501):

- Added LIMIT 1 to all subqueries used in tables.
This commit is contained in:
Rsl1122 2018-01-24 13:00:25 +02:00
parent 097958c416
commit 118cbe7ee7
3 changed files with 22 additions and 4 deletions

View File

@ -47,8 +47,8 @@ public class ServerTable extends Table {
public ServerTable(SQLDB db) { public ServerTable(SQLDB db) {
super("plan_servers", db); super("plan_servers", db);
statementSelectServerID = "(" + Select.from(tableName, tableName + "." + columnServerID).where(columnServerUUID + "=?").toString() + ")"; statementSelectServerID = "(" + Select.from(tableName, tableName + "." + columnServerID).where(columnServerUUID + "=?").toString() + " LIMIT 1)";
statementSelectServerNameID = "(" + Select.from(tableName, tableName + "." + columnServerName).where(columnServerID + "=?").toString() + ")"; statementSelectServerNameID = "(" + Select.from(tableName, tableName + "." + columnServerName).where(columnServerID + "=?").toString() + " LIMIT 1)";
insertStatement = Insert.values(tableName, insertStatement = Insert.values(tableName,
columnServerUUID, columnServerUUID,
columnServerName, columnServerName,

View File

@ -29,7 +29,7 @@ public class UsersTable extends UserIDTable {
public UsersTable(SQLDB db) { public UsersTable(SQLDB db) {
super("plan_users", db); super("plan_users", db);
statementSelectID = "(" + Select.from(tableName, tableName + "." + columnID).where(columnUUID + "=?").toString() + ")"; statementSelectID = "(" + Select.from(tableName, tableName + "." + columnID).where(columnUUID + "=?").toString() + " LIMIT 1)";
insertStatement = Insert.values(tableName, insertStatement = Insert.values(tableName,
columnUUID, columnUUID,
columnRegistered, columnRegistered,

View File

@ -31,7 +31,7 @@ public class WorldTable extends Table {
public WorldTable(SQLDB db) { public WorldTable(SQLDB db) {
super("plan_worlds", db); super("plan_worlds", db);
statementSelectID = "(SELECT " + columnWorldId + " FROM " + tableName + " WHERE (" + columnWorldName + "=?))"; statementSelectID = "(SELECT " + columnWorldId + " FROM " + tableName + " WHERE (" + columnWorldName + "=?) LIMIT 1)";
} }
@Override @Override
@ -146,4 +146,22 @@ public class WorldTable extends Table {
} }
}); });
} }
public Map<String, Integer> getWorldIds() throws SQLException {
String sql = "SELECT DISTINCT " +
columnWorldName + ", " +
columnWorldId + " FROM " +
tableName;
return query(new QueryAllStatement<Map<String, Integer>>(sql, 200) {
@Override
public Map<String, Integer> processResults(ResultSet set) throws SQLException {
Map<String, Integer> worldIds = new HashMap<>();
while (set.next()) {
}
return worldIds;
}
});
}
} }