From c40a857f8bca601b94359fbb025dbec875bffd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 23 Oct 2022 17:24:32 +0200 Subject: [PATCH] Implement complete database structure --- .../nounspicker/utils/DatabaseManager.java | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/main/java/wtf/beatrice/nounspicker/utils/DatabaseManager.java b/src/main/java/wtf/beatrice/nounspicker/utils/DatabaseManager.java index f66cbc9..b3a4484 100644 --- a/src/main/java/wtf/beatrice/nounspicker/utils/DatabaseManager.java +++ b/src/main/java/wtf/beatrice/nounspicker/utils/DatabaseManager.java @@ -4,6 +4,8 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; public class DatabaseManager { @@ -58,21 +60,53 @@ public class DatabaseManager public boolean initDb() { - String sql = "CREATE TABLE IF NOT EXISTS pronouns (" + - "player text NOT NULL," + - "main_pronoun text," + - "secondary_pronoun text" + - ");"; + List newTables = new ArrayList<>(); - try (Statement stmt = dbConnection.createStatement()) { - // create a new table - stmt.execute(sql); - } catch (SQLException e) { - logger.err(e.getMessage()); - return false; + newTables.add("CREATE TABLE IF NOT EXISTS players (" + + "player text NOT NULL," + + "main_pronoun_id integer," + + "secondary_pronoun_id integer" + + ");"); + + 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; } + /** + * 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 | + * -------------------------- + * + */ + }