2020#include < unordered_map>
2121#include " protobuf/dictionary_data.pb.h"
2222#include < memory>
23-
23+ # include " libs/sqlite4java/include/sqlite3.h "
2424
2525
2626struct DictionaryContainer {
2727public:
28- std::shared_ptr<TranslationModel > toEnglishDict;
29- std::shared_ptr<TranslationModel > fromEnglishDict;
28+ std::shared_ptr<mydata::DataMap > toEnglishDict;
29+ std::shared_ptr<mydata::DataMap > fromEnglishDict;
3030
31- DictionaryContainer (std::shared_ptr<TranslationModel > toEnglishDict, std::shared_ptr<TranslationModel > fromEnglishDict){
31+ DictionaryContainer (std::shared_ptr<mydata::DataMap > toEnglishDict, std::shared_ptr<mydata::DataMap > fromEnglishDict){
3232 this ->toEnglishDict = toEnglishDict;
3333 this ->fromEnglishDict = fromEnglishDict;
3434 }
35- };
35+ };
36+
37+ bool getLinkData (const char * dbPath, const std::string& srcLang, const std::string& tgtLang) {
38+ sqlite3* db;
39+ sqlite3_stmt* stmt;
40+ bool success = false ;
41+
42+ if (sqlite3_open_v2 (dbPath, &db, SQLITE_OPEN_READONLY , NULL ) != SQLITE_OK ) {
43+ return false ;
44+ }
45+
46+ const char * sql = " SELECT data FROM links WHERE srcLang = ? AND tgtLang = ? LIMIT 1" ;
47+
48+ if (sqlite3_prepare_v2 (db, sql, -1 , &stmt, NULL ) == SQLITE_OK ) {
49+ // Bind arguments
50+ sqlite3_bind_text (stmt, 1 , srcLang.c_str (), -1 , SQLITE_TRANSIENT );
51+ sqlite3_bind_text (stmt, 2 , tgtLang.c_str (), -1 , SQLITE_TRANSIENT );
52+
53+ if (sqlite3_step (stmt) == SQLITE_ROW ) {
54+ // 1. Get pointer to the BLOB memory
55+ const void * blobPtr = sqlite3_column_blob (stmt, 0 );
56+
57+ // 2. Get the size of the BLOB in bytes
58+ int blobSize = sqlite3_column_bytes (stmt, 0 );
59+
60+ if (blobPtr != nullptr && blobSize > 0 ) {
61+ // Example: Parsing with Protobuf
62+ // LinksData::DataMap dataMap;
63+ // if (dataMap.ParseFromArray(blobPtr, blobSize)) {
64+ // success = true;
65+ // // Process your dataMap here...
66+ // }
67+
68+ // Example: Just copying into a vector if you don't have the proto class yet
69+ std::vector<uint8_t > buffer (static_cast <const uint8_t *>(blobPtr),
70+ static_cast <const uint8_t *>(blobPtr) + blobSize);
71+ success = true ;
72+ }
73+ }
74+ }
75+
76+ sqlite3_finalize (stmt);
77+ sqlite3_close (db);
78+ return success;
79+ }
0 commit comments