aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/utils/database.h8
-rw-r--r--src/lib/utils/sqlite3/sqlite3.cpp19
2 files changed, 18 insertions, 9 deletions
diff --git a/src/lib/utils/database.h b/src/lib/utils/database.h
index bacbedd1e..4d8b90d0c 100644
--- a/src/lib/utils/database.h
+++ b/src/lib/utils/database.h
@@ -9,6 +9,7 @@
#define BOTAN_SQL_DATABASE_H__
#include <botan/types.h>
+#include <botan/exceptn.h>
#include <string>
#include <chrono>
#include <vector>
@@ -18,6 +19,13 @@ namespace Botan {
class BOTAN_DLL SQL_Database
{
public:
+
+ class BOTAN_DLL SQL_DB_Error : public Exception
+ {
+ public:
+ SQL_DB_Error(const std::string& what) : Exception("SQL database", what) {}
+ };
+
class BOTAN_DLL Statement
{
public:
diff --git a/src/lib/utils/sqlite3/sqlite3.cpp b/src/lib/utils/sqlite3/sqlite3.cpp
index 1220829dd..77b4c0d10 100644
--- a/src/lib/utils/sqlite3/sqlite3.cpp
+++ b/src/lib/utils/sqlite3/sqlite3.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/sqlite3.h>
+#include <botan/exceptn.h>
#include <sqlite3.h>
namespace Botan {
@@ -19,7 +20,7 @@ Sqlite3_Database::Sqlite3_Database(const std::string& db_filename)
const std::string err_msg = ::sqlite3_errmsg(m_db);
::sqlite3_close(m_db);
m_db = nullptr;
- throw Exception("sqlite3_open failed - " + err_msg);
+ throw SQL_DB_Error("sqlite3_open failed - " + err_msg);
}
}
@@ -42,7 +43,7 @@ size_t Sqlite3_Database::row_count(const std::string& table_name)
if(stmt->step())
return stmt->get_size_t(0);
else
- throw Exception("Querying size of table " + table_name + " failed");
+ throw SQL_DB_Error("Querying size of table " + table_name + " failed");
}
void Sqlite3_Database::create_table(const std::string& table_schema)
@@ -56,7 +57,7 @@ void Sqlite3_Database::create_table(const std::string& table_schema)
::sqlite3_free(errmsg);
::sqlite3_close(m_db);
m_db = nullptr;
- throw Exception("sqlite3_exec for table failed - " + err_msg);
+ throw SQL_DB_Error("sqlite3_exec for table failed - " + err_msg);
}
}
@@ -65,24 +66,24 @@ Sqlite3_Database::Sqlite3_Statement::Sqlite3_Statement(sqlite3* db, const std::s
int rc = ::sqlite3_prepare_v2(db, base_sql.c_str(), -1, &m_stmt, nullptr);
if(rc != SQLITE_OK)
- throw Exception("sqlite3_prepare failed " + base_sql +
- ", code " + std::to_string(rc));
+ throw SQL_DB_Error("sqlite3_prepare failed " + base_sql +
+ ", code " + std::to_string(rc));
}
void Sqlite3_Database::Sqlite3_Statement::bind(int column, const std::string& val)
{
int rc = ::sqlite3_bind_text(m_stmt, column, val.c_str(), -1, SQLITE_TRANSIENT);
if(rc != SQLITE_OK)
- throw Exception("sqlite3_bind_text failed, code " + std::to_string(rc));
+ throw SQL_DB_Error("sqlite3_bind_text failed, code " + std::to_string(rc));
}
void Sqlite3_Database::Sqlite3_Statement::bind(int column, size_t val)
{
if(val != static_cast<size_t>(static_cast<int>(val))) // is this legit?
- throw Exception("sqlite3 cannot store " + std::to_string(val) + " without truncation");
+ throw SQL_DB_Error("sqlite3 cannot store " + std::to_string(val) + " without truncation");
int rc = ::sqlite3_bind_int(m_stmt, column, val);
if(rc != SQLITE_OK)
- throw Exception("sqlite3_bind_int failed, code " + std::to_string(rc));
+ throw SQL_DB_Error("sqlite3_bind_int failed, code " + std::to_string(rc));
}
void Sqlite3_Database::Sqlite3_Statement::bind(int column, std::chrono::system_clock::time_point time)
@@ -95,7 +96,7 @@ void Sqlite3_Database::Sqlite3_Statement::bind(int column, const std::vector<byt
{
int rc = ::sqlite3_bind_blob(m_stmt, column, val.data(), val.size(), SQLITE_TRANSIENT);
if(rc != SQLITE_OK)
- throw Exception("sqlite3_bind_text failed, code " + std::to_string(rc));
+ throw SQL_DB_Error("sqlite3_bind_text failed, code " + std::to_string(rc));
}
std::pair<const byte*, size_t> Sqlite3_Database::Sqlite3_Statement::get_blob(int column)