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