Removed regex queries
Added nickname query but it's using the wrong connection, needs to either get a connection to the nickname db or something else
This commit is contained in:
parent
21a15c3817
commit
cec31f675e
|
|
@ -2,8 +2,6 @@ package com.alttd.chat.database;
|
||||||
|
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
import com.alttd.chat.objects.PartyUser;
|
import com.alttd.chat.objects.PartyUser;
|
||||||
import com.alttd.chat.objects.Regex;
|
|
||||||
import com.alttd.chat.objects.RegexType;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -20,7 +18,6 @@ public class Queries {
|
||||||
|
|
||||||
public static void createTables() {
|
public static void createTables() {
|
||||||
List<String> tables = new ArrayList<>();
|
List<String> tables = new ArrayList<>();
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS regex (`id` INT NOT NULL AUTO_INCREMENT, `regex` VARCHAR(2048) NOT NULL, `type` VARCHAR(32) NOT NULL, `replacement` VARCHAR(256) NULL, PRIMARY KEY (`id`))");
|
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))");
|
tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))");
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS party_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', PRIMARY KEY (`uuid`), FOREIGN KEY (party_id) REFERENCES parties(id) ON DELETE CASCADE)");
|
tables.add("CREATE TABLE IF NOT EXISTS party_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', PRIMARY KEY (`uuid`), FOREIGN KEY (party_id) REFERENCES parties(id) ON DELETE CASCADE)");
|
||||||
|
|
@ -38,40 +35,28 @@ public class Queries {
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
//Regex
|
//Nicknames
|
||||||
|
|
||||||
public static Regex getRegex() {
|
public static String getNickname(UUID uuid) {
|
||||||
String query = "SELECT * FROM regex";
|
//TODO use separate connection so it actually uses the nickname db...
|
||||||
|
String query = "SELECT nickname FROM nicknames WHERE uuid = ?";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
||||||
ResultSet resultSet = connection.prepareStatement(query).executeQuery();
|
PreparedStatement statement = connection.prepareStatement(query);
|
||||||
|
|
||||||
while (resultSet.next()) {
|
statement.setString(1, uuid.toString());
|
||||||
String regex = resultSet.getString("regex");
|
|
||||||
RegexType type = RegexType.getType(resultSet.getString("type"));
|
|
||||||
|
|
||||||
if (regex.isEmpty() || type == null) {
|
ResultSet resultSet = statement.executeQuery();
|
||||||
//TODO log this properly
|
|
||||||
System.out.println("INCORRECT LOGGING: regex was empty or type was invalid when getting from the database");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals(RegexType.REPLACE)) {
|
if (resultSet.next()) {
|
||||||
String replacement = resultSet.getString("replacement");
|
return resultSet.getString("nickname");
|
||||||
//TODO Add to list in util\Regex.java
|
|
||||||
new Regex(regex, type, replacement);
|
|
||||||
} else {
|
|
||||||
//TODO Add to list in util\Regex.java
|
|
||||||
new Regex(regex, type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user