mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibSQL: Create databases in writable directory
This commit is contained in:
parent
6bc7f2204e
commit
49340f98f7
Notes:
sideshowbarker
2024-07-18 11:39:56 +09:00
Author: https://github.com/Coderdreams Commit: https://github.com/SerenityOS/serenity/commit/49340f98f78 Pull-request: https://github.com/SerenityOS/serenity/pull/7435 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg
3 changed files with 30 additions and 30 deletions
|
@ -143,9 +143,9 @@ NonnullRefPtr<SQL::BTree> setup_btree(SQL::Heap& heap)
|
|||
|
||||
void insert_and_get_to_and_from_btree(int num_keys)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto btree = setup_btree(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -160,7 +160,7 @@ void insert_and_get_to_and_from_btree(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto btree = setup_btree(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -175,9 +175,9 @@ void insert_and_get_to_and_from_btree(int num_keys)
|
|||
|
||||
void insert_into_and_scan_btree(int num_keys)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto btree = setup_btree(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -192,7 +192,7 @@ void insert_into_and_scan_btree(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto btree = setup_btree(heap);
|
||||
|
||||
int count = 0;
|
||||
|
|
|
@ -78,55 +78,55 @@ void verify_table_contents(SQL::Database& db, int expected_count)
|
|||
|
||||
void insert_and_verify(int count)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
setup_table(db);
|
||||
db->commit();
|
||||
}
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
insert_into_table(db, count);
|
||||
db->commit();
|
||||
}
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
verify_table_contents(db, count);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(create_heap)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
EXPECT_EQ(heap->version(), 0x00000001u);
|
||||
}
|
||||
|
||||
TEST_CASE(create_database)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
db->commit();
|
||||
}
|
||||
|
||||
TEST_CASE(add_schema_to_database)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
setup_schema(db);
|
||||
db->commit();
|
||||
}
|
||||
|
||||
TEST_CASE(get_schema_from_database)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
setup_schema(db);
|
||||
db->commit();
|
||||
}
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
auto schema = db->get_schema("TestSchema");
|
||||
EXPECT(schema);
|
||||
}
|
||||
|
@ -134,22 +134,22 @@ TEST_CASE(get_schema_from_database)
|
|||
|
||||
TEST_CASE(add_table_to_database)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
setup_table(db);
|
||||
db->commit();
|
||||
}
|
||||
|
||||
TEST_CASE(get_table_from_database)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
setup_table(db);
|
||||
db->commit();
|
||||
}
|
||||
{
|
||||
auto db = SQL::Database::construct("test.db");
|
||||
auto db = SQL::Database::construct("/tmp/test.db");
|
||||
auto table = db->get_table("TestSchema", "TestTable");
|
||||
EXPECT(table);
|
||||
EXPECT_EQ(table->name(), "TestTable");
|
||||
|
|
|
@ -138,9 +138,9 @@ NonnullRefPtr<SQL::HashIndex> setup_hash_index(SQL::Heap& heap)
|
|||
|
||||
void insert_and_get_to_and_from_hash_index(int num_keys)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto hash_index = setup_hash_index(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -156,7 +156,7 @@ void insert_and_get_to_and_from_hash_index(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto hash_index = setup_hash_index(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -232,9 +232,9 @@ TEST_CASE(hash_index_50_keys)
|
|||
|
||||
void insert_into_and_scan_hash_index(int num_keys)
|
||||
{
|
||||
ScopeGuard guard([]() { unlink("test.db"); });
|
||||
ScopeGuard guard([]() { unlink("/tmp/test.db"); });
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto hash_index = setup_hash_index(heap);
|
||||
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
@ -250,7 +250,7 @@ void insert_into_and_scan_hash_index(int num_keys)
|
|||
}
|
||||
|
||||
{
|
||||
auto heap = SQL::Heap::construct("test.db");
|
||||
auto heap = SQL::Heap::construct("/tmp/test.db");
|
||||
auto hash_index = setup_hash_index(heap);
|
||||
Vector<bool> found;
|
||||
for (auto ix = 0; ix < num_keys; ix++) {
|
||||
|
|
Loading…
Reference in a new issue