* Attempt to open and test the database file before * accessing the configuration table. We do this because * the global table constructor cannot provide notification * in the event of failure. */
| 67 | * in the event of failure. |
| 68 | */ |
| 69 | int testConfig(const char *filename) |
| 70 | { |
| 71 | int rc, val = 9999; |
| 72 | sqlite3 *db; |
| 73 | std::string test = "sadf732zdvj2"; |
| 74 | |
| 75 | const char *keys[3] = { |
| 76 | "Log.Level", |
| 77 | "TRX.Port", |
| 78 | "TRX.IP", |
| 79 | }; |
| 80 | |
| 81 | /* Try to open the database */ |
| 82 | rc = sqlite3_open(filename, &db); |
| 83 | if (rc || !db) { |
| 84 | std::cerr << "Config: Database could not be opened" << std::endl; |
| 85 | return -1; |
| 86 | } else { |
| 87 | sqlite3_close(db); |
| 88 | } |
| 89 | |
| 90 | /* Attempt to set a value in the global config */ |
| 91 | if (!gConfig.set(test, val)) { |
| 92 | std::cerr << "Config: Failed to set test key - " |
| 93 | << "permission to access the database?" << std::endl; |
| 94 | return -1; |
| 95 | } else { |
| 96 | gConfig.remove(test); |
| 97 | } |
| 98 | |
| 99 | /* Attempt to query */ |
| 100 | for (int i = 0; i < 3; i++) { |
| 101 | try { |
| 102 | gConfig.getStr(keys[i]); |
| 103 | } catch (...) { |
| 104 | std::cerr << "Config: Failed query on " << keys[i] << std::endl; |
| 105 | return -1; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | int main(int argc, char *argv[]) |
| 113 | { |