MCPcopy Create free account
hub / github.com/aixed/WeChat-Hook / execute

Method execute

xdb/db_mgr.cpp:52–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 }
51
52 nlohmann::ordered_json DatabaseMgr::execute(sqlite3* db, const std::string& sql)
53 {
54 nlohmann::ordered_json rdata = { {"status",0},{"desc",""} };
55 if (db == nullptr) {
56 rdata["status"] = -1;
57 rdata["desc"] = "input db handle is nullptr";
58 return rdata;
59 }
60 sqlite3_stmt* stmt = nullptr;
61 int rc = m_sqlite3Rountines->prepare((LPVOID)db, sql.c_str(), -1, &stmt, 0);
62 if (rc != SQLITE_OK) {
63 rdata["status"] = rc;
64 rdata["desc"] = format_string("execute %s failed", "sqlite3_prepare");
65 return rdata;
66 }
67 nlohmann::ordered_json items = nlohmann::ordered_json::array();
68 while (m_sqlite3Rountines->step(stmt) == SQLITE_ROW)
69 {
70 int col_count = m_sqlite3Rountines->column_count(stmt);
71 nlohmann::ordered_json item;
72 for (int i = 0; i < col_count; i++)
73 {
74 const char* ColName = m_sqlite3Rountines->column_name(stmt, i);
75 int nType = m_sqlite3Rountines->column_type(stmt, i);
76 const void* pReadBlobData = m_sqlite3Rountines->column_blob(stmt, i);
77 int nLength = m_sqlite3Rountines->column_bytes(stmt, i);
78 std::string key(ColName);
79 std::string value;
80 switch (nType)
81 {
82 case SQLITE_BLOB:
83 {
84 value = toHexString(std::string((char*)pReadBlobData, nLength));
85 break;
86 }
87 default:
88 {
89 value = std::string((char*)pReadBlobData, nLength);
90 break;
91 }
92 }
93 item[key] = value;
94 }
95 items.push_back(item);
96 }
97 m_sqlite3Rountines->finalize(stmt);
98 rdata["data"] = items;
99 return rdata;
100 }
101
102 nlohmann::ordered_json DatabaseMgr::execute(const std::string& dbname, const std::string& sql)
103 {

Callers 1

Route_QueryDBFunction · 0.80

Calls 3

format_stringFunction · 0.85
toHexStringFunction · 0.85
stringFunction · 0.50

Tested by

no test coverage detected