SQLsmith  v1.2.1-5-gfacd7a8
A random SQL query generator
schema.hh
Go to the documentation of this file.
1 
4 #ifndef SCHEMA_HH
5 #define SCHEMA_HH
6 
7 #include <string>
8 #include <iostream>
9 #include <pqxx/pqxx>
10 #include <numeric>
11 #include <memory>
12 
13 #include "relmodel.hh"
14 #include "random.hh"
15 
16 struct schema {
17  sqltype *booltype;
18  sqltype *inttype;
19  sqltype *internaltype;
20  sqltype *arraytype;
21 
22  std::vector<sqltype *> types;
23 
24  std::vector<table> tables;
25  std::vector<op> operators;
26  std::vector<routine> routines;
27  std::vector<routine> aggregates;
28 
29  typedef std::tuple<sqltype *,sqltype *,sqltype *> typekey;
30  std::multimap<typekey, op> index;
31  typedef std::multimap<typekey, op>::iterator op_iterator;
32 
33  std::multimap<sqltype*, routine*> routines_returning_type;
34  std::multimap<sqltype*, routine*> aggregates_returning_type;
35  std::multimap<sqltype*, routine*> parameterless_routines_returning_type;
36  std::multimap<sqltype*, table*> tables_with_columns_of_type;
37  std::multimap<sqltype*, op*> operators_returning_type;
38  std::multimap<sqltype*, sqltype*> concrete_type;
39  std::vector<table*> base_tables;
40 
41  string version;
42  int version_num; // comparable version number
43 
44  const char *true_literal = "true";
45  const char *false_literal = "false";
46 
47  virtual std::string quote_name(const std::string &id) = 0;
48 
49  void summary() {
50  std::cout << "Found " << tables.size() <<
51  " user table(s) in information schema." << std::endl;
52  }
53  void fill_scope(struct scope &s) {
54  for (auto &t : tables)
55  s.tables.push_back(&t);
56  s.schema = this;
57  }
58  virtual void register_operator(op& o) {
59  operators.push_back(o);
60  typekey t(o.left, o.right, o.result);
61  index.insert(std::pair<typekey,op>(t,o));
62  }
63  virtual void register_routine(routine& r) {
64  routines.push_back(r);
65  }
66  virtual void register_aggregate(routine& r) {
67  aggregates.push_back(r);
68  }
69  virtual op_iterator find_operator(sqltype *left, sqltype *right, sqltype *res) {
70  typekey t(left, right, res);
71  auto cons = index.equal_range(t);
72  if (cons.first == cons.second)
73  return index.end();
74  else
75  return random_pick<>(cons.first, cons.second);
76  }
77  schema() { }
78  void generate_indexes();
79 };
80 
81 #endif
82 
randomness
supporting classes for the grammar
Definition: relmodel.hh:117
Definition: schema.hh:16
vector< named_relation * > tables
available to table_ref productions
Definition: relmodel.hh:82