Joedb 9.5.0
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 (command == "create_index" || command == "create_unique_index")
42 {
44
45 index.unique = (command == "create_unique_index");
46
47 std::vector<std::string> index_columns;
48
49 iss >> index.name;
50
52
53 {
54 std::string s;
55 iss >> s;
56 std::istringstream column_ss(s);
57 while (true)
58 {
59 std::string column;
60 if (std::getline(column_ss, column, ','))
61 index_columns.emplace_back(std::move(column));
62 else
63 break;
64 }
65 }
66
67 if (!joedb::is_identifier(index.name))
68 throw Exception("Invalid index identifier: " + index.name);
69
70 for (auto field_name: index_columns)
71 {
72 const Field_Id field_id = db.find_field(index.table_id, field_name);
73 if (field_id == Field_Id(0))
74 throw Exception("Field not found: " + field_name);
75 index.field_ids.emplace_back(field_id);
76 }
77
78 compiler_options.add_index(std::move(index));
79 }
80 else if (command == "set_table_storage")
81 {
82 std::cerr << "Warning: set_table_storage is deprecated\n";
83 }
84 else if (command == "set_single_row")
85 {
86 const Table_Id table_id = Readable_Command_Processor::parse_table(iss, db);
87 const bool value = read_boolean(iss);
88 compiler_options.set_single_row(table_id, value);
89 }
90 else
91 throw Exception("unknown command: " + command);
92 }
93 }
94}
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
void parse_compiler_options(std::istream &in, Compiler_Options &compiler_options)
std::vector< std::string > split_namespace(const std::string &s)
bool is_identifier(const std::string &s)
bool read_boolean(std::istream &in)
Definition type_io.cpp:215
Definition Blob.h:7
std::vector< Field_Id > field_ids