system catalogue initial version
This commit is contained in:
@@ -15,10 +15,35 @@ std::unique_ptr<Table> USql::execute_create_table(const CreateTableNode &node) {
|
||||
Table table{node.table_name, node.cols_defs};
|
||||
m_tables.push_back(table);
|
||||
|
||||
execute_create_table_sys_catalogue(node);
|
||||
|
||||
return create_stmt_result_table(0, "table created", 0);
|
||||
}
|
||||
|
||||
|
||||
bool USql::execute_create_table_sys_catalogue(const CreateTableNode &node) {
|
||||
// usql_tables
|
||||
auto r = execute("insert into usql_tables(name, modified) values('" + node.table_name + "', false)");
|
||||
|
||||
// usql_columns
|
||||
for(const ColDefNode & col_def : node.cols_defs) {
|
||||
std::string i {"insert into usql_columns(table_name, column_name, column_type, column_length, nullable, column_order) values("};
|
||||
i += "'" + node.table_name + "', ";
|
||||
i += "'" + col_def.name + "', ";
|
||||
i += "'" + column_type_name(col_def.type) + "', ";
|
||||
i += std::to_string(col_def.length) + ", ";
|
||||
i += (col_def.null ? "true, " : "false, ");
|
||||
i += std::to_string(col_def.order);
|
||||
i += ")";
|
||||
|
||||
auto r = execute(i);
|
||||
// r->print();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_index(const CreateIndexNode &node) {
|
||||
Table *table_def = find_table(node.table_name); // throws exception if not found
|
||||
ColDefNode col_def = table_def->get_column_def(node.column_name); // throws exception if not found
|
||||
@@ -57,7 +82,6 @@ std::unique_ptr<Table> USql::execute_create_table_as_table(const CreateTableAsSe
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_drop(const DropTableNode &node) {
|
||||
auto name_cmp = [node](const Table& t) { return t.m_name == node.table_name; };
|
||||
|
||||
@@ -70,11 +94,13 @@ std::unique_ptr<Table> USql::execute_drop(const DropTableNode &node) {
|
||||
throw Exception("table not found (" + node.table_name + ")");
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_set(const SetNode &node) {
|
||||
Settings::set_setting(node.name, node.value);
|
||||
return create_stmt_result_table(0, "set succeeded", 1);
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_show(const ShowNode &node) {
|
||||
std::string value = Settings::get_setting(node.name);
|
||||
return create_stmt_result_table(0, "show succeeded: " + value, 1);
|
||||
|
||||
Reference in New Issue
Block a user