Fix SQL view not being deleted with dataset

This commit is contained in:
Kiana Sheibani 2023-10-05 22:08:13 -04:00
parent 376a8588b9
commit 38e0937d8f
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -86,7 +86,8 @@ pub fn delete_dataset(connection: &Connection, dataset: &str) -> sqlite::Result<
let query = format!( let query = format!(
r#"DELETE FROM datasets WHERE name = '{0}'; r#"DELETE FROM datasets WHERE name = '{0}';
DROP TABLE "{0}_players"; DROP TABLE "{0}_players";
DROP TABLE "{0}_network";"#, DROP TABLE "{0}_network";
DROP VIEW "{0}_view";"#,
dataset dataset
); );
@ -100,12 +101,12 @@ pub fn new_dataset(
) -> sqlite::Result<()> { ) -> sqlite::Result<()> {
let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?)"#; let query1 = r#"INSERT INTO datasets VALUES (?, ?, ?, ?, ?)"#;
let query2 = format!( let query2 = format!(
r#" r#"CREATE TABLE "{0}_players" (
CREATE TABLE "{0}_players" (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
name TEXT, name TEXT,
prefix TEXT prefix TEXT
); );
CREATE TABLE "{0}_network" ( CREATE TABLE "{0}_network" (
player_A INTEGER NOT NULL, player_A INTEGER NOT NULL,
player_B INTEGER NOT NULL, player_B INTEGER NOT NULL,
@ -128,8 +129,10 @@ pub fn new_dataset(
ON "{0}_network" (player_B); ON "{0}_network" (player_B);
CREATE VIEW "{0}_view" CREATE VIEW "{0}_view"
(player_A_id, player_B_id, player_A_name, player_B_name, advantage, sets_A, sets_B, games_A, games_B) AS (player_A_id, player_B_id, player_A_name, player_B_name, advantage,
SELECT players_A.id, players_B.id, players_A.name, players_B.name, advantage, sets_A, sets_B, games_A, games_B FROM "{0}_network" sets_A, sets_B, sets, games_A, games_B, games) AS
SELECT players_A.id, players_B.id, players_A.name, players_B.name, advantage,
sets_A, sets_B, sets_A + sets_B, games_A, games_B, games_A + games_B FROM "{0}_network"
INNER JOIN "{0}_players" players_A ON player_A = players_A.id INNER JOIN "{0}_players" players_A ON player_A = players_A.id
INNER JOIN "{0}_players" players_B ON player_B = players_B.id;"#, INNER JOIN "{0}_players" players_B ON player_B = players_B.id;"#,
dataset dataset