Use semicolons instead of commas as separator in sqlite string

This commit is contained in:
Kiana Sheibani 2023-11-18 20:41:04 -05:00
parent ff454e3cae
commit 361efe60a3
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -128,9 +128,9 @@ pub fn new_dataset(
volatility REAL NOT NULL, volatility REAL NOT NULL,
sets_won TEXT NOT NULL, sets_won TEXT NOT NULL,
sets_count_won INTEGER AS (length(sets_won) - length(replace(sets_won, ',', ''))), sets_count_won INTEGER AS (length(sets_won) - length(replace(sets_won, ';', ''))),
sets_lost TEXT NOT NULL, sets_lost TEXT NOT NULL,
sets_count_lost INTEGER AS (length(sets_lost) - length(replace(sets_lost, ',', ''))), sets_count_lost INTEGER AS (length(sets_lost) - length(replace(sets_lost, ';', ''))),
sets TEXT AS (sets_won || sets_lost), sets TEXT AS (sets_won || sets_lost),
sets_count INTEGER AS (sets_count_won + sets_count_lost) sets_count INTEGER AS (sets_count_won + sets_count_lost)
) STRICT; ) STRICT;
@ -141,9 +141,9 @@ CREATE TABLE "{0}_network" (
advantage REAL NOT NULL, advantage REAL NOT NULL,
sets_A TEXT NOT NULL, sets_A TEXT NOT NULL,
sets_count_A INTEGER AS (length(sets_A) - length(replace(sets_A, ',', ''))), sets_count_A INTEGER AS (length(sets_A) - length(replace(sets_A, ';', ''))),
sets_B TEXT NOT NULL, sets_B TEXT NOT NULL,
sets_count_B INTEGER AS (length(sets_B) - length(replace(sets_B, ',', ''))), sets_count_B INTEGER AS (length(sets_B) - length(replace(sets_B, ';', ''))),
sets TEXT AS (sets_A || sets_B), sets TEXT AS (sets_A || sets_B),
sets_count INTEGER AS (sets_count_A + sets_count_B), sets_count INTEGER AS (sets_count_A + sets_count_B),
@ -292,8 +292,8 @@ pub fn set_player_data(
) -> sqlite::Result<()> { ) -> sqlite::Result<()> {
let query = format!( let query = format!(
r#"UPDATE "{}_players" SET deviation = :dev, volatility = :vol, last_played = :last, r#"UPDATE "{}_players" SET deviation = :dev, volatility = :vol, last_played = :last,
sets_won = iif(:won, sets_won || :set || ',', sets_won), sets_won = iif(:won, sets_won || :set || ';', sets_won),
sets_lost = iif(:won, sets_lost, sets_lost || :set || ',') WHERE id = :id"#, sets_lost = iif(:won, sets_lost, sets_lost || :set || ';') WHERE id = :id"#,
dataset dataset
); );
@ -303,7 +303,7 @@ pub fn set_player_data(
statement.bind((":last", last_played.0 as i64))?; statement.bind((":last", last_played.0 as i64))?;
statement.bind((":id", player.0 as i64))?; statement.bind((":id", player.0 as i64))?;
statement.bind((":won", if won { 1 } else { 0 }))?; statement.bind((":won", if won { 1 } else { 0 }))?;
statement.bind((":set", set.0 as i64))?; statement.bind((":set", &set.0.to_string()[..]))?;
statement.next()?; statement.next()?;
Ok(()) Ok(())
} }
@ -376,8 +376,8 @@ WHERE (player_A = :pl AND player_B != :plo)
let query2 = format!( let query2 = format!(
r#"UPDATE "{}_network" r#"UPDATE "{}_network"
SET advantage = advantage + iif(:a > :b, -:v, :v), SET advantage = advantage + iif(:a > :b, -:v, :v),
sets_A = iif(:w = (:a > :b), sets_A || :set || ',', sets_A), sets_A = iif(:w = (:a > :b), sets_A || :set || ';', sets_A),
sets_B = iif(:w = (:b > :a), sets_B || :set || ',', sets_B) sets_B = iif(:w = (:b > :a), sets_B || :set || ';', sets_B)
WHERE player_A = min(:a, :b) AND player_B = max(:a, :b)"#, WHERE player_A = min(:a, :b) AND player_B = max(:a, :b)"#,
dataset dataset
); );
@ -405,7 +405,7 @@ WHERE player_A = min(:a, :b) AND player_B = max(:a, :b)"#,
statement.bind((":b", player2.0 as i64))?; statement.bind((":b", player2.0 as i64))?;
statement.bind((":v", adjust2 - adjust1))?; statement.bind((":v", adjust2 - adjust1))?;
statement.bind((":w", winner as i64))?; statement.bind((":w", winner as i64))?;
statement.bind((":set", set.0 as i64))?; statement.bind((":set", &set.0.to_string()[..]))?;
statement.into_iter().try_for_each(|x| x.map(|_| ())) statement.into_iter().try_for_each(|x| x.map(|_| ()))
} }