| 88 | } |
| 89 | |
| 90 | bool DB::exist(String tableName, String schema) const { |
| 91 | bool existed = false; |
| 92 | _thread->runInMainSync([&]() { |
| 93 | if (!schema.empty() && !existDBUnsafe(_database.get(), schema)) { |
| 94 | return; |
| 95 | } |
| 96 | try { |
| 97 | SQLite::Statement statement(*_database, schema.empty() ? "SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?)"s : fmt::format("SELECT EXISTS(SELECT 1 FROM {}.sqlite_master WHERE type='table' AND name = ?)", schema.toString())); |
| 98 | statement.bind(1, tableName.toString()); |
| 99 | int result = 0; |
| 100 | if (statement.executeStep()) { |
| 101 | result = statement.getColumn(0); |
| 102 | } |
| 103 | existed = result == 0 ? false : true; |
| 104 | } catch (std::exception& e) { |
| 105 | Warn("failed to execute DB query: {}", e.what()); |
| 106 | } |
| 107 | }); |
| 108 | return existed; |
| 109 | } |
| 110 | |
| 111 | int DB::exec(String sql) { |
| 112 | int rowChanged = -1; |
nothing calls this directly
no test coverage detected