use fsqlite_core::connection::Connection;
async fn ddl_err(ddl: &str) -> String {
let c = Connection::open(":memory:").await.unwrap();
c.execute(ddl)
.await
.expect_err("reserved name must be rejected")
.to_string()
}
#[test]
fn create_table_reserved_sqlite_name_rejected() {
asupersync::test_utils::run_test(|| async {
assert_eq!(
ddl_err("CREATE TABLE sqlite_foo(a)").await,
"object name reserved for internal use: sqlite_foo",
);
assert_eq!(
ddl_err("CREATE TABLE SQLITE_Bar(a)").await,
"object name reserved for internal use: SQLITE_Bar",
);
assert_eq!(
ddl_err("CREATE TABLE IF NOT EXISTS sqlite_baz(a)").await,
"object name reserved for internal use: sqlite_baz",
);
assert_eq!(
ddl_err("CREATE TABLE \"sqlite_q\"(a)").await,
"object name reserved for internal use: sqlite_q",
);
assert_eq!(
ddl_err("CREATE TABLE sqlite_(a)").await,
"object name reserved for internal use: sqlite_",
);
let c = Connection::open(":memory:").await.unwrap();
c.execute("CREATE TABLE sqlitex(a)")
.await
.expect("sqlitex is a valid name");
let c2 = Connection::open(":memory:").await.unwrap();
c2.execute("CREATE TABLE t(a INTEGER PRIMARY KEY AUTOINCREMENT, b)")
.await
.unwrap();
c2.execute("INSERT INTO t(b) VALUES('x')").await.unwrap();
let rows = c2
.query_with_params("SELECT name FROM sqlite_sequence", &[])
.await
.expect("sqlite_sequence must exist after AUTOINCREMENT insert");
assert_eq!(
rows.len(),
1,
"sqlite_sequence should have one row for table t"
);
});
}