use fsqlite_core::connection::Connection;
async fn exec_err(setup: &[&str], sql: &str) -> String {
let c = Connection::open(":memory:").await.unwrap();
for s in setup {
c.execute(s).await.unwrap();
}
c.execute(sql)
.await
.expect_err("aggregate-in-WHERE misuse must error")
.to_string()
}
async fn exec_ok(setup: &[&str], sql: &str) {
let c = Connection::open(":memory:").await.unwrap();
for s in setup {
c.execute(s).await.unwrap();
}
c.execute(sql)
.await
.expect("valid query must succeed via execute()");
}
#[test]
fn execute_aggregate_in_where_reports_misuse() {
asupersync::test_utils::run_test(|| async {
let t: &[&str] = &["CREATE TABLE t(x)"];
assert_eq!(
exec_err(t, "SELECT max(x) FROM t WHERE max(x) > 0").await,
"misuse of aggregate: max()",
);
assert_eq!(
exec_err(t, "SELECT * FROM t WHERE sum(x) > 0").await,
"misuse of aggregate function sum()",
);
exec_ok(t, "SELECT * FROM t WHERE x > 0").await;
exec_ok(t, "SELECT sum(x) FROM t").await;
exec_ok(
&["CREATE TABLE t2(x)", "INSERT INTO t2 VALUES(1),(2)"],
"SELECT count(*) FROM t2",
)
.await;
});
}