Implement complete database structure
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
3b07c687c4
commit
c40a857f8b
@ -4,6 +4,8 @@ import java.sql.Connection;
|
|||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DatabaseManager
|
public class DatabaseManager
|
||||||
{
|
{
|
||||||
@ -58,21 +60,53 @@ public class DatabaseManager
|
|||||||
|
|
||||||
public boolean initDb()
|
public boolean initDb()
|
||||||
{
|
{
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS pronouns (" +
|
List<String> newTables = new ArrayList<>();
|
||||||
"player text NOT NULL," +
|
|
||||||
"main_pronoun text," +
|
|
||||||
"secondary_pronoun text" +
|
|
||||||
");";
|
|
||||||
|
|
||||||
try (Statement stmt = dbConnection.createStatement()) {
|
newTables.add("CREATE TABLE IF NOT EXISTS players (" +
|
||||||
// create a new table
|
"player text NOT NULL," +
|
||||||
stmt.execute(sql);
|
"main_pronoun_id integer," +
|
||||||
} catch (SQLException e) {
|
"secondary_pronoun_id integer" +
|
||||||
logger.err(e.getMessage());
|
");");
|
||||||
return false;
|
|
||||||
|
newTables.add("CREATE TABLE IF NOT EXISTS pronouns (\" +\n" +
|
||||||
|
" \"pronoun text,\" +\n" +
|
||||||
|
" \"id integer\" +\n" +
|
||||||
|
" \");");
|
||||||
|
|
||||||
|
for(String sql : newTables)
|
||||||
|
{
|
||||||
|
try (Statement stmt = dbConnection.createStatement()) {
|
||||||
|
// execute the statement
|
||||||
|
stmt.execute(sql);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
logger.err(e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB STRUCTURE
|
||||||
|
* TABLE 1: PLAYERS
|
||||||
|
* -----------------------------------------------------------------
|
||||||
|
* | name | main_pronoun_id | secondary_pronoun_id |
|
||||||
|
* -----------------------------------------------------------------
|
||||||
|
* | AstroBea | 1 | 2 |
|
||||||
|
* | Notch | 3 | 1 |
|
||||||
|
* -----------------------------------------------------------------
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* TABLE 2: PRONOUNS
|
||||||
|
* --------------------------
|
||||||
|
* | pronoun | id |
|
||||||
|
* --------------------------
|
||||||
|
* | she | 1 |
|
||||||
|
* | her | 2 |
|
||||||
|
* | he | 3 |
|
||||||
|
* --------------------------
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user