Skip to content

Commit e2277ee

Browse files
[SDK 669] Fixed bug in deleting events locally (#49)
* Fix no event printing error * change log and sdk version updated * change log updated and sdk version * cpp-codeql * removed code analysis * Adding a comment * Update CHANGELOG.md Co-authored-by: ArtursKadikis <[email protected]>
1 parent c78340c commit e2277ee

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
21.11.2
2+
* Fixed a bug that occured after trying to erase events from the sqlite database when there were none.
3+
14
21.11.1
25
* !! Major breaking change !! Fixed a bug that triggered when providing segmentation to the "RecordEvent" call. Previously, by mistake, every segmentation value was parsed as a JSON and threw an exception when it wasn't a valid JSON string. Now this will not be the case and every String value can be provided. This is marked as a "major breaking change" in case some integrations were adding workarounds to this issue.
36
* ! Minor breaking change ! Default automatic session update duration changed to 60 seconds.

include/countly.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using json = nlohmann::json;
2121

2222
#define COUNTLY_SDK_NAME "cpp-native-unknown"
2323
#define COUNTLY_SDK_VERSION "0.1.0"
24-
#define COUNTLY_API_VERSION "21.11.1"
24+
#define COUNTLY_API_VERSION "21.11.2"
2525
#define COUNTLY_POST_THRESHOLD 2000
2626
#define COUNTLY_KEEPALIVE_INTERVAL 3000
2727
#define COUNTLY_MAX_EVENTS_DEFAULT 200

src/countly.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -685,19 +685,22 @@ bool Countly::updateSession() {
685685
#ifndef COUNTLY_USE_SQLITE
686686
event_queue.clear();
687687
#else
688-
return_value = sqlite3_open(database_path.c_str(), &database);
689-
if (return_value == SQLITE_OK) {
690-
std::ostringstream sql_statement_stream;
691-
sql_statement_stream << "DELETE FROM events WHERE evtid IN " << event_ids << ';';
692-
std::string sql_statement = sql_statement_stream.str();
688+
if (!event_ids.empty()) {
689+
//we attempt to clear the events in the database only if there were any events collected previously
690+
return_value = sqlite3_open(database_path.c_str(), &database);
691+
if (return_value == SQLITE_OK) {
692+
std::ostringstream sql_statement_stream;
693+
sql_statement_stream << "DELETE FROM events WHERE evtid IN " << event_ids << ';';
694+
std::string sql_statement = sql_statement_stream.str();
693695

694-
return_value = sqlite3_exec(database, sql_statement.c_str(), nullptr, nullptr, &error_message);
695-
if (return_value != SQLITE_OK) {
696-
log(Countly::LogLevel::ERROR, error_message);
697-
sqlite3_free(error_message);
696+
return_value = sqlite3_exec(database, sql_statement.c_str(), nullptr, nullptr, &error_message);
697+
if (return_value != SQLITE_OK) {
698+
log(Countly::LogLevel::ERROR, error_message);
699+
sqlite3_free(error_message);
700+
}
698701
}
702+
sqlite3_close(database);
699703
}
700-
sqlite3_close(database);
701704
#endif
702705

703706
mutex.unlock();

0 commit comments

Comments
 (0)