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" +
|
|
||||||
");";
|
|
||||||
|
|
||||||
|
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()) {
|
try (Statement stmt = dbConnection.createStatement()) {
|
||||||
// create a new table
|
// execute the statement
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.err(e.getMessage());
|
logger.err(e.getMessage());
|
||||||
return false;
|
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