mirror of
https://github.com/ttttupup/wxhelper.git
synced 2024-11-22 10:19:23 +08:00
feat: 新增数据库查询
This commit is contained in:
parent
7ab8d4733f
commit
9b643901cd
100
doc/3.9.5.81.md
100
doc/3.9.5.81.md
@ -374,4 +374,104 @@ enableHttp=0时,使用ip,port的tcp服务回传消息。
|
||||
],
|
||||
"msg":"success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 7.查询数据库**
|
||||
###### 接口功能
|
||||
> 查询数据库
|
||||
|
||||
###### 接口地址
|
||||
> [/api/execSql](/api/execSql)
|
||||
|
||||
###### HTTP请求方式
|
||||
> POST JSON
|
||||
|
||||
###### 请求参数
|
||||
|参数|必选|类型|说明|
|
||||
|---|---|---|---|
|
||||
|dbHandle |true |number| |
|
||||
|sql |true |string| 执行的sql |
|
||||
|
||||
###### 返回字段
|
||||
|返回字段|字段类型|说明 |
|
||||
|---|---|---|
|
||||
|code|int|返回状态,0成功, 非0失败|
|
||||
|msg|string|返回信息|
|
||||
|data|array|sqlite返回的结果|
|
||||
|
||||
|
||||
|
||||
###### 接口示例
|
||||
入参:
|
||||
``` javascript
|
||||
{
|
||||
"dbHandle":2006119800400,
|
||||
"sql":"select * from MSG where localId =301;"
|
||||
}
|
||||
```
|
||||
响应:
|
||||
``` javascript
|
||||
{
|
||||
"code": 1,
|
||||
"data": [
|
||||
[
|
||||
"localId",
|
||||
"TalkerId",
|
||||
"MsgSvrID",
|
||||
"Type",
|
||||
"SubType",
|
||||
"IsSender",
|
||||
"CreateTime",
|
||||
"Sequence",
|
||||
"StatusEx",
|
||||
"FlagEx",
|
||||
"Status",
|
||||
"MsgServerSeq",
|
||||
"MsgSequence",
|
||||
"StrTalker",
|
||||
"StrContent",
|
||||
"DisplayContent",
|
||||
"Reserved0",
|
||||
"Reserved1",
|
||||
"Reserved2",
|
||||
"Reserved3",
|
||||
"Reserved4",
|
||||
"Reserved5",
|
||||
"Reserved6",
|
||||
"CompressContent",
|
||||
"BytesExtra",
|
||||
"BytesTrans"
|
||||
],
|
||||
[
|
||||
"301",
|
||||
"1",
|
||||
"8824834301214701891",
|
||||
"1",
|
||||
"0",
|
||||
"0",
|
||||
"1685401473",
|
||||
"1685401473000",
|
||||
"0",
|
||||
"0",
|
||||
"2",
|
||||
"1",
|
||||
"795781866",
|
||||
"wxid_123",
|
||||
"testtest",
|
||||
"",
|
||||
"0",
|
||||
"2",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"CgQIEBAAGo0BCAcSiAE8bXNnc291cmNlPJPHNpZ25hdHVyZT52MV9wd12bTZyRzwvc2lnbmF0dXJPgoJPHRtcF9ub2RlPgoJCTxwsaXNoZXItaWQ+Jmx0OyFbQ0RBVEFbXV0mZ3Q7PC9wdWJsaXNoZXItaWQ+Cgk8L3RtcF9ub2RlPgo8L21zZ3NvdXJjZT4KGiQIAhIgNDE1MDA0NjRhZTRmMjk2NjhjMzY2ZjFkOTdmMjAwNDg=",
|
||||
""
|
||||
]
|
||||
],
|
||||
"msg": "success"
|
||||
}
|
||||
```
|
@ -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 =
|
||||
|
@ -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"}};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user