Commit graph

10 commits

Author SHA1 Message Date
Shannon Booth
201c9bb154 LibDatabase: Allow String values to contain embedded null bytes
LibDatabase previously truncated String values at the first '\0' when
round-tripping through SQLite due to the use of strlen.

This is something which we should support according to WPT:

https://wpt.live/webstorage/storage_setitem.window.html

The above test works fine when run through our test-web harness
as we have the SQL database disabled, so this instead adds a C++
test.
2026-02-14 10:25:33 -05:00
Shannon Booth
d3624c328f LibDatabase: Allow creating a memory backed database 2026-02-14 10:25:33 -05:00
Timothy Flynn
63eeb4d75f LibDatabase: Add an accessor for a database's file path 2026-02-13 10:20:52 -05:00
Timothy Flynn
5bb084aa3a LibDatabase: Ensure the exact number of placeholder values are provided
By default, sqlite will fill missing placeholder values with NULL. There
isn't a situation where we want this, so let's assert that the correct
number of placeholders were provided by the caller.
2026-02-06 16:24:49 +01:00
Timothy Flynn
71c7ab208e LibDatabase: Enable the WAL and set the synchronous pragma to normal
Let's do this by default. The APIs to override these are provided if
needed.

In a simple localStorage.setItem loop:

    for (let i = 0; i < 100; ++i) {
        localStorage.setItem(`item_${i}`, `value_${i}`);
    }

This reduces the runtime from ~3.5 seconds to ~50 milliseconds on my
machine.

Co-Authored-By: Tim Ledbetter <tim.ledbetter@ladybird.org>
2026-01-28 21:43:09 +01:00
Timothy Flynn
7a2064ec14 LibDatabase: Add APIs to set the journal mode and synchronous pragmas 2026-01-28 21:43:09 +01:00
Timothy Flynn
d5c00a493c LibDatabase+RequestServer: Store ByteString data as a BLOB
We currently store ByteString as TEXT, but that is interpreted by SQLite
as UTF-8. All string-related operations will try to operate on the text
as if it is stored with UTF-8. We should use BLOB instead, which does
not make any encoding assumptions.

The only user of ByteString in the database currently is the HTTP disk
cache. So we bump its version here to remove existing data. Again, we
will want to handle changes like this more gracefully eventually.
2025-11-12 09:06:21 -05:00
Timothy Flynn
d421b95fef LibDatabase: Support storing ByteString values 2025-11-02 13:03:29 -05:00
Timothy Flynn
411aed96ab LibDatabase: Support all C++ integral types in SQL storage 2025-10-14 13:40:33 +02:00
Timothy Flynn
187d02c45d LibDatabase+LibWebView: Extract our SQLite wrapper to its own library
It currently lives in LibWebView as it was only used for cookies and
local storage, both of which are managed in the UI process. Let's move
it to its own library now to allow other processes to use it, without
having to depend on LibWebView (and therefore LibWeb).
2025-10-14 13:40:33 +02:00
Renamed from Libraries/LibWebView/Database.cpp (Browse further)