Page MenuHomePhorge

D14517.1768803233.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D14517.1768803233.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
@@ -51,6 +51,10 @@
processMessagesResults(SQLiteStatementWrapper &preparedSQL) const;
std::string getThickThreadTypesList() const;
std::vector<std::string> getAllTableNames(sqlite3 *db) const;
+ void copyTablesDataUsingAttach(
+ sqlite3 *db,
+ const std::string &sourceDbPath,
+ const std::vector<std::string> &tableNames) const;
public:
static std::string sqliteFilePath;
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
@@ -3296,6 +3296,28 @@
}
#endif
+void SQLiteQueryExecutor::copyTablesDataUsingAttach(
+ sqlite3 *db,
+ const std::string &sourceDbPath,
+ const std::vector<std::string> &tableNames) const {
+ if (!file_exists(sourceDbPath)) {
+ std::stringstream errorMessage;
+ errorMessage << "Error: File does not exist at path: " << sourceDbPath
+ << std::endl;
+ Logger::log(errorMessage.str());
+ throw std::runtime_error(errorMessage.str());
+ }
+
+ std::ostringstream sql;
+ sql << "ATTACH DATABASE '" << sourceDbPath << "' AS sourceDB KEY '';";
+ for (const auto &tableName : tableNames) {
+ sql << "INSERT OR IGNORE INTO " << tableName << " SELECT *"
+ << " FROM sourceDB." << tableName << ";" << std::endl;
+ }
+ sql << "DETACH DATABASE sourceDB;";
+ executeQuery(db, sql.str());
+}
+
void SQLiteQueryExecutor::restoreFromMainCompaction(
std::string mainCompactionPath,
std::string mainCompactionEncryptionKey,

File Metadata

Mime Type
text/plain
Expires
Mon, Jan 19, 6:13 AM (12 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5954762
Default Alt Text
D14517.1768803233.diff (1 KB)

Event Timeline