diff options
author | Mahmoud Mandour <ma.mandourr@gmail.com> | 2021-12-06 15:30:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-05 00:35:03 +0100 |
commit | f6233913ad4deda351530736e659027150a5dd03 (patch) | |
tree | 1d5b72c655378c6c1a10f2d1de41df1ef2029965 /Userland/Libraries/LibSQL/Database.cpp | |
parent | cd4dba87fa52b5a3cad819ccf4161be5a6bd1d8b (diff) | |
download | serenity-f6233913ad4deda351530736e659027150a5dd03.zip |
LibSQL: Implement a DESCRIBE TABLE statement
This statement (for now) outputs the name and types of the different
attributes in a table. It's not standard SQL but all DBMSs that I know
of implement a sort of statement for such functionality.
Since the output of DESCRIBE TABLE is just a relation, an internal
schema, `master` was created and a table definition for DESCRIBE into
it. The table definition and the master schema are not accessible by the
user.
Diffstat (limited to 'Userland/Libraries/LibSQL/Database.cpp')
-rw-r--r-- | Userland/Libraries/LibSQL/Database.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibSQL/Database.cpp b/Userland/Libraries/LibSQL/Database.cpp index e0574f1d59..e4ed4960e6 100644 --- a/Userland/Libraries/LibSQL/Database.cpp +++ b/Userland/Libraries/LibSQL/Database.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jan de Visser <jan@de-visser.net> + * Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,6 +48,21 @@ ErrorOr<void> Database::open() default_schema = SchemaDef::construct("default"); TRY(add_schema(*default_schema)); } + + auto master_schema = TRY(get_schema("master")); + if (!master_schema) { + master_schema = SchemaDef::construct("master"); + TRY(add_schema(*master_schema)); + } + + auto table_def = TRY(get_table("master", "internal_describe_table")); + if (!table_def) { + auto describe_internal_table = TableDef::construct(master_schema, "internal_describe_table"); + describe_internal_table->append_column("Name", SQLType::Text); + describe_internal_table->append_column("Type", SQLType::Text); + TRY(add_table(*describe_internal_table)); + } + return {}; } |