@@ -61,6 +61,7 @@ namespace libp2p::storage {
6161 * @param st_handle - statement identifier
6262 * @param args - command arguments
6363 * @return number of rows affected, -1 in case of error
64+ * @throws std::invalid_argument if statement handle is invalid
6465 */
6566 template <typename ... Args>
6667 inline int execCommand (StatementHandle st_handle, const Args &...args) {
@@ -69,11 +70,14 @@ namespace libp2p::storage {
6970 bindArgs (st, args...);
7071 st.execute ();
7172 return countChanges ();
72- } catch (const std::runtime_error &e) {
73+ } catch (const std::invalid_argument &e) {
7374 // getStatement can receive invalid handle
74- log_->error (e.what ());
75+ log_->error (" Invalid statement handle: {}" , e.what ());
76+ throw ; // Re-throw invalid_argument as it's a programming error
77+ } catch (const std::runtime_error &e) {
78+ log_->error (" Runtime error during command execution: {}" , e.what ());
7579 } catch (...) {
76- log_->error (getErrorMessage ());
80+ log_->error (" Unknown error during command execution: {} " , getErrorMessage ());
7781 }
7882 return -1 ;
7983 }
@@ -86,6 +90,7 @@ namespace libp2p::storage {
8690 * @param sink - query response consumer
8791 * @param args - query arguments
8892 * @return true when query was successfully executed, otherwise - false
93+ * @throws std::invalid_argument if statement handle is invalid
8994 */
9095 template <typename Sink, typename ... Args>
9196 inline bool execQuery (StatementHandle st_handle,
@@ -96,11 +101,14 @@ namespace libp2p::storage {
96101 bindArgs (st, args...);
97102 st >> sink;
98103 return true ;
99- } catch (const std::runtime_error &e) {
104+ } catch (const std::invalid_argument &e) {
100105 // getStatement can receive invalid handle
101- log_->error (e.what ());
106+ log_->error (" Invalid statement handle: {}" , e.what ());
107+ throw ; // Re-throw invalid_argument as it's a programming error
108+ } catch (const std::runtime_error &e) {
109+ log_->error (" Runtime error during query execution: {}" , e.what ());
102110 } catch (...) {
103- log_->error (getErrorMessage ());
111+ log_->error (" Unknown error during query execution: {} " , getErrorMessage ());
104112 }
105113 return false ;
106114 }
@@ -121,6 +129,12 @@ namespace libp2p::storage {
121129 // / Returns the number of rows modified
122130 int countChanges () const ;
123131
132+ // / Returns the database file path
133+ const std::string &getDatabaseFile () const ;
134+
135+ // / Returns the number of prepared statements
136+ size_t getStatementCount () const ;
137+
124138 ::sqlite::database db_;
125139 std::string db_file_;
126140 log::Logger log_;
0 commit comments