feat: 新增数据库查询

This commit is contained in:
hugy
2023-07-04 17:17:01 +08:00
parent 7ab8d4733f
commit 9b643901cd
4 changed files with 140 additions and 3 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ void FreeResult(std::vector<std::vector<common::SqlResult>> &data) {
int DB::SelectDataInner(UINT64 db, const char *sql,
std::vector<std::vector<common::SqlResult>> &data) {
common::sqlite3_prepare p_sqlite3_prepare =
(common::sqlite3_prepare)(this->base_addr_ + offset::k_sqlite3_prepare);
(common::sqlite3_prepare)(base_addr_ + offset::k_sqlite3_prepare);
common::sqlite3_step p_sqlite3_step =
(common::sqlite3_step)(base_addr_ + offset::k_sqlite3_step);
common::sqlite3_column_count p_sqlite3_column_count =
+38
View File
@@ -5,9 +5,26 @@
#include "global_context.h"
#include "hooks.h"
#include "db.h"
#define STR2LL(str) (wxhelper::Utils::IsDigit(str) ? stoll(str) : 0)
namespace common = wxhelper::common;
INT64 GetINT64Param(nlohmann::json data, std::string key) {
INT64 result;
try {
result = data[key].get<INT64>();
} catch (nlohmann::json::exception) {
result = STR2LL(data[key].get<std::string>());
}
return result;
}
std::string GetStringParam(nlohmann::json data, std::string key) {
return data[key].get<std::string>();
}
std::wstring GetWStringParam(nlohmann::json data, std::string key) {
return wxhelper::Utils::UTF8ToWstring(data[key].get<std::string>());
}
@@ -210,6 +227,27 @@ std::string HttpDispatch(struct mg_connection *c, struct mg_http_message *hm) {
ret_data["msg"] = "success";
ret = ret_data.dump();
return ret;
} else if (mg_http_match_uri(hm, "/api/execSql")) {
UINT64 db_handle = GetINT64Param(j_param, "dbHandle");
std::string sql = GetStringParam(j_param, "sql");
std::vector<std::vector<std::string>> items;
int success = wxhelper::DB::GetInstance().Select(db_handle, sql.c_str(), items);
nlohmann::json ret_data = {
{"data", nlohmann::json::array()}, {"code", success}, {"msg", "success"}};
if (success == 0) {
ret_data["msg"] = "no data";
ret = ret_data.dump();
return ret;
}
for (auto it : items) {
nlohmann::json temp_arr = nlohmann::json::array();
for (size_t i = 0; i < it.size(); i++) {
temp_arr.push_back(it[i]);
}
ret_data["data"].push_back(temp_arr);
}
ret = ret_data.dump();
return ret;
} else {
nlohmann::json ret_data = {
{"code", 200}, {"data", {}}, {"msg", "not support url"}};
+1 -2
View File
@@ -247,7 +247,7 @@ const UINT64 k_sqlite3_backup_init= 0x24e8450;
const UINT64 k_sqlite3_errcode = 0x256bfb0;
const UINT64 k_sqlite3_close = 0x256a110;
const UINT64 k_sqlite3_step = 0x24f2350;
const UINT64 k_sqlite3_column_count = 0x1df3c80;
const UINT64 k_sqlite3_column_count = 0x24f2b70;
const UINT64 k_sqlite3_column_name = 0x24f3570;
const UINT64 k_sqlite3_column_type = 0x24f33c0;
const UINT64 k_sqlite3_column_blob = 0x24f2ba0;
@@ -268,7 +268,6 @@ const UINT64 kStorageEnd= 0x0;
const UINT64 kMultiDBMgr= 0x3acfb68;
const UINT64 kPublicMsgMgr= 0x3acc268;
const UINT64 kFavoriteStorageMgr= 0x3acf0d0;
const UINT64 kFTSFavoriteMgr= 0x24f1400;
} // namespace offset
} // namespace V3_9_5_81