max page count doesn't return sqlite_full error when reaches the limit of page count
(1) By ltts_guest (lttsguest) on 2020-11-30 06:42:13 [link] [source]
I tried implementing it as below :
static const sqlite3_int64 SOFT_HEAP_LIMIT = 5 * 1024; //5kb sqlite3_int64 SQLITE_MAX_PAGE_COUNT = SOFT_HEAP_LIMIT;
rc = sqlite3_exec(db, "PRAGMA count_changes = true", callback, (void*)data, &zErrMsg); rc = sqlite3_exec(db, "PRAGMA max_page_count = 2", callback, (void*)data, &zErrMsg);
I inserted a payload of 63kb. Both the ways, it is not returning SQLITE_FULL error. Can you please let me know how can i set the max_page_count to 2 and trigger the error if it exceeds that limit?
(2.1) By Keith Medcalf (kmedcalf) on 2020-11-30 09:02:52 edited from 2.0 in reply to 1 [source]
Works just fine here.
SQLite version 3.34.0 2020-11-28 21:08:26 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> pragma page_count; ┌────────────┐ │ page_count │ ├────────────┤ │ 0 │ └────────────┘ sqlite> pragma max_page_count=2; ┌────────────────┐ │ max_page_count │ ├────────────────┤ │ 2 │ └────────────────┘ sqlite> create table x(x); sqlite> pragma page_count; ┌────────────┐ │ page_count │ ├────────────┤ │ 2 │ └────────────┘ sqlite> create table y(y); Error: database or disk is full sqlite> pragma page_count; ┌────────────┐ │ page_count │ ├────────────┤ │ 2 │ └────────────┘ sqlite>
You cannot set the max_page_count to a smaller number of pages than exist in the file (returned by
pragma page_count;) at the time you set max_page_count.
The count is in pages, not in bytes.
The count has naught to do with the heap limits nor anything else.
You are not prevented from adding data to the database -- you are merely prohibited from adding more pages to the database. You may add data to existing pages until your boots are quite full.
Setting a max_page_count is a property of the connection setting the limit and not a property of the database. A connection other than the one on which the limit has been set is free to add as many pages as it wants to the database. If you want a page limit you must set one EVERY TIME on EVERY CONNECTION to the database. It is not persistent across database connections.
It would probably be perspicacious to see what the value of page_count and max_page_count are after you have set the latter, and what the value of page_count is after you think it ought have been violated.