| 87 | } |
| 88 | |
| 89 | schema_sqlite::schema_sqlite(std::string &conninfo, bool no_catalog) |
| 90 | : sqlite_connection(conninfo) |
| 91 | { |
| 92 | std::string query = "SELECT * FROM main.sqlite_master where type in ('table', 'view')"; |
| 93 | |
| 94 | if (no_catalog) |
| 95 | query+= " AND name NOT like 'sqlite_%%'"; |
| 96 | |
| 97 | version = "SQLite " SQLITE_VERSION " " SQLITE_SOURCE_ID; |
| 98 | |
| 99 | // sqlite3_busy_handler(db, my_sqlite3_busy_handler, 0); |
| 100 | cerr << "Loading tables..."; |
| 101 | |
| 102 | rc = sqlite3_exec(db, query.c_str(), table_callback, (void *)&tables, &zErrMsg); |
| 103 | if (rc!=SQLITE_OK) { |
| 104 | auto e = std::runtime_error(zErrMsg); |
| 105 | sqlite3_free(zErrMsg); |
| 106 | throw e; |
| 107 | } |
| 108 | |
| 109 | if (!no_catalog) |
| 110 | { |
| 111 | // sqlite_master doesn't list itself, do it manually |
| 112 | table tab("sqlite_master", "main", false, false); |
| 113 | tables.push_back(tab); |
| 114 | } |
| 115 | |
| 116 | cerr << "done." << endl; |
| 117 | |
| 118 | cerr << "Loading columns and constraints..."; |
| 119 | |
| 120 | for (auto t = tables.begin(); t != tables.end(); ++t) { |
| 121 | string q("pragma table_info("); |
| 122 | q += t->name; |
| 123 | q += ");"; |
| 124 | |
| 125 | rc = sqlite3_exec(db, q.c_str(), column_callback, (void *)&*t, &zErrMsg); |
| 126 | if (rc!=SQLITE_OK) { |
| 127 | auto e = std::runtime_error(zErrMsg); |
| 128 | sqlite3_free(zErrMsg); |
| 129 | throw e; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | cerr << "done." << endl; |
| 134 | |
| 135 | #define BINOP(n,t) do {op o(#n,sqltype::get(#t),sqltype::get(#t),sqltype::get(#t)); register_operator(o); } while(0) |
| 136 | |
| 137 | BINOP(||, TEXT); |
| 138 | BINOP(*, INTEGER); |
| 139 | BINOP(/, INTEGER); |
| 140 | |
| 141 | BINOP(+, INTEGER); |
| 142 | BINOP(-, INTEGER); |
| 143 | |
| 144 | BINOP(>>, INTEGER); |
| 145 | BINOP(<<, INTEGER); |
| 146 |
nothing calls this directly
no outgoing calls
no test coverage detected