|
1 | 1 | #pragma once
|
2 | 2 |
|
| 3 | +#include <algorithm> |
| 4 | +#include <cctype> |
3 | 5 | #include <string>
|
4 | 6 | #include <functional>
|
5 | 7 | #include <stdexcept>
|
@@ -85,10 +87,11 @@ namespace sqlite {
|
85 | 87 | class more_rows: public sqlite_exception { using sqlite_exception::sqlite_exception; };
|
86 | 88 | class no_rows: public sqlite_exception { using sqlite_exception::sqlite_exception; };
|
87 | 89 | class reexecution: public sqlite_exception { using sqlite_exception::sqlite_exception; }; // Prepared statements need to be reset before calling them again
|
| 90 | + class more_statements: public sqlite_exception { using sqlite_exception::sqlite_exception; }; // Prepared statements can only contain one statement |
88 | 91 |
|
89 | 92 | static void throw_sqlite_error(const int& error_code, const std::string &sql = "") {
|
90 | 93 | if(error_code == SQLITE_ERROR) throw exceptions::error(error_code, sql);
|
91 |
| - else if(error_code == SQLITE_INTERNAL) throw exceptions::internal (error_code, sql); |
| 94 | + else if(error_code == SQLITE_INTERNAL) throw exceptions::internal(error_code, sql); |
92 | 95 | else if(error_code == SQLITE_PERM) throw exceptions::perm(error_code, sql);
|
93 | 96 | else if(error_code == SQLITE_ABORT) throw exceptions::abort(error_code, sql);
|
94 | 97 | else if(error_code == SQLITE_BUSY) throw exceptions::busy(error_code, sql);
|
@@ -249,8 +252,11 @@ namespace sqlite {
|
249 | 252 | sqlite3_stmt* _prepare(const std::string& sql) {
|
250 | 253 | int hresult;
|
251 | 254 | sqlite3_stmt* tmp = nullptr;
|
252 |
| - hresult = sqlite3_prepare_v2(_db.get(), sql.data(), -1, &tmp, nullptr); |
253 |
| - if((hresult) != SQLITE_OK) exceptions::throw_sqlite_error(hresult, sql); |
| 255 | + const char *remaining; |
| 256 | + hresult = sqlite3_prepare_v2(_db.get(), sql.data(), -1, &tmp, &remaining); |
| 257 | + if(hresult != SQLITE_OK) exceptions::throw_sqlite_error(hresult, sql); |
| 258 | + if(!std::all_of(remaining, sql.data() + sql.size(), [](char ch) {return std::isblank(ch);})) |
| 259 | + throw exceptions::more_statements("Multiple semicolon separated statements are unsupported", sql); |
254 | 260 | return tmp;
|
255 | 261 | }
|
256 | 262 |
|
@@ -296,7 +302,7 @@ namespace sqlite {
|
296 | 302 | // Overload instead of specializing function templates (http://www.gotw.ca/publications/mill17.htm)
|
297 | 303 | friend database_binder& operator<<(database_binder& db, const int& val);
|
298 | 304 | friend void get_col_from_db(database_binder& db, int inx, int& val);
|
299 |
| - friend database_binder& operator <<(database_binder& db, const sqlite_int64& val); |
| 305 | + friend database_binder& operator <<(database_binder& db, const sqlite_int64& val); |
300 | 306 | friend void get_col_from_db(database_binder& db, int inx, sqlite3_int64& i);
|
301 | 307 | friend database_binder& operator <<(database_binder& db, const float& val);
|
302 | 308 | friend void get_col_from_db(database_binder& db, int inx, float& f);
|
|
0 commit comments