#![cfg(feature = "std")]
use std::process::Command;
fn sqlite3_available() -> bool {
Command::new("sqlite3").arg("--version").output().is_ok()
}
fn out(bin: &str, sql: &str) -> String {
let o = Command::new(bin).arg(":memory:").arg(sql).output().unwrap();
String::from_utf8_lossy(&o.stdout).into_owned()
}
#[test]
fn targeted_upsert_updates_the_named_conflict_row() {
if !sqlite3_available() {
eprintln!("sqlite3 CLI not found; skipping");
return;
}
let g = env!("CARGO_BIN_EXE_graphitesql");
let cases = [
"CREATE TABLE t(a INTEGER PRIMARY KEY, b UNIQUE, c);\
INSERT INTO t VALUES(2,-1,'x'),(3,1,9);\
INSERT INTO t VALUES(3,-1,3) ON CONFLICT(a) DO UPDATE SET b=3;\
SELECT quote(a),quote(b),quote(c) FROM t ORDER BY a;",
"CREATE TABLE t(a UNIQUE, b UNIQUE, c);\
INSERT INTO t VALUES(1,10,100),(2,20,200);\
INSERT INTO t VALUES(2,10,999) ON CONFLICT(b) DO UPDATE SET c=excluded.c;\
SELECT quote(a),quote(b),quote(c) FROM t ORDER BY a;",
"CREATE TABLE t(a INTEGER PRIMARY KEY, b UNIQUE, c);\
INSERT INTO t VALUES(5,50,'p'),(6,60,'q');\
INSERT INTO t VALUES(6,50,'z') ON CONFLICT(a) DO UPDATE SET c=excluded.c, b=t.b;\
SELECT quote(a),quote(b),quote(c) FROM t ORDER BY a;",
];
for sql in cases {
assert_eq!(out("sqlite3", sql), out(g, sql), "for `{sql}`");
}
}