From d30ea565307b1db5068a383cf32ea3454c123332 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 10 Sep 2024 00:40:32 +0300 Subject: [PATCH] return sqlite3 status int for save and prepare methods --- src/app/browser/main/tab.cpp | 77 ++++++++++++++++++++---------------- src/app/browser/main/tab.hpp | 4 +- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/app/browser/main/tab.cpp b/src/app/browser/main/tab.cpp index b6f66b3e..32dbb3e1 100644 --- a/src/app/browser/main/tab.cpp +++ b/src/app/browser/main/tab.cpp @@ -66,11 +66,11 @@ Tab::Tab( ); } -void Tab::session_restore() +int Tab::session_restore() { sqlite3_stmt* statement; - const int PREPARE = ::sqlite3_prepare_v3( + const int PREPARE_STATUS = ::sqlite3_prepare_v3( this->db, R"SQL( SELECT * FROM `app_browser_main_tab__session` ORDER BY `number` ASC @@ -81,7 +81,7 @@ void Tab::session_restore() nullptr ); - if (PREPARE == SQLITE_OK) + if (PREPARE_STATUS == SQLITE_OK) { close_all(); @@ -109,17 +109,19 @@ void Tab::session_restore() } } - sqlite3_finalize( + ::sqlite3_finalize( statement ); + + return PREPARE_STATUS; } -void Tab::session_save() +int Tab::session_save() { char * error; // @TODO // Delete previous tab session - ::sqlite3_exec( + const int EXEC_STATUS = ::sqlite3_exec( db, R"SQL( DELETE FROM `app_browser_main_tab__session` @@ -129,38 +131,43 @@ void Tab::session_save() &error ); - // Save current tab session - for (int page_number = 0; page_number < get_n_pages(); page_number++) + if (EXEC_STATUS == SQLITE_OK) { - auto tabPage = get_tabPage( - page_number - ); + // Save current tab session + for (int page_number = 0; page_number < get_n_pages(); page_number++) + { + auto tabPage = get_tabPage( + page_number + ); - ::sqlite3_exec( - db, - Glib::ustring::sprintf( - R"SQL( - INSERT INTO `app_browser_main_tab__session` ( - `time`, - `number`, - `current`, - `request` - ) VALUES ( - CURRENT_TIMESTAMP, - '%d', - '%d', - '%s' - ) - )SQL", - page_number, - page_number == get_current_page() ? 1 : 0, - tabPage->get_navigation_request_text() - ).c_str(), - nullptr, - nullptr, - &error - ); + ::sqlite3_exec( + db, + Glib::ustring::sprintf( + R"SQL( + INSERT INTO `app_browser_main_tab__session` ( + `time`, + `number`, + `current`, + `request` + ) VALUES ( + CURRENT_TIMESTAMP, + '%d', + '%d', + '%s' + ) + )SQL", + page_number, + page_number == get_current_page() ? 1 : 0, + tabPage->get_navigation_request_text() + ).c_str(), + nullptr, + nullptr, + &error + ); + } } + + return EXEC_STATUS; } void Tab::shutdown() diff --git a/src/app/browser/main/tab.hpp b/src/app/browser/main/tab.hpp index 8d4805c4..b45b89d3 100644 --- a/src/app/browser/main/tab.hpp +++ b/src/app/browser/main/tab.hpp @@ -94,8 +94,8 @@ namespace app::browser::main const int & PAGE_NUMBER ); - void session_restore(); - void session_save(); + int session_restore(); + int session_save(); void shutdown();