From f3f09a5b7b6917f6abfeadefd1efb1f23c7c1f8a Mon Sep 17 00:00:00 2001 From: meteorgan Date: Sat, 26 Apr 2025 00:00:29 +0800 Subject: [PATCH] Fix pragma page_count --- core/vdbe/execute.rs | 9 ++------- testing/pragma.test | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/vdbe/execute.rs b/core/vdbe/execute.rs index 928f7f94a..18f3ecf4f 100644 --- a/core/vdbe/execute.rs +++ b/core/vdbe/execute.rs @@ -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) } diff --git a/testing/pragma.test b/testing/pragma.test index c478c032c..29a460c65 100755 --- a/testing/pragma.test +++ b/testing/pragma.test @@ -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);