Fix pragma page_count

This commit is contained in:
meteorgan
2025-04-26 00:00:29 +08:00
parent bde2d4f0a3
commit f3f09a5b7b
2 changed files with 3 additions and 8 deletions

View File

@@ -4229,13 +4229,8 @@ pub fn op_page_count(
// TODO: implement temp databases
todo!("temp databases not implemented yet");
}
// SQLite returns "0" on an empty database, and 2 on the first insertion,
// so we'll mimic that behavior.
let mut pages = pager.db_header.lock().database_size.into();
if pages == 1 {
pages = 0;
}
state.registers[*dest] = Register::OwnedValue(OwnedValue::Integer(pages));
let count = pager.db_header.lock().database_size.into();
state.registers[*dest] = Register::OwnedValue(OwnedValue::Integer(count));
state.pc += 1;
Ok(InsnFunctionStepResult::Step)
}

View File

@@ -35,7 +35,7 @@ do_execsql_test pragma-table-info-invalid-table {
do_execsql_test_on_specific_db ":memory:" pragma-page-count-empty {
PRAGMA page_count
} {0}
} {1}
do_execsql_test_on_specific_db ":memory:" pragma-page-count-table {
CREATE TABLE foo(bar);