mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:58:12 +00:00
LibSQL: Create databases in writable directory
This commit is contained in:
parent
6bc7f2204e
commit
49340f98f7
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)
|
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);
|
auto btree = setup_btree(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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);
|
auto btree = setup_btree(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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)
|
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);
|
auto btree = setup_btree(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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);
|
auto btree = setup_btree(heap);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -78,55 +78,55 @@ void verify_table_contents(SQL::Database& db, int expected_count)
|
||||||
|
|
||||||
void insert_and_verify(int 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);
|
setup_table(db);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto db = SQL::Database::construct("test.db");
|
auto db = SQL::Database::construct("/tmp/test.db");
|
||||||
insert_into_table(db, count);
|
insert_into_table(db, count);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto db = SQL::Database::construct("test.db");
|
auto db = SQL::Database::construct("/tmp/test.db");
|
||||||
verify_table_contents(db, count);
|
verify_table_contents(db, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(create_heap)
|
TEST_CASE(create_heap)
|
||||||
{
|
{
|
||||||
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");
|
||||||
EXPECT_EQ(heap->version(), 0x00000001u);
|
EXPECT_EQ(heap->version(), 0x00000001u);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(create_database)
|
TEST_CASE(create_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");
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(add_schema_to_database)
|
TEST_CASE(add_schema_to_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);
|
setup_schema(db);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(get_schema_from_database)
|
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);
|
setup_schema(db);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto db = SQL::Database::construct("test.db");
|
auto db = SQL::Database::construct("/tmp/test.db");
|
||||||
auto schema = db->get_schema("TestSchema");
|
auto schema = db->get_schema("TestSchema");
|
||||||
EXPECT(schema);
|
EXPECT(schema);
|
||||||
}
|
}
|
||||||
|
@ -134,22 +134,22 @@ TEST_CASE(get_schema_from_database)
|
||||||
|
|
||||||
TEST_CASE(add_table_to_database)
|
TEST_CASE(add_table_to_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);
|
setup_table(db);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(get_table_from_database)
|
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);
|
setup_table(db);
|
||||||
db->commit();
|
db->commit();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto db = SQL::Database::construct("test.db");
|
auto db = SQL::Database::construct("/tmp/test.db");
|
||||||
auto table = db->get_table("TestSchema", "TestTable");
|
auto table = db->get_table("TestSchema", "TestTable");
|
||||||
EXPECT(table);
|
EXPECT(table);
|
||||||
EXPECT_EQ(table->name(), "TestTable");
|
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)
|
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);
|
auto hash_index = setup_hash_index(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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);
|
auto hash_index = setup_hash_index(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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)
|
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);
|
auto hash_index = setup_hash_index(heap);
|
||||||
|
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
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);
|
auto hash_index = setup_hash_index(heap);
|
||||||
Vector<bool> found;
|
Vector<bool> found;
|
||||||
for (auto ix = 0; ix < num_keys; ix++) {
|
for (auto ix = 0; ix < num_keys; ix++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue