| 70 | |
| 71 | |
| 72 | NameSet DatabaseSQLite::fetchTablesList() const |
| 73 | { |
| 74 | if (!sqlite_db) |
| 75 | sqlite_db = openSQLiteDB(database_path, getContext(), /* throw_on_error */true); |
| 76 | |
| 77 | std::unordered_set<String> tables; |
| 78 | std::string query = "SELECT name FROM sqlite_master " |
| 79 | "WHERE type = 'table' AND name NOT LIKE 'sqlite_%'"; |
| 80 | |
| 81 | auto callback_get_data = [](void * res, int col_num, char ** data_by_col, char ** /* col_names */) -> int |
| 82 | { |
| 83 | for (int i = 0; i < col_num; ++i) |
| 84 | static_cast<std::unordered_set<std::string> *>(res)->insert(data_by_col[i]); |
| 85 | return 0; |
| 86 | }; |
| 87 | |
| 88 | char * err_message = nullptr; |
| 89 | int status = sqlite3_exec(sqlite_db.get(), query.c_str(), callback_get_data, &tables, &err_message); |
| 90 | if (status != SQLITE_OK) |
| 91 | { |
| 92 | String err_msg(err_message); |
| 93 | sqlite3_free(err_message); |
| 94 | throw Exception(ErrorCodes::SQLITE_ENGINE_ERROR, |
| 95 | "Cannot fetch sqlite database tables. Error status: {}. Message: {}", |
| 96 | status, err_msg); |
| 97 | } |
| 98 | |
| 99 | return tables; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | bool DatabaseSQLite::checkSQLiteTable(const String & table_name) const |
nothing calls this directly
no test coverage detected