diff Core/SQLite/Connection.cpp @ 1582:bd1889029cbb

encoding of exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 17:39:38 +0200
parents f967bdf8534e
children 9a3e03d6a4d5
line wrap: on
line diff
--- a/Core/SQLite/Connection.cpp	Tue Aug 25 16:18:37 2015 +0200
+++ b/Core/SQLite/Connection.cpp	Tue Aug 25 17:39:38 2015 +0200
@@ -75,7 +75,7 @@
     {
       if (!db_)
       {
-        throw OrthancSQLiteException("SQLite: The database is not opened");
+        throw OrthancSQLiteException(ErrorCode_SQLiteNotOpened);
       }
     }
 
@@ -83,7 +83,7 @@
     {
       if (db_) 
       {
-        throw OrthancSQLiteException("SQLite: Connection is already open");
+        throw OrthancSQLiteException(ErrorCode_SQLiteAlreadyOpened);
       }
 
       int err = sqlite3_open(path.c_str(), &db_);
@@ -91,7 +91,7 @@
       {
         Close();
         db_ = NULL;
-        throw OrthancSQLiteException("SQLite: Unable to open the database");
+        throw OrthancSQLiteException(ErrorCode_SQLiteCannotOpen);
       }
 
       // Execute PRAGMAs at this point
@@ -137,7 +137,7 @@
       {
         if (i->second->GetReferenceCount() >= 1)
         {
-          throw OrthancSQLiteException("SQLite: This cached statement is already being referred to");
+          throw OrthancSQLiteException(ErrorCode_SQLiteStatementAlreadyUsed);
         }
 
         return *i->second;
@@ -162,7 +162,8 @@
       int error = sqlite3_exec(db_, sql, NULL, NULL, NULL);
       if (error == SQLITE_ERROR)
       {
-        throw OrthancSQLiteException("SQLite Execute error: " + std::string(sqlite3_errmsg(db_)));
+        LOG(ERROR) << "SQLite execute error: " << sqlite3_errmsg(db_);
+        throw OrthancSQLiteException(ErrorCode_SQLiteExecute);
       }
       else
       {
@@ -283,7 +284,7 @@
     {
       if (!transactionNesting_)
       {
-        throw OrthancSQLiteException("Rolling back a nonexistent transaction");
+        throw OrthancSQLiteException(ErrorCode_SQLiteRollbackWithoutTransaction);
       }
 
       transactionNesting_--;
@@ -302,7 +303,7 @@
     {
       if (!transactionNesting_) 
       {
-        throw OrthancSQLiteException("Committing a nonexistent transaction");
+        throw OrthancSQLiteException(ErrorCode_SQLiteCommitWithoutTransaction);
       }
       transactionNesting_--;
 
@@ -370,7 +371,7 @@
       if (err != SQLITE_OK)
       {
         delete func;
-        throw OrthancSQLiteException("SQLite: Unable to register a function");
+        throw OrthancSQLiteException(ErrorCode_SQLiteRegisterFunction);
       }
 
       return func;
@@ -387,7 +388,7 @@
 
       if (err != SQLITE_OK)
       {
-        throw OrthancSQLiteException("SQLite: Unable to flush the database");
+        throw OrthancSQLiteException(ErrorCode_SQLiteFlush);
       }
     }
   }