Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Interpreter_Dump_Writable.cpp
Go to the documentation of this file.
2#include "joedb/ui/type_io.h"
4
5#include <iostream>
6
7namespace joedb
8{
9 ////////////////////////////////////////////////////////////////////////////
10 void Interpreter_Writable::write_type(Type type)
11 ////////////////////////////////////////////////////////////////////////////
12 {
13 switch(type.get_type_id())
14 {
16 out << "null";
17 break;
18
19 #define TYPE_MACRO(type, return_type, type_id, read, write)\
20 case Type::Type_Id::type_id:\
21 out << #type_id;\
22 break;
23 #define TYPE_MACRO_NO_REFERENCE
24 #include "joedb/TYPE_MACRO.h"
25
26 case Type::Type_Id::reference:
27 out << "references " << schema.get_table_name(type.get_table_id());
28 break;
29 }
30 }
31
32 ////////////////////////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////////////////////////
35 {
36 out << std::endl;
37 }
38
39 ////////////////////////////////////////////////////////////////////////////
40 void Interpreter_Writable::create_table(const std::string &name)
41 ////////////////////////////////////////////////////////////////////////////
42 {
43 out << "create_table " << name << '\n';
44 }
45
46 ////////////////////////////////////////////////////////////////////////////
48 ////////////////////////////////////////////////////////////////////////////
49 {
50 out << "drop_table " << schema.get_table_name(table_id) << '\n';
51 }
52
53 ////////////////////////////////////////////////////////////////////////////
55 ////////////////////////////////////////////////////////////////////////////
56 (
57 Table_Id table_id,
58 const std::string &name
59 )
60 {
61 out << "rename_table " << schema.get_table_name(table_id);
62 out << ' ' << name << '\n';
63 }
64
65 ////////////////////////////////////////////////////////////////////////////
67 ////////////////////////////////////////////////////////////////////////////
68 (
69 Table_Id table_id,
70 const std::string &name,
71 Type type
72 )
73 {
74 out << "add_field " << schema.get_table_name(table_id);
75 out << ' ' << name << ' ';
76 write_type(type);
77 out << '\n';
78 }
79
80 ////////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////////
83 (
84 Table_Id table_id,
85 Field_Id field_id
86 )
87 {
88 out << "drop_field " << schema.get_table_name(table_id) << ' ';
89 out << schema.get_field_name(table_id, field_id) << '\n';
90 }
91
92 ////////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////////
95 (
96 Table_Id table_id,
97 Field_Id field_id,
98 const std::string &name
99 )
100 {
101 out << "rename_field " << schema.get_table_name(table_id) << ' ';
102 out << schema.get_field_name(table_id, field_id) << ' ' << name << '\n';
103 }
104
105 ////////////////////////////////////////////////////////////////////////////
106 void Interpreter_Writable::custom(const std::string &name)
107 ////////////////////////////////////////////////////////////////////////////
108 {
109 out << "custom " << name << '\n';
110 }
111
112 ////////////////////////////////////////////////////////////////////////////
113 void Interpreter_Writable::comment(const std::string &comment)
114 ////////////////////////////////////////////////////////////////////////////
115 {
116 out << "comment ";
117 write_string(out, comment);
118 out << '\n';
119 }
120
121 ////////////////////////////////////////////////////////////////////////////
122 void Interpreter_Writable::timestamp(int64_t timestamp)
123 ////////////////////////////////////////////////////////////////////////////
124 {
125 out << "timestamp " << timestamp << ' ';
126 out << get_time_string(timestamp) << '\n';
127 }
128
129 ////////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////////
132 {
133 out << "valid_data\n";
134 }
135
136 ////////////////////////////////////////////////////////////////////////////
138 ////////////////////////////////////////////////////////////////////////////
139 (
140 Table_Id table_id,
141 Record_Id record_id
142 )
143 {
144 out << "insert_into " << schema.get_table_name(table_id) << ' ';
145 out << record_id << '\n';
146 }
147
148 ////////////////////////////////////////////////////////////////////////////
150 ////////////////////////////////////////////////////////////////////////////
151 (
152 Table_Id table_id,
153 Record_Id record_id
154 )
155 {
156 out << "delete_from " << schema.get_table_name(table_id) << ' ';
157 out << record_id << '\n';
158 }
159
160 ////////////////////////////////////////////////////////////////////////////
162 ////////////////////////////////////////////////////////////////////////////
163 (
164 Table_Id table_id,
165 Record_Id record_id,
166 size_t size
167 )
168 {
169 out << "insert_vector " << schema.get_table_name(table_id) << ' ';
170 out << record_id << ' ' << size << '\n';
171 }
172
173 ////////////////////////////////////////////////////////////////////////////
175 ////////////////////////////////////////////////////////////////////////////
176 (
177 Table_Id table_id,
178 Record_Id record_id,
179 size_t size
180 )
181 {
182 out << "delete_vector " << schema.get_table_name(table_id) << ' ';
183 out << record_id << ' ' << size << '\n';
184 }
185
186 ////////////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////////////
189 (
190 const char *command,
191 Table_Id table_id,
192 Record_Id record_id,
193 Field_Id field_id
194 )
195 {
196 out << command << schema.get_table_name(table_id) << ' ';
197 out << record_id << ' ';
198 out << schema.get_field_name(table_id, field_id) << ' ';
199 }
200
201 #define TYPE_MACRO(type, return_type, type_id, R, W)\
202 void Interpreter_Writable::update_##type_id\
203 (\
204 Table_Id table_id,\
205 Record_Id record_id,\
206 Field_Id field_id,\
207 return_type value\
208 )\
209 {\
210 write_update("update ", table_id, record_id, field_id);\
211 joedb::write_##type_id(out, value);\
212 out << '\n';\
213 }\
214 void Interpreter_Writable::update_vector_##type_id\
215 (\
216 Table_Id table_id,\
217 Record_Id record_id,\
218 Field_Id field_id,\
219 size_t size,\
220 const type *value\
221 )\
222 {\
223 write_update("update_vector ", table_id, record_id, field_id);\
224 out << size;\
225 for (size_t i = 0; i < size; i++)\
226 {\
227 out << ' ';\
228 joedb::write_##type_id(out, value[i]);\
229 }\
230 out << '\n';\
231 }
232 #include "joedb/TYPE_MACRO.h"
233
234 ////////////////////////////////////////////////////////////////////////////
236 ////////////////////////////////////////////////////////////////////////////
237 {
238 out << "# Blob: ";
239 joedb::write_blob(out, blob);
240 out << '\n';
241 }
242
243 ////////////////////////////////////////////////////////////////////////////
244 Blob Interpreter_Writable::write_blob(const std::string &data)
245 ////////////////////////////////////////////////////////////////////////////
246 {
247 out << "write_blob ";
248 write_string(out, data);
249 out << '\n';
250
251 return Blob();
252 }
253
254 ////////////////////////////////////////////////////////////////////////////
256 ////////////////////////////////////////////////////////////////////////////
257}
void create_table(const std::string &name) override
void comment(const std::string &comment) override
void insert_into(Table_Id table_id, Record_Id record_id) override
void rename_table(Table_Id table_id, const std::string &name) override
void custom(const std::string &name) override
void drop_field(Table_Id table_id, Field_Id field_id) override
void timestamp(int64_t timestamp) override
void add_field(Table_Id table_id, const std::string &name, Type type) override
Blob write_blob(const std::string &data) override
void delete_from(Table_Id table_id, Record_Id record_id) override
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void drop_table(Table_Id table_id) override
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) override
void write_update(const char *command, Table_Id table_id, Record_Id record_id, Field_Id field_id)
const std::string & get_table_name(Table_Id table_id) const
Definition Readable.cpp:38
std::string get_time_string(int64_t timestamp)
void write_string(std::ostream &out, const std::string &s, bool json)
void write_blob(std::ostream &out, Blob blob)
Definition type_io.cpp:243
Definition Blob.h:7