Skip to content

Commit e2ca833

Browse files
committed
Add --dump-all-queries, printing queries as they are generated.
1 parent bee122b commit e2ca833

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.org

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The following options are currently supported:
8080
| =--dry-run= | print queries instead of executing them |
8181
| =--max-queries=long= | terminate after generating this many queries |
8282
| =--exclude-catalog= | don't generate queries using catalog relations |
83+
| =--dump-all-queries= | dump queries as they are generated |
8384
| =--dump-all-graphs= | dump generated ASTs for debugging |
8485
| =--rng-state=string= | deserialize dumped rng state |
8586

log.hh

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ struct logger {
2020
}
2121
};
2222

23+
/// logger to dump all generated queries
24+
struct query_dumper : logger {
25+
virtual void generated(prod &query) {
26+
query.out(std::cout);
27+
std::cout << ";" << std::endl;
28+
}
29+
};
30+
2331
/// logger for statistics collection
2432
struct stats_collecting_logger : logger {
2533
long queries = 0;

sqlsmith.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
6262
cerr << PACKAGE_NAME " " GITREV << endl;
6363

6464
map<string,string> options;
65-
regex optregex("--(help|log-to|verbose|target|sqlite|monetdb|version|dump-all-graphs|seed|dry-run|max-queries|rng-state|exclude-catalog)(?:=((?:.|\n)*))?");
65+
regex optregex("--(help|log-to|verbose|target|sqlite|monetdb|version|dump-all-graphs|dump-all-queries|seed|dry-run|max-queries|rng-state|exclude-catalog)(?:=((?:.|\n)*))?");
6666

6767
for(char **opt = argv+1 ;opt < argv+argc; opt++) {
6868
smatch match;
@@ -86,6 +86,7 @@ int main(int argc, char *argv[])
8686
#endif
8787
" --log-to=connstr log errors to postgres database" << endl <<
8888
" --seed=int seed RNG with specified int instead of PID" << endl <<
89+
" --dump-all-queries print queries as they are generated" << endl <<
8990
" --dump-all-graphs dump generated ASTs" << endl <<
9091
" --dry-run print queries instead of executing them" << endl <<
9192
" --exclude-catalog don't generate queries using catalog relations" << endl <<
@@ -149,7 +150,10 @@ int main(int argc, char *argv[])
149150

150151
if (options.count("dump-all-graphs"))
151152
loggers.push_back(make_shared<ast_logger>());
152-
153+
154+
if (options.count("dump-all-queries"))
155+
loggers.push_back(make_shared<query_dumper>());
156+
153157
if (options.count("dry-run")) {
154158
while (1) {
155159
shared_ptr<prod> gen = statement_factory(&scope);

0 commit comments

Comments
 (0)