Sample Header Ad - 728x90

SQLite Internals - Records

2 votes
1 answer
450 views
Hey I'm trying to wrap my head around SQLite data storage, specifically how it is storing Records. I've found a book [The Definitive guide to SQLlite](https://link.springer.com/book/10.1007/978-1-4302-3226-1) , where the author explains internal record format (Figure 9-5, page 351): Given table:
sqlite> SELECT * FROM episodes ORDER BY id LIMIT 1;
id   season  name
---  ------  --------------------
0    1       Good News Bad News
Its internal record format is:
| 04 | 01 | 01 | 49 |   | 00 | 01 | Good News Bad News |
> "The header is 4 bytes long. The header size reflects this and itself is encoded as a single byte. The first type, corresponding to the id field, is a 1-byte signed integer. The second type, corresponding to the season field, is as well. The name type entry is an odd number, meaning it is a text value. Its size is therefore given by (49-13)/2=18 bytes." Specifically I'm curious about TEXT attribute, in the example above we have a string of length 18 characters. And the rule for TEXT in SQLite is as follows:
Type Value     Meaning   Length of Data
----------     -------   --------------------
N>13 and odd   TEXT      (N-13)/2
What hapenns though when the string is longer ? It'll get out of range of that one byte.
Asked by Matis (121 rep)
Mar 5, 2020, 04:13 PM
Last activity: Jun 6, 2025, 05:08 PM