|
28 | 28 |
|
29 | 29 | namespace sqlite {
|
30 | 30 |
|
31 |
| - struct sqlite_exception: public std::runtime_error { |
32 |
| - sqlite_exception(const char* msg):runtime_error(msg) {} |
| 31 | + class sqlite_exception: public std::runtime_error { |
| 32 | + public: |
| 33 | + sqlite_exception(const char* msg, int code = -1): runtime_error(msg), code(code) {} |
| 34 | + sqlite_exception(int code): runtime_error(sqlite3_errstr(code)), code(code) {} |
| 35 | + int get_code() {return code;} |
| 36 | + private: |
| 37 | + int code; |
33 | 38 | };
|
34 | 39 |
|
35 | 40 | namespace exceptions {
|
@@ -70,33 +75,33 @@ namespace sqlite {
|
70 | 75 | class no_rows: public sqlite_exception { using sqlite_exception::sqlite_exception; };
|
71 | 76 |
|
72 | 77 | static void throw_sqlite_error(const int& error_code) {
|
73 |
| - if(error_code == SQLITE_ERROR) throw exceptions::error(sqlite3_errstr(error_code)); |
74 |
| - else if(error_code == SQLITE_INTERNAL) throw exceptions::internal (sqlite3_errstr(error_code)); |
75 |
| - else if(error_code == SQLITE_PERM) throw exceptions::perm(sqlite3_errstr(error_code)); |
76 |
| - else if(error_code == SQLITE_ABORT) throw exceptions::abort(sqlite3_errstr(error_code)); |
77 |
| - else if(error_code == SQLITE_BUSY) throw exceptions::busy(sqlite3_errstr(error_code)); |
78 |
| - else if(error_code == SQLITE_LOCKED) throw exceptions::locked(sqlite3_errstr(error_code)); |
79 |
| - else if(error_code == SQLITE_NOMEM) throw exceptions::nomem(sqlite3_errstr(error_code)); |
80 |
| - else if(error_code == SQLITE_READONLY) throw exceptions::readonly(sqlite3_errstr(error_code)); |
81 |
| - else if(error_code == SQLITE_INTERRUPT) throw exceptions::interrupt(sqlite3_errstr(error_code)); |
82 |
| - else if(error_code == SQLITE_IOERR) throw exceptions::ioerr(sqlite3_errstr(error_code)); |
83 |
| - else if(error_code == SQLITE_CORRUPT) throw exceptions::corrupt(sqlite3_errstr(error_code)); |
84 |
| - else if(error_code == SQLITE_NOTFOUND) throw exceptions::notfound(sqlite3_errstr(error_code)); |
85 |
| - else if(error_code == SQLITE_FULL) throw exceptions::full(sqlite3_errstr(error_code)); |
86 |
| - else if(error_code == SQLITE_CANTOPEN) throw exceptions::cantopen(sqlite3_errstr(error_code)); |
87 |
| - else if(error_code == SQLITE_PROTOCOL) throw exceptions::protocol(sqlite3_errstr(error_code)); |
88 |
| - else if(error_code == SQLITE_EMPTY) throw exceptions::empty(sqlite3_errstr(error_code)); |
89 |
| - else if(error_code == SQLITE_SCHEMA) throw exceptions::schema(sqlite3_errstr(error_code)); |
90 |
| - else if(error_code == SQLITE_TOOBIG) throw exceptions::toobig(sqlite3_errstr(error_code)); |
91 |
| - else if(error_code == SQLITE_CONSTRAINT) throw exceptions::constraint(sqlite3_errstr(error_code)); |
92 |
| - else if(error_code == SQLITE_MISMATCH) throw exceptions::mismatch(sqlite3_errstr(error_code)); |
93 |
| - else if(error_code == SQLITE_MISUSE) throw exceptions::misuse(sqlite3_errstr(error_code)); |
94 |
| - else if(error_code == SQLITE_NOLFS) throw exceptions::nolfs(sqlite3_errstr(error_code)); |
95 |
| - else if(error_code == SQLITE_AUTH) throw exceptions::auth(sqlite3_errstr(error_code)); |
96 |
| - else if(error_code == SQLITE_FORMAT) throw exceptions::format(sqlite3_errstr(error_code)); |
97 |
| - else if(error_code == SQLITE_RANGE) throw exceptions::range(sqlite3_errstr(error_code)); |
98 |
| - else if(error_code == SQLITE_NOTADB) throw exceptions::notadb(sqlite3_errstr(error_code)); |
99 |
| - else throw sqlite_exception(sqlite3_errstr(error_code)); |
| 78 | + if(error_code == SQLITE_ERROR) throw exceptions::error(error_code); |
| 79 | + else if(error_code == SQLITE_INTERNAL) throw exceptions::internal (error_code); |
| 80 | + else if(error_code == SQLITE_PERM) throw exceptions::perm(error_code); |
| 81 | + else if(error_code == SQLITE_ABORT) throw exceptions::abort(error_code); |
| 82 | + else if(error_code == SQLITE_BUSY) throw exceptions::busy(error_code); |
| 83 | + else if(error_code == SQLITE_LOCKED) throw exceptions::locked(error_code); |
| 84 | + else if(error_code == SQLITE_NOMEM) throw exceptions::nomem(error_code); |
| 85 | + else if(error_code == SQLITE_READONLY) throw exceptions::readonly(error_code); |
| 86 | + else if(error_code == SQLITE_INTERRUPT) throw exceptions::interrupt(error_code); |
| 87 | + else if(error_code == SQLITE_IOERR) throw exceptions::ioerr(error_code); |
| 88 | + else if(error_code == SQLITE_CORRUPT) throw exceptions::corrupt(error_code); |
| 89 | + else if(error_code == SQLITE_NOTFOUND) throw exceptions::notfound(error_code); |
| 90 | + else if(error_code == SQLITE_FULL) throw exceptions::full(error_code); |
| 91 | + else if(error_code == SQLITE_CANTOPEN) throw exceptions::cantopen(error_code); |
| 92 | + else if(error_code == SQLITE_PROTOCOL) throw exceptions::protocol(error_code); |
| 93 | + else if(error_code == SQLITE_EMPTY) throw exceptions::empty(error_code); |
| 94 | + else if(error_code == SQLITE_SCHEMA) throw exceptions::schema(error_code); |
| 95 | + else if(error_code == SQLITE_TOOBIG) throw exceptions::toobig(error_code); |
| 96 | + else if(error_code == SQLITE_CONSTRAINT) throw exceptions::constraint(error_code); |
| 97 | + else if(error_code == SQLITE_MISMATCH) throw exceptions::mismatch(error_code); |
| 98 | + else if(error_code == SQLITE_MISUSE) throw exceptions::misuse(error_code); |
| 99 | + else if(error_code == SQLITE_NOLFS) throw exceptions::nolfs(error_code); |
| 100 | + else if(error_code == SQLITE_AUTH) throw exceptions::auth(error_code); |
| 101 | + else if(error_code == SQLITE_FORMAT) throw exceptions::format(error_code); |
| 102 | + else if(error_code == SQLITE_RANGE) throw exceptions::range(error_code); |
| 103 | + else if(error_code == SQLITE_NOTADB) throw exceptions::notadb(error_code); |
| 104 | + else throw sqlite_exception(error_code); |
100 | 105 | }
|
101 | 106 | }
|
102 | 107 |
|
@@ -183,11 +188,11 @@ namespace sqlite {
|
183 | 188 | if((hresult = sqlite3_step(_stmt.get())) == SQLITE_ROW) {
|
184 | 189 | call_back();
|
185 | 190 | } else if(hresult == SQLITE_DONE) {
|
186 |
| - throw exceptions::no_rows("no rows to extract: exactly 1 row expected"); |
| 191 | + throw exceptions::no_rows("no rows to extract: exactly 1 row expected", SQLITE_DONE); |
187 | 192 | }
|
188 | 193 |
|
189 | 194 | if((hresult = sqlite3_step(_stmt.get())) == SQLITE_ROW) {
|
190 |
| - throw exceptions::more_rows("not all rows extracted"); |
| 195 | + throw exceptions::more_rows("not all rows extracted", SQLITE_ROW); |
191 | 196 | }
|
192 | 197 |
|
193 | 198 | if(hresult != SQLITE_DONE) {
|
|
0 commit comments