diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-29 02:42:43 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-29 06:00:07 +0000 |
commit | 3a7e2b9a7bde4682f2273022e9d2ddecd7e5e3b8 (patch) | |
tree | d5dc58209bd8fa28047c54a11c09bc64505d5354 /libsqlitepp/sqlite-connection.cpp | |
parent | Remove rebind (diff) | |
download | libdbpp-sqlite-3a7e2b9a7bde4682f2273022e9d2ddecd7e5e3b8.tar.bz2 libdbpp-sqlite-3a7e2b9a7bde4682f2273022e9d2ddecd7e5e3b8.tar.xz libdbpp-sqlite-3a7e2b9a7bde4682f2273022e9d2ddecd7e5e3b8.zip |
Reshuffle and add new exceptions
Diffstat (limited to 'libsqlitepp/sqlite-connection.cpp')
-rw-r--r-- | libsqlitepp/sqlite-connection.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/libsqlitepp/sqlite-connection.cpp b/libsqlitepp/sqlite-connection.cpp index 5eead63..df7de68 100644 --- a/libsqlitepp/sqlite-connection.cpp +++ b/libsqlitepp/sqlite-connection.cpp @@ -3,17 +3,19 @@ #include "sqlite-selectcommand.h" #include "sqlite-modifycommand.h" +SQLite::ConnectionError::ConnectionError(sqlite3 * db) : + SQLite::Error(db) +{ +} + SQLite::Connection::Connection(const std::string & str) : txDepth(0), rolledback(false) { if (sqlite3_open(str.c_str(), &db) != SQLITE_OK) { - if (db) { - std::string err(sqlite3_errmsg(db)); - sqlite3_close(db); - throw Error(err.c_str()); - } - throw Error("Unknown error opening database"); + ConnectionError err(db); + sqlite3_close(db); + throw err; } } @@ -27,7 +29,7 @@ SQLite::Connection::finish() const { if (txDepth != 0) { rollbackTx(); - throw Error("Transaction still open"); + throw DB::TransactionStillOpen(); } } @@ -36,7 +38,7 @@ SQLite::Connection::beginTx() const { if (txDepth == 0) { if (sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { - throw Error(sqlite3_errmsg(db)); + throw Error(db); } rolledback = false; } @@ -51,7 +53,7 @@ SQLite::Connection::commitTx() const } if (--txDepth == 0) { if (sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { - throw Error(sqlite3_errmsg(db)); + throw Error(db); } } return txDepth; @@ -62,7 +64,7 @@ SQLite::Connection::rollbackTx() const { if (--txDepth == 0) { if (sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) { - throw Error(sqlite3_errmsg(db)); + throw Error(db); } } else { @@ -111,19 +113,19 @@ SQLite::Connection::newModifyCommand(const std::string & sql) const void SQLite::Connection::beginBulkUpload(const char *, const char *) const { - throw Error("Not implemented"); + throw DB::BulkUploadNotSupported(); } void SQLite::Connection::endBulkUpload(const char *) const { - throw Error("Not implemented"); + throw DB::BulkUploadNotSupported(); } size_t SQLite::Connection::bulkUploadData(const char *, size_t) const { - throw Error("Not implemented"); + throw DB::BulkUploadNotSupported(); } int64_t |