Fix multiple SQL syntax issues
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
27544accb1
commit
e6534c54e1
@ -29,7 +29,7 @@ public class DatabaseManager
|
||||
logger.log("Database connection established!");
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class DatabaseManager
|
||||
dbConnection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ public class DatabaseManager
|
||||
// execute the statement
|
||||
stmt.execute(sql);
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ public class DatabaseManager
|
||||
}
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -149,7 +149,7 @@ public class DatabaseManager
|
||||
return true;
|
||||
} catch (SQLException e)
|
||||
{
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -163,9 +163,10 @@ public class DatabaseManager
|
||||
|
||||
try (Statement stmt = dbConnection.createStatement()) {
|
||||
ResultSet rSet = stmt.executeQuery(query);
|
||||
if(rSet.isClosed()) return -1;
|
||||
return rSet.getInt("id");
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -184,7 +185,7 @@ public class DatabaseManager
|
||||
preparedStatement.setString(1, pronoun);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -203,7 +204,7 @@ public class DatabaseManager
|
||||
try(Statement stmt = dbConnection.createStatement()) {
|
||||
stmt.executeUpdate(q);
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -214,9 +215,25 @@ public class DatabaseManager
|
||||
|
||||
public boolean setPlayerPronouns(String playerName, String mainPronoun, String secondaryPronoun) {
|
||||
|
||||
// if the player is not in the table, add them
|
||||
if(!hasPronouns(playerName))
|
||||
{
|
||||
String query = "INSERT INTO players (player) VALUES (?);";
|
||||
|
||||
try(PreparedStatement pStatement = dbConnection.prepareStatement(query)) {
|
||||
pStatement.setString(1, playerName);
|
||||
pStatement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get pronouns ids
|
||||
int mainPronounId = getPronounId(mainPronoun);
|
||||
int secondaryPronounId = getPronounId(secondaryPronoun);
|
||||
|
||||
// update player values in the table
|
||||
String query = "UPDATE players " +
|
||||
"SET (main_pronoun_id, secondary_pronoun_id) = (?,?) " +
|
||||
"WHERE player = ?;";
|
||||
@ -228,7 +245,7 @@ public class DatabaseManager
|
||||
pStatement.executeUpdate();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -242,13 +259,33 @@ public class DatabaseManager
|
||||
try (Statement stmt = dbConnection.createStatement())
|
||||
{
|
||||
ResultSet rSet = stmt.executeQuery(query);
|
||||
return rSet.getString("id");
|
||||
return rSet.getString("format");
|
||||
} catch (SQLException e) {
|
||||
logger.err(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasPronouns(String playerName) {
|
||||
String query = "SELECT player FROM players " +
|
||||
"WHERE player = ? " +
|
||||
"LIMIT 1;";
|
||||
|
||||
try (PreparedStatement pStatement = dbConnection.prepareStatement(query)) {
|
||||
pStatement.setString(1, playerName);
|
||||
ResultSet rSet = pStatement.executeQuery();
|
||||
if(rSet.isClosed()) return false;
|
||||
while(rSet.next())
|
||||
{
|
||||
if(rSet.getString("player").equals(playerName)) return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user