Joedb 10.4.3
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Compiler_Options_io.cpp
Go to the documentation of this file.
6#include "joedb/ui/type_io.h"
8
9#include <iostream>
10#include <sstream>
11
12namespace joedb
13{
14 /////////////////////////////////////////////////////////////////////////////
16 /////////////////////////////////////////////////////////////////////////////
17 (
18 std::istream &in,
19 Compiler_Options &compiler_options
20 )
21 {
22 std::string line;
23
24 while(std::getline(in, line))
25 {
26 std::istringstream iss(line);
27 std::string command;
28 iss >> command;
29
30 const Database_Schema &db = compiler_options.get_db();
31
32 if (command.empty() || command[0] == '#')
33 continue;
34
35 if (command == "namespace")
36 {
37 std::string s;
38 iss >> s;
39 compiler_options.set_name_space(split_namespace(s));
40 }
41 else if (
42 command == "create_index" ||
43 command == "create_unique_index" ||
44 command == "create_unordered_index" ||
45 command == "create_unordered_unique_index"
46 )
47 {
49
50 index.unique = (command.find("unique") != std::string::npos);
51 index.ordered = (command.find("unordered") == std::string::npos);
52
53 iss >> index.name;
54
56
57 {
58 std::string s;
59 iss >> s;
60 std::istringstream column_ss(s);
61
62 while (true)
63 {
64 std::string field_name;
65 if (std::getline(column_ss, field_name, ','))
66 {
67 const Field_Id field_id = db.find_field(index.table_id, field_name);
68 if (field_id == Field_Id(0))
69 throw Exception("Field not found: " + field_name);
70 index.field_ids.emplace_back(field_id);
71 }
72 else
73 break;
74 }
75 }
76
77 if (!joedb::is_identifier(index.name))
78 throw Exception("Invalid index identifier: " + index.name);
79
80 compiler_options.add_index(std::move(index));
81 }
82 else if (command == "set_table_storage")
83 {
84 std::cerr << "Warning: set_table_storage is deprecated\n";
85 }
86 else if (command == "set_single_row")
87 {
88 const Table_Id table_id = Readable_Command_Processor::parse_table(iss, db);
89 const bool value = read_boolean(iss);
90 compiler_options.set_single_row(table_id, value);
91 }
92 else
93 throw Exception("unknown command: " + command);
94 }
95 }
96}
static Table_Id parse_table(std::istream &in, const Readable &readable)
Field_Id find_field(Table_Id table_id, const std::string &name) const
Definition Readable.cpp:22
std::vector< std::string > split_namespace(std::string_view s)
void parse_compiler_options(std::istream &in, Compiler_Options &compiler_options)
bool is_identifier(const std::string_view s)
bool read_boolean(std::istream &in)
Definition type_io.cpp:215
std::vector< Field_Id > field_ids