Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32618706
D4826.1767461455.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D4826.1767461455.diff
View Options
diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
@@ -274,6 +274,33 @@
}
}
+void trace_queries(sqlite3 *db) {
+ int error_code = sqlite3_trace_v2(
+ db,
+ SQLITE_TRACE_PROFILE,
+ [](unsigned, void *, void *p, void *) {
+ sqlite3_stmt *s = (sqlite3_stmt *)p;
+ char *sql = sqlite3_expanded_sql(s);
+ if (sql != nullptr) {
+ std::string sqlStr(sql);
+ std::cout << "sql query detected: " << sqlStr << std::endl;
+ }
+ return 0;
+ },
+ NULL);
+ if (error_code != SQLITE_OK) {
+ std::ostringstream error_message;
+ error_message << "Failed to set trace callback, error code: " << error_code;
+ throw std::system_error(
+ ECANCELED, std::generic_category(), error_message.str());
+ }
+}
+
+void open_callback(sqlite3 *db) {
+ set_encryption_key(db);
+ trace_queries(db);
+}
+
bool file_exists(const std::string &file_path) {
std::ifstream file(file_path.c_str());
return file.good();
@@ -330,7 +357,7 @@
sqlite3 *db;
sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
- set_encryption_key(db);
+ open_callback(db);
char *key_validation_error;
// According to SQLCipher documentation running some SELECT is the only way to
// check for key validity
@@ -406,7 +433,7 @@
sqlite3 *db;
sqlite3_open(SQLiteQueryExecutor::sqliteFilePath.c_str(), &db);
- set_encryption_key(db);
+ open_callback(db);
std::stringstream db_path;
db_path << "db path: " << SQLiteQueryExecutor::sqliteFilePath.c_str()
@@ -513,7 +540,7 @@
"metadata",
make_column("name", &Metadata::name, unique(), primary_key()),
make_column("data", &Metadata::data)));
- storage.on_open = set_encryption_key;
+ storage.on_open = open_callback;
return storage;
}
@@ -553,7 +580,8 @@
void SQLiteQueryExecutor::updateDraft(std::string key, std::string text) const {
Draft draft = {key, text};
- SQLiteQueryExecutor::getStorage().replace(draft);
+ auto storage = SQLiteQueryExecutor::getStorage();
+ storage.replace(draft);
}
bool SQLiteQueryExecutor::moveDraft(std::string oldKey, std::string newKey)
@@ -564,8 +592,9 @@
return false;
}
draft->key = newKey;
- SQLiteQueryExecutor::getStorage().replace(*draft);
- SQLiteQueryExecutor::getStorage().remove<Draft>(oldKey);
+ auto storage = SQLiteQueryExecutor::getStorage();
+ storage.replace(*draft);
+ storage.remove<Draft>(oldKey);
return true;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 5:30 PM (5 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5889980
Default Alt Text
D4826.1767461455.diff (2 KB)
Attached To
Mode
D4826: [native] Trace sqlite queries
Attached
Detach File
Event Timeline
Log In to Comment