SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Reader.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
9 
10 
11 namespace SWC { namespace client { namespace SQL {
12 
13 
14 Reader::Reader(const std::string& a_sql, std::string& a_message)
15  : sql(a_sql), message(a_message),
16  ptr(sql.data()), remain(sql.length()),
17  err(Error::OK) {
18 }
19 
20 bool Reader::is_char(const char* stop) const {
21  if(stop) do {
22  if(*stop++ == *ptr)
23  return true;
24  } while(*stop);
25  return false;
26 }
27 
28 bool Reader::found_char(const char c) {
29  if(*ptr == c) {
30  ++ptr;
31  --remain;
32  return true;
33  }
34  return false;
35 }
36 
38  return found_char(' ') || found_char('\t')
39  || found_char('\n') || found_char('\r');
40 }
41 
42 bool Reader::found_quote_single(bool& quote) {
43  if(found_char('\'')) {
44  quote = !quote;
45  return true;
46  }
47  return false;
48 }
49 
50 bool Reader::found_quote_double(bool& quote) {
51  if(found_char('"')) {
52  quote = !quote;
53  return true;
54  }
55  return false;
56 }
57 
58 bool Reader::found_token(const char* token, uint8_t token_len) {
59  if(remain >= token_len && Condition::str_case_eq(ptr, token, token_len)) {
60  ptr += token_len;
61  remain -= token_len;
62  return true;
63  }
64  return false;
65 }
66 
67 bool Reader::found_comparator(Condition::Comp& comp, uint8_t extended) {
68  while(remain) {
69  if(found_space())
70  continue;
71  if((comp = Condition::from(&ptr, &remain, extended)) != Condition::NONE)
72  return true;
73  break;
74  }
75  return false;
76 }
77 
79  while(remain && !err && found_space());
80 }
81 
83  seek_space();
84  bool eq = false;
85  expect_token("=", 1, eq); // ? (not space is eq)
86 }
87 
88 void Reader::expect_comma(bool& comma) {
89  seek_space();
90  expect_token(",", 1, comma);
91 }
92 
93 void Reader::expect_comparator(Condition::Comp& comp, uint8_t extended) {
94  if(found_comparator(comp, extended) && comp != Condition::NONE)
95  return;
96  error_msg(Error::SQL_PARSE_ERROR, "missing 'comparator'");
97 }
98 
100  if(remain >= 1) {
101  if(std::isdigit(*ptr)) {
102  ++ptr;
103  --remain;
104  return;
105  }
106  }
107  error_msg(Error::SQL_PARSE_ERROR, "missing 'digit'");
108 }
109 
110 void Reader::expected_boolean(bool& value) {
111  if(found_char('1') || found_token(TOKEN_BOOL_TRUE, LEN_BOOL_TRUE))
112  value = true;
113  else if(found_char('0') || found_token(TOKEN_BOOL_FALSE, LEN_BOOL_FALSE))
114  value = false;
115  else {
116  ++ptr;
117  --remain;
118  error_msg(Error::SQL_PARSE_ERROR, "missing 'bool'");
119  }
120 }
121 
122 void Reader::expect_token(const char* token, uint8_t token_len, bool& found) {
123  if(remain >= token_len) {
124  if(found_space())
125  return;
126 
127  if(Condition::str_case_eq(ptr, token, token_len)) {
128  ptr += token_len;
129  remain -= token_len;
130  found = true;
131  return;
132  }
133  }
134  error_msg(Error::SQL_PARSE_ERROR, "missing '"+std::string(token)+"'");
135 }
136 
138  const std::string& col) {
139  DB::Schema::Ptr schema;
140  if(std::find_if(col.cbegin(), col.cend(),
141  [](unsigned char c){ return !std::isdigit(c); } ) != col.cend()){
142  schema = clients->get_schema(err, col);
143  } else {
144  try {
145  schema = clients->get_schema(err, std::stoull(col));
146  } catch(...) {
148  err = e.code();
149  }
150  }
151  if(err)
152  error_msg(err, "problem getting column '"+col+"' schema");
153  return schema;
154 }
155 
158  const DB::Schemas::SelectorPatterns& patterns) {
159  auto schemas = clients->get_schema(err, patterns);
160  if(err) {
161  std::string msg("problem getting columns schema on patterns");
162  if(!patterns.names.empty()) {
163  msg.append(" names=[");
164  for(auto& p : patterns.names) {
165  msg.append(Condition::to_string(p.comp));
166  msg.append("'" + p + "', ");
167  }
168  msg += ']';
169  }
170  if(!patterns.tags.empty() || patterns.tags.comp != Condition::NONE) {
171  msg.append(" tags");
172  msg.append(Condition::to_string(patterns.tags.comp));
173  msg += '[';
174  for(auto& p : patterns.tags) {
175  msg.append(Condition::to_string(p.comp));
176  msg.append("'" + p + "', ");
177  }
178  msg += ']';
179  }
180  error_msg(err, msg);
181  }
182  return schemas;
183 }
184 
185 void Reader::read(std::string& buf, const char* stop, bool keep_escape) {
186  uint32_t escape = 0;
187  bool quote_1 = false;
188  bool quote_2 = false;
189  bool is_quoted = false;
190  bool was_quoted = false;
191 
192  while(remain && !err) {
193  if(!escape && *ptr == '\\') {
194  escape = remain-1;
195  if(!keep_escape) {
196  ++ptr;
197  --remain;
198  continue;
199  }
200  } else if(escape && escape != remain)
201  escape = 0;
202 
203  if(!escape) {
204  if(!is_quoted && buf.empty() && found_space())
205  continue;
206  if(((!is_quoted || quote_1) && found_quote_single(quote_1)) ||
207  ((!is_quoted || quote_2) && found_quote_double(quote_2))) {
208  is_quoted = quote_1 || quote_2;
209  was_quoted = true;
210  continue;
211  }
212  if((was_quoted && !is_quoted) ||
213  (!was_quoted && (found_space() || is_char(stop))))
214  break;
215  }
216  buf += *ptr;
217  ++ptr;
218  --remain;
219  }
220 }
221 
222 
223 void Reader::read_uint8_t(uint8_t& value, bool& was_set) {
224  int64_t v;
225  read_int64_t(v, was_set);
226  if (!was_set || v > UINT8_MAX || v < INT8_MIN)
227  error_msg(Error::SQL_PARSE_ERROR, " unsigned 8-bit integer out of range");
228  else
229  value = v;
230 }
231 
232 void Reader::read_uint16_t(uint16_t& value, bool& was_set) {
233  int64_t v;
234  read_int64_t(v, was_set);
235  if (!was_set || v > UINT16_MAX || v < INT16_MIN)
236  error_msg(Error::SQL_PARSE_ERROR, " unsigned 16-bit integer out of range");
237  else
238  value = v;
239 }
240 
241 void Reader::read_uint24_t(uint24_t& value, bool& was_set, const char* stop) {
242  int64_t v;
243  read_int64_t(v, was_set, stop);
244  if (!was_set || v > UINT24_MAX || v < INT24_MIN)
245  error_msg(Error::SQL_PARSE_ERROR, " unsigned 24-bit integer out of range");
246  else
247  value = v;
248 }
249 
250 void Reader::read_uint32_t(uint32_t& value, bool& was_set, const char* stop) {
251  int64_t v;
252  read_int64_t(v, was_set, stop);
253  if (!was_set || v > UINT32_MAX || v < INT32_MIN)
254  error_msg(Error::SQL_PARSE_ERROR, " unsigned 32-bit integer out of range");
255  else
256  value = v;
257 }
258 
259 void Reader::read_int64_t(int64_t& value, bool& was_set, const char* stop) {
260  std::string buf;
261  read(buf, stop ? stop : "),]");
262  if(!err) {
263  try {
264  value = std::stoll(buf);
265  was_set = true;
266  return;
267  } catch(...) {
268  error_msg(Error::SQL_PARSE_ERROR, " signed 64-bit integer out of range");
269  }
270  }
271  was_set = false;
272 }
273 
274 void Reader::read_uint64_t(uint64_t& value, bool& was_set, const char* stop) {
275  std::string buf;
276  read(buf, stop ? stop : "),]");
277  if(err)
278  return;
279  try {
280  value = std::stoull(buf);
281  was_set = true;
282  } catch(...) {
283  error_msg(
284  Error::SQL_PARSE_ERROR, " unsigned 64-bit integer out of range");
285  was_set = false;
286  }
287 }
288 
289 void Reader::read_double_t(long double& value, bool& was_set,
290  const char* stop) {
291  std::string buf;
292  read(buf, stop ? stop : "),]");
293  if(err)
294  return;
295  try {
296  value = std::stold(buf);
297  was_set = true;
298  } catch(...) {
299  error_msg(Error::SQL_PARSE_ERROR, "double out of range");
300  was_set = false;
301  }
302 }
303 
304 void Reader::read_duration_secs(uint64_t& value, bool& was_set, const char* stop) {
305  std::string buf;
306  read(buf, stop ? stop : "),]");
307  try {
308  size_t pos = 0;
309  value = std::stoull(buf.c_str(), &pos);
310  was_set = true;
311  if(pos == buf.size())
312  return;
313  const char* p = buf.c_str() + pos;
314  if( *p == 'w' || Condition::str_case_eq(p, "week", 4))
315  value *= 60 * 60 * 24 * 7;
316  else if (*p == 'd' || Condition::str_case_eq(p, "day", 3))
317  value *= 60 * 60 * 24;
318  else if (*p == 'h' || Condition::str_case_eq(p, "hour", 4))
319  value *= 60 * 60;
320  else if (*p == 'm' ||Condition::str_case_eq(p, "minute", 6))
321  value *= 60;
322  else
323  error_msg(Error::SQL_PARSE_ERROR, " unknown duration: "+std::string(p));
324  } catch(...) {
325  error_msg(Error::SQL_PARSE_ERROR, " signed 64-bit integer out of range");
326  was_set = false;
327  }
328 }
329 
331  std::string encoder;
332  read(encoder, ")");
334  if(err || enc == DB::Types::Encoder::UNKNOWN)
335  error_msg(Error::SQL_PARSE_ERROR, "bad encoder");
336  return enc;
337 }
338 
341  if(found_token("INT64", 5) || found_token("I", 1)) {
343  } else if (found_token("DOUBLE", 6) || found_token("D", 1)) {
345  } else if (found_token("BYTES", 5) || found_token("B", 1)) {
347  } else if (found_token("KEY", 3) || found_token("K", 1)) {
349  } else if (found_token("LIST_INT64", 10) || found_token("LI", 2)) {
351  } else if (found_token("LIST_BYTES", 10) || found_token("LB", 2)) {
353  } else {
354  error_msg(
355  Error::SQL_PARSE_ERROR, "Not Supported Serial Value Type");
357  }
358  seek_space();
359  bool was_set;
360  expect_token(":", 1, was_set);
361  return typ;
362 }
363 
365  bool bracket_square = false;
366  std::string fraction;
367 
368  seek_space();
369  expect_token("[", 1, bracket_square);
370 
371  while(remain && !err) {
372  if(found_space())
373  continue;
374 
375  read(fraction, ",]");
376  key.add(fraction);
377  fraction.clear();
378 
379  seek_space();
380  if(found_char(','))
381  continue;
382  break;
383  }
384 
385  expect_token("]", 1, bracket_square);
386 }
387 
389  switch(comp) {
390  case Condition::NONE: {
391  comp = Condition::EQ;
392  return true;
393  }
394  case Condition::RE:
395  case Condition::PF:
396  case Condition::POSBS:
397  case Condition::POSPS: {
399  "unsupported numeric 'comparator' PF,RE,POSBS,POSPS");
400  return false;
401  }
402  case Condition::FOSBS:
403  case Condition::FOSPS: {
404  if(_double) {
406  "unsupported double numeric 'comparator' FOSPS,FOSBS");
407  return false;
408  }
409  return true;
410  }
411  default:
412  return true;
413  }
414 }
415 
418  seek_space();
419  found_comparator(comp);
420  if(comp != Condition::NONE &&
421  comp != Condition::NE &&
422  comp != Condition::GT &&
423  comp != Condition::LT &&
424  comp != Condition::GE &&
425  comp != Condition::LE &&
426  comp != Condition::EQ &&
427  comp != Condition::SBS &&
428  comp != Condition::SPS &&
429  comp != Condition::POSBS &&
430  comp != Condition::FOSBS &&
431  comp != Condition::POSPS &&
432  comp != Condition::FOSPS ) {
434  std::string("unsupported 'comparator' ") +
436  );
437  return;
438  }
439  tags.comp = comp;
440  seek_space();
441  bool chk;
442  expect_token("[", 1, chk);
443 
444  std::string buff;
445  while(remain && !err) {
446  if(found_char(',') || found_space())
447  continue;
448  if(found_char(']')) {
449  if(tags.comp == Condition::NONE && !tags.empty()) {
450  tags.comp = Condition::EQ;
451  }
452  return;
453  }
455  seek_space();
456  read(buff, ",]", comp == Condition::RE);
457  if(!buff.empty() || comp != Condition::NONE) {
458  tags.emplace_back(
459  comp == Condition::NONE ? Condition::EQ : comp,
460  std::move(buff)
461  );
462  }
463  }
464  expect_token("]", 1, chk);
465 }
466 
467 void Reader::read_column(const char* stop,
468  std::string& col_name,
469  DB::Schemas::NamePatterns& names) {
472  read(col_name, stop, comp == Condition::RE);
473  if(comp != Condition::NONE && comp != Condition::EQ) {
474  if(col_name.empty()) {
475  error_msg(
477  "expected column name(expression) after comparator"
478  );
479  } else {
480  names.emplace_back(comp, std::move(col_name));
481  }
482  }
483 }
484 
486  DB::Specs::UpdateOP& operation) {
487  if(DB::Types::is_counter(col_type))
488  return operation.set_op(DB::Specs::UpdateOP::REPLACE);
489 
490  if(found_token("+=", 2))
491  return operation.set_op(DB::Specs::UpdateOP::APPEND);
492 
493  if(found_token("=+", 2))
494  return operation.set_op(DB::Specs::UpdateOP::PREPEND);
495 
496  if(col_type == DB::Types::Column::SERIAL)
497  return operation.set_op(
498  found_token("~=", 2)
501  );
502 
503  if(found_token("+:", 2))
505  else if(found_token("=:", 2))
507  else
508  return operation.set_op(DB::Specs::UpdateOP::REPLACE);
509 
510  uint32_t pos = 0;
511  bool was_set;
512  read_uint32_t(pos, was_set, " (");
513  if(!err)
514  operation.set_pos(pos);
515 }
516 
517 void Reader::read_ts_and_value(DB::Types::Column col_type, bool require_ts,
519  bool w_serial) {
520  std::string buf;
521  read(buf, ",)");
522  if(err)
523  return;
524  if(!buf.empty()) {
525  if(Condition::str_case_eq(buf.c_str(), "auto", 4)) {
526  cell.set_timestamp_auto();
527  } else {
528  cell.set_timestamp(Time::parse_ns(err, buf));
529  }
530  }
531  if(err || (require_ts && buf.empty())) {
532  error_msg(Error::SQL_PARSE_ERROR, "bad datetime format");
533  return;
534  }
535  buf.clear();
536 
537  seek_space();
538  if(err)
539  return;
540 
541  switch(col_type) {
542  case DB::Types::Column::PLAIN: {
543  if(!found_char(','))
544  break;
545  std::string value;
546  read(value, ",)");
547  if(err)
548  return;
549  seek_space();
550  if(err)
551  return;
552  if(found_char(',')) {
554  if(err)
555  return;
556  if(encoder == nullptr) {
557  cell.set_value(enc, value);
558  } else {
559  cell.set_value(value, true);
560  *encoder = enc;
561  }
562  } else {
563  cell.set_value(value, true);
564  }
565  break;
566  }
567 
569  if(!found_char(','))
570  break;
571  bool bracket_square = false;
572  bool was_set;
573  seek_space();
574  expect_token("[", 1, bracket_square);
575  if(err)
576  return;
577  seek_space();
578 
580  if(!is_char("]")) do {
581  uint32_t fid;
582  read_uint32_t(fid, was_set, ":");
583  if(err)
584  return;
585  seek_space();
586  expect_token(":", 1, was_set);
587  if(err)
588  return;
589 
591  if(err)
592  return;
593  switch(typ) {
594 
597  if(w_serial)
598  ufield.set_op(&ptr, &remain);
599  int64_t v;
600  if(w_serial && ufield.is_delete_field()) {
601  v = 0;
602  } else {
603  read_int64_t(v, was_set, ",]");
604  if(err)
605  return;
606  }
607  wfields.add(fid, v);
608  if(w_serial)
609  wfields.add(&ufield);
610  break;
611  }
612 
615  if(w_serial)
616  ufield.set_op(&ptr, &remain);
617  long double v;
618  if(w_serial && ufield.is_delete_field()) {
619  v = 0;
620  } else {
621  read_double_t(v, was_set, ",]");
622  if(err)
623  return;
624  }
625  wfields.add(fid, v);
626  if(w_serial)
627  wfields.add(&ufield);
628  break;
629  }
630 
633  if(w_serial) {
634  ufield.set_op(&ptr, &remain, err);
635  if(err)
636  return error_msg(err, "Bad OP syntax");
637  }
638  if(w_serial && ufield.is_delete_field()) {
639  buf.clear();
640  } else {
641  read(buf, ",]");
642  if(err)
643  return;
644  }
645  wfields.add(fid, buf);
646  if(w_serial)
647  wfields.add(&ufield);
648  buf.clear();
649  break;
650  }
651 
653  DB::Cell::Key fkey;
654  read_key(fkey);
655  if(err)
656  return;
657  wfields.add(fid, fkey);
658  break;
659  }
660 
663  if(w_serial) {
664  seek_space();
665  ufield.set_op<true>(&ptr, &remain, err);
666  if(err)
667  return error_msg(err, "Bad OP syntax");
668  }
669  Core::Vector<int64_t> items;
670  if(!w_serial || !ufield.is_delete_field()) {
671  seek_space();
672  expect_token("[", 1, bracket_square);
673  if(err)
674  return;
675  do {
676  seek_space();
677  if(!is_char(",]")) {
678  if(w_serial) {
679  seek_space();
680  if(ufield.is_op_by_idx()) {
681  uint24_t idx=0;
682  read_uint24_t(idx, was_set, "!*/+=");
683  if(err)
684  return;
685  seek_space();
686  ufield.add_item(idx).set_op(&ptr, &remain);
687  } else if(ufield.is_op_by_unique()) {
688  ufield.add_item(0).set_op(&ptr, &remain, true);
689  } else if(ufield.is_op_by_cond()) {
690  Condition::Comp comp;
691  expect_comparator(comp);
692  if(comp == Condition::RE || comp == Condition::PF)
693  return error_msg(
695  "unsupported 'comparator' RE|PF"
696  );
697  seek_space();
698  ufield.add_item(comp).set_op(&ptr, &remain, true);
699  }
700  //if(err)
701  // return error_msg(err, "Bad OP syntax");
702  }
703  read_int64_t(items.emplace_back(), was_set, ",]");
704  if(err)
705  return;
706  seek_space();
707  }
708  } while(found_char(','));
709  expect_token("]", 1, bracket_square);
710  if(err)
711  return;
712  }
713  wfields.add(fid, items);
714  if(w_serial)
715  wfields.add(&ufield);
716  break;
717  }
718 
721  if(w_serial) {
722  seek_space();
723  ufield.set_op<true>(&ptr, &remain, err);
724  if(err)
725  return error_msg(err, "Bad OP syntax");
726  }
728  if(!w_serial || !ufield.is_delete_field()) {
729  seek_space();
730  expect_token("[", 1, bracket_square);
731  if(err)
732  return;
733  do {
734  seek_space();
735  if(!is_char(",]")) {
736  if(w_serial) {
737  seek_space();
738  if(ufield.is_op_by_idx()) {
739  uint24_t idx=0;
740  read_uint24_t(idx, was_set, "!+=-");
741  if(err)
742  return;
743  seek_space();
744  ufield.add_item(idx).set_op(&ptr, &remain, err);
745  } else if(ufield.is_op_by_unique()) {
746  ufield.add_item(0).set_op(&ptr, &remain, err, true);
747  } else if(ufield.is_op_by_cond()) {
748  Condition::Comp comp;
750  auto& uitem = ufield.add_item(comp);
751  seek_space();
752  uitem.set_op(&ptr, &remain, err, true);
753  if(uitem.is_value_set() &&
754  (comp == Condition::RE || comp == Condition::PF))
755  return error_msg(
757  "unsupported 'comparator' RE|PF for set-value"
758  );
759  }
760  if(err)
761  return error_msg(err, "Bad OP syntax");
762  }
763  read(items.emplace_back(), ",]");
764  if(err)
765  return;
766  seek_space();
767  }
768  } while(found_char(','));
769  expect_token("]", 1, bracket_square);
770  if(err)
771  return;
772  }
773  wfields.add(fid, items);
774  if(w_serial)
775  wfields.add(&ufield);
776  break;
777  }
778 
779  default: {
780  return error_msg(
781  Error::SQL_PARSE_ERROR, "Not Supported Serial Value Type");
782  }
783  }
784  seek_space();
785  } while(found_char(','));
786 
787  expect_token("]", 1, bracket_square);
788 
789  while(remain && !err && (found_char(' ') || found_char('\t')));
790  if(err)
791  return;
792 
793  if(found_char(',')) {
795  if(err)
796  return;
797  if(encoder == nullptr) {
798  cell.set_value(enc, wfields.base, wfields.fill());
799  } else {
800  cell.set_value(wfields.base, wfields.fill(), true);
801  *encoder = enc;
802  }
803  } else {
804  cell.set_value(wfields.base, wfields.fill(), true);
805  }
806  break;
807  }
808 
809  case DB::Types::Column::COUNTER_I64:
810  case DB::Types::Column::COUNTER_I32:
811  case DB::Types::Column::COUNTER_I16:
812  case DB::Types::Column::COUNTER_I8: {
813  found_char(',');
814  std::string value;
815  read(value, ",)");
816  if(err)
817  return;
818  const uint8_t* valp = reinterpret_cast<const uint8_t*>(value.c_str());
819  size_t _remain = value.length();
820  uint8_t op;
821  int64_t v;
822  err = DB::Cells::Cell::counter_from_str(&valp, &_remain, op, v);
823  if(err) {
825  return;
826  }
827  cell.set_counter(
828  op,
829  v,
831  ? col_type
832  : DB::Types::Column::COUNTER_I64
833  );
834  break;
835  }
836  default:
837  break;
838  }
839 }
840 
841 void Reader::error_msg(int error, const std::string& msg) {
842  err = error;
843  auto at = sql.length() - remain + 1;
844  message.append("error=");
845  message.append(std::to_string(err));
846  message.append("(");
847  message.append(Error::get_text(err));
848  message.append(")\n");
849 
850  message.append(" SQL='");
851  message.append(sql);
852  message.append("'\n");
853  message.insert(message.length(), at + 5, ' ');
854  message.append("^ at=");
855  message.append(std::to_string(at));
856  message.append("\n");
857  message.insert(message.cend(), at + 5, ' ');
858  message.append(msg);
859  message.append("\n");
860 }
861 
862 
863 
864 
865 }}} // SWC::client:SQL namespace
SWC::Condition::LE
@ LE
Definition: Comparators.h:33
SWC::DB::Cells::Cell::set_counter
void set_counter(uint8_t op, int64_t v, Types::Column typ=Types::Column::COUNTER_I64, int64_t rev=TIMESTAMP_NULL)
Definition: Cell.h:450
SWC::Error::SQL_PARSE_ERROR
@ SQL_PARSE_ERROR
Definition: Error.h:122
SWC::DB::Schemas::TagsPattern::comp
Condition::Comp comp
Definition: Schemas.h:87
SWC::DB::Cells::Cell::set_value
SWC_CAN_INLINE void set_value(uint8_t *v, uint32_t len, bool owner)
Definition: Cell.h:223
SWC::Condition::POSPS
@ POSPS
Definition: Comparators.h:48
SWC::Error::Exception::code
constexpr SWC_CAN_INLINE int code() const noexcept
Definition: Exception.h:51
SWC::Condition::FOSPS
@ FOSPS
Definition: Comparators.h:50
SWC::DB::Specs::UpdateOP::set_pos
SWC_CAN_INLINE void set_pos(uint32_t a_pos) noexcept
Definition: SpecsUpdateOp.h:105
SWC::client::SQL::Reader::expect_eq
void expect_eq()
Definition: Reader.cc:82
SWC::client::SQL::Reader::expect_token
void expect_token(const char *token, uint8_t token_len, bool &found)
Definition: Reader.cc:122
SWC::client::SQL::Reader::expect_comma
void expect_comma(bool &comma)
Definition: Reader.cc:88
SWC::DB::Schema::Ptr
std::shared_ptr< Schema > Ptr
Definition: Schema.h:185
SWC::Condition::GE
@ GE
Definition: Comparators.h:31
SWC::client::SQL::Reader::message
std::string & message
Definition: Reader.h:122
SWC::client::SQL::Reader::read_ts_and_value
void read_ts_and_value(DB::Types::Column col_type, bool require_ts, DB::Cells::Cell &cell, DB::Types::Encoder *encoder, bool w_serial=false)
Definition: Reader.cc:517
data
T data
Definition: BitFieldInt.h:1
SWC::client::SQL::Reader::read_uint16_t
void read_uint16_t(uint16_t &value, bool &was_set)
Definition: Reader.cc:232
SWC::DB::Specs::UpdateOP::REPLACE
static constexpr const uint8_t REPLACE
Definition: SpecsUpdateOp.h:20
SWC::Error::get_text
const char * get_text(const int err) noexcept
Definition: Error.cc:173
SWC::Core::Encoder::Type
Type
Definition: Encoder.h:28
SWC::Condition::GT
@ GT
Definition: Comparators.h:30
SWC::DB::Cell::Serial::Value::Type
Type
Definition: CellValueSerialField.h:33
SWC::UINT24_MAX
constexpr const uint24_t UINT24_MAX
Definition: BitFieldInt.h:403
SWC::DB::Specs::UpdateOP::INSERT
static constexpr const uint8_t INSERT
Definition: SpecsUpdateOp.h:23
SWC::client::Clients::Ptr
ClientsPtr Ptr
Definition: Clients.h:58
SWC::DB::Specs::UpdateOP::SERIAL
static constexpr const uint8_t SERIAL
Definition: SpecsUpdateOp.h:26
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::client::SQL::Reader::seek_space
void seek_space()
Definition: Reader.cc:78
SWC::Condition::COMP_EXTENDED_VALUE
const uint COMP_EXTENDED_VALUE
Definition: Comparators.h:24
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST_ITEMS::add_item
SWC_CAN_INLINE UpdateField_T & add_item(uint32_t i, ArgsT &&... args)
Definition: CellValueSerialFieldUpdate.h:582
SWC::client::SQL::Reader::read_uint64_t
void read_uint64_t(uint64_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:274
SWC::client::SQL::Reader::remain
uint32_t remain
Definition: Reader.h:124
SWC::DB::Cell::Serial::Value::FieldUpdate_MATH
Definition: CellValueSerialFieldUpdate.h:131
SWC::Condition::LT
@ LT
Definition: Comparators.h:34
SWC::client::SQL::Reader::read_duration_secs
void read_duration_secs(uint64_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:304
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::Core::Encoder::encoding_from
Type SWC_PURE_FUNC encoding_from(const std::string &typ) noexcept
Definition: Encoder.cc:50
SWC::client::SQL::Reader::read_column_tags
void read_column_tags(DB::Schemas::TagsPattern &tags)
Definition: Reader.cc:416
SWC::DB::Schemas::SelectorPatterns
Definition: Schemas.h:100
SWC::DB::Cell::Key
Definition: CellKey.h:24
SWC::DB::Schemas::SelectorPatterns::names
NamePatterns names
Definition: Schemas.h:101
SWC::Condition::RE
@ RE
Definition: Comparators.h:36
SWC::DB::Cells::Cell::counter_from_str
static int counter_from_str(const uint8_t **ptrp, size_t *remainp, uint8_t &op, int64_t &value) noexcept
Definition: Cell.h:540
SWC::Condition::eq
SWC_CAN_INLINE bool eq(const uint8_t *p1, uint32_t p1_len, const uint8_t *p2, uint32_t p2_len) noexcept
Definition: Comparators.h:195
SWC::DB::Cell::Serial::Value::FieldsWriter::add
SWC_CAN_INLINE void add(Field *field)
Definition: CellValueSerialFields.h:42
SWC::client::SQL::Reader::found_comparator
bool found_comparator(Condition::Comp &comp, uint8_t extended=0x00)
Definition: Reader.cc:67
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST::is_op_by_idx
SWC_CAN_INLINE bool is_op_by_idx() const noexcept
Definition: CellValueSerialFieldUpdate.h:287
SWC::DB::Cell::Key::add
SWC_CAN_INLINE void add(const std::string_view &fraction)
Definition: CellKey.h:86
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST
Definition: CellValueSerialFieldUpdate.h:243
SWC::client::SQL::Reader::read_int64_t
void read_int64_t(int64_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:259
SWC::DB::Cell::Serial::Value::DOUBLE
@ DOUBLE
Definition: CellValueSerialField.h:36
SWC::client::SQL::Reader::found_char
bool found_char(const char c)
Definition: Reader.cc:28
encoder
Core::Encoder::Type encoder
Buffer Encoder.
Definition: HeaderBufferInfo.h:50
SWC::DB::Cell::Serial::Value::BYTES
@ BYTES
Definition: CellValueSerialField.h:37
SWC::DB::Cell::Serial::Value::FieldUpdate::is_delete_field
SWC_CAN_INLINE bool is_delete_field() const noexcept
Definition: CellValueSerialFieldUpdate.h:89
SWC::client::SQL::Reader::is_numeric_comparator
bool is_numeric_comparator(Condition::Comp &comp, bool _double=false)
Definition: Reader.cc:388
SWC::client::SQL::Reader::found_space
bool found_space()
Definition: Reader.cc:37
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::Condition::Comp
Comp
Definition: Comparators.h:27
SWC::Core::Vector::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC::client::SQL::Reader::get_schema
DB::Schema::Ptr get_schema(const Clients::Ptr &clients, const std::string &col)
Definition: Reader.cc:137
SWC::client::SQL::Reader::read_double_t
void read_double_t(long double &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:289
SWC::DB::Cell::Serial::Value::UNKNOWN
@ UNKNOWN
Definition: CellValueSerialField.h:34
SWC::client::SQL::Reader::read
void read(std::string &buf, const char *stop=nullptr, bool keep_escape=false)
Definition: Reader.cc:185
SWC::client::SQL::Reader::expect_comparator
void expect_comparator(Condition::Comp &comp, uint8_t extended=0x00)
Definition: Reader.cc:93
SWC::client::SQL::Reader::read_key
void read_key(DB::Cell::Key &key)
Definition: Reader.cc:364
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC::client::SQL::Reader::read_uint8_t
void read_uint8_t(uint8_t &value, bool &was_set)
Definition: Reader.cc:223
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Time::parse_ns
int64_t parse_ns(int &err, const std::string &buf)
Definition: Time.cc:37
SWC::DB::Cell::Serial::Value::INT64
@ INT64
Definition: CellValueSerialField.h:35
SWC::DB::Schemas::TagsPattern
Definition: Schemas.h:86
SWC::DB::Types::is_counter
bool SWC_CONST_FUNC is_counter(const Column typ) noexcept
Definition: Column.cc:26
SWC::Condition::EQ
@ EQ
Definition: Comparators.h:32
SWC::Condition::NE
@ NE
Definition: Comparators.h:35
SWC::Condition::PF
@ PF
Definition: Comparators.h:29
SWC::DB::Specs::UpdateOP::OVERWRITE
static constexpr const uint8_t OVERWRITE
Definition: SpecsUpdateOp.h:24
SWC::Comm::Protocol::FsBroker::Handler::length
void length(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Length.h:17
SWC::client::SQL::Reader::found_quote_double
bool found_quote_double(bool &quote)
Definition: Reader.cc:50
SWC::client::SQL::Reader::found_token
bool found_token(const char *token, uint8_t token_len)
Definition: Reader.cc:58
SWC::DB::Cell::Serial::Value::LIST_INT64
@ LIST_INT64
Definition: CellValueSerialField.h:39
SWC::Condition::NONE
@ NONE
Definition: Comparators.h:28
SWC::client::SQL::Reader::Reader
Reader(const std::string &sql, std::string &message)
Definition: Reader.cc:14
SWC::DB::Cell::Serial::Value::FieldsWriter
Definition: CellValueSerialFields.h:34
SWC::DB::Cells::Cell::set_timestamp_auto
constexpr SWC_CAN_INLINE void set_timestamp_auto() noexcept
Definition: Cell.h:198
SWC::Condition::SPS
@ SPS
Definition: Comparators.h:46
SWC::Condition::POSBS
@ POSBS
Definition: Comparators.h:47
SWC::client::SQL::Reader::found_quote_single
bool found_quote_single(bool &quote)
Definition: Reader.cc:42
SWC::Core::Vector
Definition: Vector.h:14
SWC::client::SQL::Reader::read_serial_value_type
DB::Cell::Serial::Value::Type read_serial_value_type()
Definition: Reader.cc:339
SWC::DB::Specs::UpdateOP::APPEND
static constexpr const uint8_t APPEND
Definition: SpecsUpdateOp.h:21
SWC::DB::Schemas::SelectorPatterns::tags
TagsPattern tags
Definition: Schemas.h:102
SWC::Core::BufferDyn::fill
constexpr SWC_CAN_INLINE size_t fill() const noexcept
Definition: Buffer.h:192
SWC::Condition::from
Comp from(const char **buf, uint32_t *remainp, uint8_t extended=0x00) noexcept
Definition: Comparators.cc:15
SWC::client::SQL::Reader::read_uint24_t
void read_uint24_t(uint24_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:241
SWC::client::SQL::Reader::read_operation
void read_operation(const DB::Types::Column col_type, DB::Specs::UpdateOP &operation)
Definition: Reader.cc:485
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST::is_op_by_unique
SWC_CAN_INLINE bool is_op_by_unique() const noexcept
Definition: CellValueSerialFieldUpdate.h:279
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST::is_op_by_cond
SWC_CAN_INLINE bool is_op_by_cond() const noexcept
Definition: CellValueSerialFieldUpdate.h:283
SWC::uint24_t
Core::uint24_t uint24_t
Definition: BitFieldInt.h:401
SWC::DB::Cells::OP_EQUAL
constexpr const uint8_t OP_EQUAL
Definition: Cell.h:83
SWC::client::SQL::Reader::is_char
bool SWC_PURE_FUNC is_char(const char *stop) const
Definition: Reader.cc:20
SWC::client::SQL::Reader::err
int err
Definition: Reader.h:125
SWC::client::SQL::Reader::read_column
void read_column(const char *stop, std::string &col_name, DB::Schemas::NamePatterns &names)
Definition: Reader.cc:467
SWC::client::SQL::Reader::ptr
const char * ptr
Definition: Reader.h:123
SWC::DB::Cell::Serial::Value::FieldUpdate_MATH::set_op
SWC_CAN_INLINE void set_op(const char **ptr, uint32_t *remainp, bool w_value_ctrl=false) noexcept
Definition: CellValueSerialFieldUpdate.h:156
SWC::Condition::to_string
const char *SWC_CONST_FUNC to_string(Comp comp) noexcept
Definition: Comparators.cc:174
SWC::DB::Specs::UpdateOP::PREPEND
static constexpr const uint8_t PREPEND
Definition: SpecsUpdateOp.h:22
SWC::INT24_MIN
constexpr const int24_t INT24_MIN
Definition: BitFieldInt.h:406
SWC::client::SQL::Reader::expected_boolean
void expected_boolean(bool &value)
Definition: Reader.cc:110
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST_ITEMS
Definition: CellValueSerialFieldUpdate.h:551
SWC::DB::Cell::Serial::Value::LIST_BYTES
@ LIST_BYTES
Definition: CellValueSerialField.h:40
SQL.h
SWC::Condition::SBS
@ SBS
Definition: Comparators.h:45
SWC::DB::Cell::Serial::Value::FieldUpdate_LIST::set_op
SWC_CAN_INLINE void set_op(const char **ptr, uint32_t *remainp, int &err, bool w_value_ctrl=false) noexcept
Definition: CellValueSerialFieldUpdate.h:300
SWC::DB::Types::Column::SERIAL
@ SERIAL
SWC::Condition::FOSBS
@ FOSBS
Definition: Comparators.h:49
SWC::client::SQL::Reader::error_msg
void error_msg(int error, const std::string &msg)
Definition: Reader.cc:841
Reader.h
SWC::DB::Specs::UpdateOP::set_op
SWC_CAN_INLINE void set_op(uint8_t a_op) noexcept
Definition: SpecsUpdateOp.h:95
SWC::Core::to_string
SWC_CAN_INLINE std::string to_string(const BitFieldInt< T, SZ > &v)
Definition: BitFieldInt.h:263
SWC::client::SQL::Reader::read_uint32_t
void read_uint32_t(uint32_t &value, bool &was_set, const char *stop=nullptr)
Definition: Reader.cc:250
SWC::Condition::str_case_eq
bool str_case_eq(const char *s1, const char *s2, size_t count) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Comparators_basic.h:257
SWC::DB::Specs::UpdateOP
Definition: SpecsUpdateOp.h:18
SWC::Core::Vector::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::client::SQL::Reader::read_encoder
DB::Types::Encoder read_encoder()
Definition: Reader.cc:330
SWC::Error::Exception
Definition: Exception.h:21
SWC::DB::Cell::Serial::Value::KEY
@ KEY
Definition: CellValueSerialField.h:38
SWC::client::SQL::Reader::sql
const std::string & sql
Definition: Reader.h:121
SWC::DB::Cells::Cell::set_timestamp
constexpr SWC_CAN_INLINE void set_timestamp(int64_t ts) noexcept
Definition: Cell.h:182
SWC::client::SQL::Reader::expect_digit
void expect_digit()
Definition: Reader.cc:99