Skip to content

Commit 34767ea

Browse files
committed
Add an "exclude-catalog" option.
1 parent d2f6823 commit 34767ea

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

postgres.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void dut_pqxx::test(const std::string &stmt)
102102
}
103103

104104

105-
schema_pqxx::schema_pqxx(std::string &conninfo) : c(conninfo)
105+
schema_pqxx::schema_pqxx(std::string &conninfo, bool no_catalog) : c(conninfo)
106106
{
107107
pqxx::work w(c);
108108

@@ -154,10 +154,9 @@ schema_pqxx::schema_pqxx(std::string &conninfo) : c(conninfo)
154154
string schema(row[1].as<string>());
155155
string insertable(row[2].as<string>());
156156
string table_type(row[3].as<string>());
157-
// if (schema == "pg_catalog")
158-
// continue;
159-
// if (schema == "information_schema")
160-
// continue;
157+
158+
if (no_catalog && ((schema == "pg_catalog") || (schema == "information_schema")))
159+
continue;
161160

162161
tables.push_back(table(row[0].as<string>(),
163162
schema,

postgres.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct schema_pqxx : public schema {
4343
virtual std::string quote_name(const std::string &id) {
4444
return c.quote_name(id);
4545
}
46-
schema_pqxx(std::string &conninfo);
46+
schema_pqxx(std::string &conninfo, bool no_catalog);
4747
};
4848

4949
struct dut_pqxx : dut_base {

sqlite.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,32 @@ sqlite_connection::~sqlite_connection()
8585
sqlite3_close(db);
8686
}
8787

88-
schema_sqlite::schema_sqlite(std::string &conninfo)
88+
schema_sqlite::schema_sqlite(std::string &conninfo, bool no_catalog)
8989
: sqlite_connection(conninfo)
9090
{
91+
std::string query = "SELECT * FROM main.sqlite_master where type in ('table', 'view')";
92+
93+
if (no_catalog)
94+
query+= " AND name NOT like 'sqlite_%%'";
9195

9296
version = "SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID;
9397

9498
// sqlite3_busy_handler(db, my_sqlite3_busy_handler, 0);
9599
cerr << "Loading tables...";
96100

97-
rc = sqlite3_exec(db, "SELECT * FROM main.sqlite_master where type in ('table', 'view')", table_callback, (void *)&tables, &zErrMsg);
101+
rc = sqlite3_exec(db, query.c_str(), table_callback, (void *)&tables, &zErrMsg);
98102
if (rc!=SQLITE_OK) {
99103
auto e = std::runtime_error(zErrMsg);
100104
sqlite3_free(zErrMsg);
101105
throw e;
102106
}
103107

104-
// sqlite_master doesn't list itself, do it manually
105-
table tab("sqlite_master", "main", false, false);
106-
tables.push_back(tab);
108+
if (!no_catalog)
109+
{
110+
// sqlite_master doesn't list itself, do it manually
111+
table tab("sqlite_master", "main", false, false);
112+
tables.push_back(tab);
113+
}
107114

108115
cerr << "done." << endl;
109116

sqlite.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct sqlite_connection {
2222
};
2323

2424
struct schema_sqlite : schema, sqlite_connection {
25-
schema_sqlite(std::string &conninfo);
25+
schema_sqlite(std::string &conninfo, bool no_catalog);
2626
virtual std::string quote_name(const std::string &id) {
2727
return id;
2828
}

sqlsmith.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
5858
cerr << PACKAGE_NAME " " GITREV << endl;
5959

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

6363
for(char **opt = argv+1 ;opt < argv+argc; opt++) {
6464
smatch match;
@@ -81,6 +81,7 @@ int main(int argc, char *argv[])
8181
" --seed=int seed RNG with specified int instead of PID" << endl <<
8282
" --dump-all-graphs dump generated ASTs" << endl <<
8383
" --dry-run print queries instead of executing them" << endl <<
84+
" --exclude-catalog don't generate queries using the catalog objects" << endl <<
8485
" --max-queries=long terminate after generating this many queries" << endl <<
8586
" --verbose emit progress output" << endl <<
8687
" --version print version information and exit" << endl <<
@@ -95,14 +96,14 @@ int main(int argc, char *argv[])
9596
shared_ptr<schema> schema;
9697
if (options.count("sqlite")) {
9798
#ifdef HAVE_LIBSQLITE3
98-
schema = make_shared<schema_sqlite>(options["sqlite"]);
99+
schema = make_shared<schema_sqlite>(options["sqlite"], options.count("exclude-catalog"));
99100
#else
100101
cerr << "Sorry, " PACKAGE_NAME " was compiled without SQLite support." << endl;
101102
return 1;
102103
#endif
103104
}
104105
else
105-
schema = make_shared<schema_pqxx>(options["target"]);
106+
schema = make_shared<schema_pqxx>(options["target"], options.count("exclude-catalog"));
106107

107108
scope scope;
108109
long queries_generated = 0;

0 commit comments

Comments
 (0)