37 size_t max_column_width,
44 const auto &fields = readable.get_fields(table_id);
45 std::map<Field_Id, size_t> column_width;
47 for (
const auto &[fid, fname]: fields)
48 column_width[fid] = fname.size();
53 std::map<Field_Id, std::vector<std::string>> columns;
54 std::vector<Record_Id> id_column;
57 const Record_Id size = readable.get_size(table_id);
58 for (
Record_Id record_id{0}; record_id < size; ++record_id)
62 readable.is_used(table_id, record_id) &&
63 (length == 0 || (record_id >= start && record_id < start + length))
67 id_column.emplace_back(record_id);
69 for (
const auto &[fid, fname]: fields)
71 std::ostringstream ss;
74 const std::string &s = ss.str();
76 if (column_width[fid] < width)
77 column_width[fid] = width;
78 columns[fid].emplace_back(s);
88 std::ostringstream ss;
91 id_width = ss.str().size();
93 size_t table_width = id_width;
94 for (
const auto &[fid, fname]: fields)
96 if (max_column_width && column_width[fid] > max_column_width)
97 column_width[fid] = max_column_width;
98 table_width += column_width[fid] + 1;
104 out << std::string(table_width,
'-') <<
'\n';
105 out << std::string(id_width,
' ');
106 for (
const auto &[fid, fname]: fields)
119 type_id == Type::Type_Id::string
123 out << std::string(table_width,
'-') <<
'\n';
128 for (
size_t i = 0; i < rows; i++)
130 out << std::setw(
int(id_width)) << id_column[i];
132 for (
const auto &[fid, fname]: fields)
146 type_id == Type::Type_Id::string
158 const std::string &command,
159 std::istream ¶meters,
164 if (command ==
"table")
166 const Table_Id table_id = parse_table(parameters, readable);
168 size_t max_column_width = 25;
172 max_column_width = w;
178 parameters >> start >> length;
180 print_table(out, table_id, max_column_width, start, length);
182 else if (command ==
"record")
184 const Table_Id table_id = parse_table(parameters, readable);
186 if (!(parameters >> record_id))
189 const auto &freedom = readable.get_freedom(table_id);
191 if (!readable.is_used(table_id, record_id))
194 out << record_id <<
" is not used.\n";
195 out <<
"first_used: " << freedom.get_first_used() <<
'\n';
196 out <<
"last_used: " << freedom.get_last_used() <<
'\n';
197 out <<
"used_count: " << freedom.get_used_count() <<
'\n';
198 out <<
"size: " << freedom.get_size() <<
'\n';
199 out <<
"dense: " << freedom.is_dense() <<
'\n';
203 out <<
"id = " << record_id;
204 out <<
"; next = " << freedom.get_next(record_id);
205 out <<
"; previous = " << freedom.get_previous(record_id) <<
'\n';
207 const auto &fields = readable.get_fields(table_id);
208 size_t max_field_size = 0;
209 for (
const auto &[fid, fname]: fields)
210 if (fname.size() > max_field_size)
211 max_field_size = fname.size();
213 for (
const auto &[fid, fname]: fields)
215 out << std::setw(
int(max_field_size)) << fname <<
": ";
221 else if (command ==
"schema")
224 dump(readable, dump_writable,
true);
226 else if (command ==
"dump")
229 dump(readable, dump_writable);
231 else if (command ==
"sql")
234 dump(readable, dump_writable);
236 else if (command ==
"json")
238 bool use_base64 =
false;
239 parameters >> use_base64;
242 else if (command ==
"help")
244 out << R
"RRR(Displaying data
246 table <table_name> [<max_column_width>] [start] [length]
247 record <table_name> [<record_id>]