mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
Applications that run checkpoints themselves, or that want the WAL to grow more or less than 1000 pages, set PRAGMA wal_autocheckpoint as SQLite documents it. Turso ignored the pragma as an unknown name, so a connection that turned automatic checkpoints off still got one after any commit that left more than 1000 frames in the WAL. PRAGMA wal_autocheckpoint returns the connection's threshold, 1000 by default. PRAGMA wal_autocheckpoint = N sets it for this connection only and returns the new value. Zero, a negative value, or a value too large for a 32-bit int turns automatic checkpoints off and reads back as 0, as in SQLite. Closing the last connection still checkpoints the WAL: SQLite runs that checkpoint whatever this setting is. Like SQLite, the pragma has no pragma_wal_autocheckpoint table-valued function. Tests: cargo test -p core_tester --test integration_tests pragma_wal_autocheckpoint Tests: sqltest run sqlite-sqltests/pragma/memory.sqltest -f 'pragma-wal-autocheckpoint-*'
369 lines
6.7 KiB
Plaintext
369 lines
6.7 KiB
Plaintext
@database :memory:
|
|
|
|
test pragma-cache-size-default {
|
|
PRAGMA cache_size
|
|
}
|
|
expect {
|
|
-2000
|
|
}
|
|
|
|
# 200 is minimum cache size value, so we test for this
|
|
test pragma-set-cache-size {
|
|
PRAGMA cache_size = 200;
|
|
PRAGMA cache_size
|
|
}
|
|
expect {
|
|
200
|
|
}
|
|
|
|
# Even though the cache size was set to 100 in previous test, a new connection defaults back to -2000.
|
|
test pragma-cache-size {
|
|
PRAGMA cache_size
|
|
}
|
|
expect {
|
|
-2000
|
|
}
|
|
|
|
@cross-check-integrity
|
|
test pragma-attached-database-has-its-own-synchronous-mode {
|
|
PRAGMA main.synchronous=OFF;
|
|
ATTACH ':memory:' AS aux;
|
|
PRAGMA main.synchronous;
|
|
PRAGMA aux.synchronous;
|
|
PRAGMA aux.synchronous=NORMAL;
|
|
PRAGMA main.synchronous;
|
|
PRAGMA aux.synchronous;
|
|
}
|
|
expect {
|
|
0
|
|
2
|
|
0
|
|
1
|
|
}
|
|
|
|
@cross-check-integrity
|
|
test pragma-temp-synchronous-stays-off {
|
|
PRAGMA temp.synchronous;
|
|
PRAGMA temp.synchronous=FULL;
|
|
PRAGMA temp.synchronous;
|
|
PRAGMA main.synchronous;
|
|
}
|
|
expect {
|
|
0
|
|
0
|
|
2
|
|
}
|
|
|
|
test pragma-function-cache-size {
|
|
SELECT * FROM pragma_cache_size()
|
|
}
|
|
expect {
|
|
-2000
|
|
}
|
|
|
|
# SQLite has memory mode, but we only report wal or mvcc
|
|
@backend rust
|
|
@skip-if mvcc "should return something different for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-function-update-journal-mode {
|
|
SELECT * FROM pragma_journal_mode()
|
|
}
|
|
expect {
|
|
wal
|
|
}
|
|
|
|
# SQLite only allows memory mode when in memory, but we allow wal or mvcc for in-mem dbs
|
|
@backend rust
|
|
@cross-check-integrity
|
|
test pragma-update-journal-mode-wal {
|
|
PRAGMA journal_mode=WAL
|
|
}
|
|
expect {
|
|
wal
|
|
}
|
|
|
|
test pragma-table-info-vtable {
|
|
SELECT name FROM pragma_table_info('generate_series')
|
|
}
|
|
expect {
|
|
value
|
|
}
|
|
|
|
@skip-if mvcc "page_count not implemented for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-page-count-table {
|
|
CREATE TABLE foo (bar);
|
|
PRAGMA page_count
|
|
}
|
|
expect {
|
|
2
|
|
}
|
|
|
|
@cross-check-integrity
|
|
test pragma-function-argument-with-space {
|
|
CREATE TABLE "foo bar"(c0);
|
|
SELECT * FROM pragma_table_info('foo bar')
|
|
}
|
|
expect {
|
|
0|c0||0||0
|
|
}
|
|
|
|
# If the argument passed to the first function call were simply concatenated with the underlying PRAGMA statement,
|
|
# we would end up with: PRAGMA table_info='sqlite_schema';CREATE TABLE foo (c0);SELECT 'bar'. Depending on how many
|
|
# statements are executed at once, at least one of the following would run:
|
|
# - PRAGMA table_info='sqlite_schema';
|
|
# - CREATE TABLE foo (c0);
|
|
# - SELECT 'bar';
|
|
# No output means that none of them were executed.
|
|
@cross-check-integrity
|
|
test pragma-function-sql-injection {
|
|
SELECT * FROM pragma_table_info('sqlite_schema'';CREATE TABLE foo (c0);SELECT ''bar');
|
|
SELECT * FROM pragma_table_info('foo');
|
|
}
|
|
expect {
|
|
}
|
|
|
|
# pragma page_size=xxx doesn't change the page size of an initialized database.
|
|
@cross-check-integrity
|
|
test pragma-page-size-set-initialized-db {
|
|
CREATE TABLE "foo bar"(c0);
|
|
PRAGMA page_size=1024;
|
|
PRAGMA page_size
|
|
}
|
|
expect {
|
|
4096
|
|
}
|
|
|
|
@skip-if mvcc "max_page_count and page_count not implemented for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-max-page-count-clamping-with-data {
|
|
CREATE TABLE test (id INTEGER);
|
|
PRAGMA page_count;
|
|
PRAGMA max_page_count = 1;
|
|
}
|
|
expect {
|
|
2
|
|
2
|
|
}
|
|
|
|
@skip-if mvcc "max_page_count not implemented for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-max-page-count-enforcement-error {
|
|
PRAGMA max_page_count = 1;
|
|
CREATE TABLE test (id INTEGER)
|
|
}
|
|
expect error {
|
|
}
|
|
|
|
test pragma-page-count-empty {
|
|
PRAGMA page_count
|
|
}
|
|
expect {
|
|
0
|
|
}
|
|
|
|
@skip-if mvcc "page_count not implemented for mvcc"
|
|
test pragma-page-count-empty-2 {
|
|
PRAGMA user_version=1;
|
|
PRAGMA page_count
|
|
}
|
|
expect {
|
|
1
|
|
}
|
|
|
|
test pragma-user-version-default {
|
|
PRAGMA user_version
|
|
}
|
|
expect {
|
|
0
|
|
}
|
|
|
|
@skip-if mvcc "user_version not implemented for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-user-version-update {
|
|
PRAGMA user_version = 42;
|
|
PRAGMA user_version;
|
|
}
|
|
expect {
|
|
42
|
|
}
|
|
|
|
@skip-if mvcc "user_version not implemented for mvcc"
|
|
test pragma-user-version-negative-value {
|
|
PRAGMA user_version = -10;
|
|
PRAGMA user_version;
|
|
}
|
|
expect {
|
|
-10
|
|
}
|
|
|
|
@skip-if mvcc "user_version not implemented for mvcc"
|
|
test pragma-user-version-float-value {
|
|
PRAGMA user_version = 10.9;
|
|
PRAGMA user_version;
|
|
}
|
|
expect {
|
|
10
|
|
}
|
|
|
|
test pragma-application-id-default {
|
|
PRAGMA application_id
|
|
}
|
|
expect {
|
|
0
|
|
}
|
|
|
|
@skip-if mvcc "application_id not implemented for mvcc"
|
|
@cross-check-integrity
|
|
test pragma-application-id-update {
|
|
PRAGMA application_id = 12345;
|
|
PRAGMA application_id;
|
|
}
|
|
expect {
|
|
12345
|
|
}
|
|
|
|
@skip-if mvcc "application_id not implemented for mvcc"
|
|
test pragma-application-id-float-value {
|
|
PRAGMA application_id = 10.9;
|
|
PRAGMA application_id;
|
|
}
|
|
expect {
|
|
10
|
|
}
|
|
|
|
@skip-if mvcc "application_id not implemented for mvcc"
|
|
test pragma-application-id-large-value {
|
|
PRAGMA application_id = 2147483647;
|
|
PRAGMA application_id;
|
|
}
|
|
expect {
|
|
2147483647
|
|
}
|
|
|
|
@skip-if mvcc "application_id not implemented for mvcc"
|
|
test pragma-application-id-negative-value {
|
|
PRAGMA application_id = -23;
|
|
PRAGMA application_id;
|
|
}
|
|
expect {
|
|
-23
|
|
}
|
|
|
|
test pragma-application-id-zero {
|
|
PRAGMA application_id = 0;
|
|
PRAGMA application_id;
|
|
}
|
|
expect {
|
|
0
|
|
}
|
|
|
|
test pragma-page-size-default {
|
|
PRAGMA page_size
|
|
}
|
|
expect {
|
|
4096
|
|
}
|
|
|
|
test pragma-page-size-set {
|
|
PRAGMA page_size=1024;
|
|
PRAGMA page_size
|
|
}
|
|
expect {
|
|
1024
|
|
}
|
|
|
|
test pragma-max-page-count-default {
|
|
PRAGMA max_page_count
|
|
}
|
|
expect {
|
|
4294967294
|
|
}
|
|
|
|
test pragma-max-page-count-set-large {
|
|
PRAGMA max_page_count = 1000;
|
|
PRAGMA max_page_count
|
|
}
|
|
expect {
|
|
1000
|
|
1000
|
|
}
|
|
|
|
test pragma-max-page-count-set-zero-ignored {
|
|
PRAGMA max_page_count = 0;
|
|
PRAGMA max_page_count
|
|
}
|
|
expect {
|
|
4294967294
|
|
4294967294
|
|
}
|
|
|
|
test pragma-integrity-check-empty {
|
|
PRAGMA integrity_check;
|
|
}
|
|
expect {
|
|
ok
|
|
}
|
|
|
|
test pragma-cache-spill-off {
|
|
PRAGMA cache_spill=off;
|
|
PRAGMA cache_spill;
|
|
}
|
|
expect {
|
|
0
|
|
}
|
|
|
|
# pragma page_size=xxx changes the page size of an uninitialized database and persists the change.
|
|
# set user_version to trigger database initialization.
|
|
test pragma-page-size-set-uninitialized-db {
|
|
PRAGMA page_size=1024;
|
|
PRAGMA user_version=1;
|
|
PRAGMA page_size
|
|
}
|
|
expect {
|
|
1024
|
|
}
|
|
|
|
test pragma-wal-autocheckpoint-default {
|
|
PRAGMA wal_autocheckpoint;
|
|
}
|
|
expect {
|
|
1000
|
|
}
|
|
|
|
test pragma-wal-autocheckpoint-update {
|
|
PRAGMA wal_autocheckpoint = 100;
|
|
PRAGMA wal_autocheckpoint;
|
|
}
|
|
expect {
|
|
100
|
|
100
|
|
}
|
|
|
|
test pragma-wal-autocheckpoint-zero {
|
|
PRAGMA wal_autocheckpoint = 0;
|
|
PRAGMA wal_autocheckpoint;
|
|
}
|
|
expect {
|
|
0
|
|
0
|
|
}
|
|
|
|
test pragma-wal-autocheckpoint-negative-value-reads-back-as-zero {
|
|
PRAGMA wal_autocheckpoint = -5;
|
|
PRAGMA wal_autocheckpoint;
|
|
}
|
|
expect {
|
|
0
|
|
0
|
|
}
|
|
|
|
test pragma-wal-autocheckpoint-value-above-int-range-reads-back-as-zero {
|
|
PRAGMA wal_autocheckpoint = 2147483648;
|
|
PRAGMA wal_autocheckpoint;
|
|
}
|
|
expect {
|
|
0
|
|
0
|
|
}
|