Impl execute sql
This commit is contained in:
@@ -212,6 +212,27 @@ PPRpcTables RpcGetDbTables(const wchar_t *db, int *pNum)
|
||||
return ppRpcTables;
|
||||
}
|
||||
|
||||
PPPRpcSqlResult RpcExecDbQuery(const wchar_t *db, const wchar_t *sql, int *pRow, int *pCol)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned long ulCode = 0;
|
||||
PPPRpcSqlResult pppRpcSqlResult = NULL;
|
||||
|
||||
RpcTryExcept { ret = client_ExecDbQuery(db, sql, pRow, pCol, &pppRpcSqlResult); }
|
||||
RpcExcept(1)
|
||||
{
|
||||
ulCode = RpcExceptionCode();
|
||||
printf("RpcExecDbQuery exception 0x%lx = %ld\n", ulCode, ulCode);
|
||||
}
|
||||
RpcEndExcept;
|
||||
if (ret != 0) {
|
||||
printf("RpcExecDbQuery Failed: %d\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pppRpcSqlResult;
|
||||
}
|
||||
|
||||
int server_ReceiveMsg(RpcMessage_t rpcMsg)
|
||||
{
|
||||
WxMessage_t msg;
|
||||
|
||||
@@ -14,3 +14,4 @@ PPRpcIntBstrPair RpcGetMsgTypes(int *pNum);
|
||||
PPRpcContact RpcGetContacts(int *pNum);
|
||||
BSTR *RpcGetDbNames(int *pNum);
|
||||
PPRpcTables RpcGetDbTables(const wchar_t *db, int *pNum);
|
||||
PPPRpcSqlResult RpcExecDbQuery(const wchar_t *db, const wchar_t *sql, int *row, int *col);
|
||||
|
||||
+25
@@ -237,3 +237,28 @@ DbTableVector_t WxGetDbTables(wstring db)
|
||||
|
||||
return vTables;
|
||||
}
|
||||
|
||||
SqlRetVector_t WxExecDbQuery(wstring db, wstring sql)
|
||||
{
|
||||
int row, col = 0;
|
||||
PPPRpcSqlResult ppp = RpcExecDbQuery(db.c_str(), sql.c_str(), &row, &col);
|
||||
vector<vector<WxSqlResult_t>> vvResults;
|
||||
for (int r = 0; r < row; r++) {
|
||||
vector<WxSqlResult_t> vResult;
|
||||
for (int c = 0; c < col; c++) {
|
||||
WxSqlResult_t result = { 0 };
|
||||
result.type = ppp[r][c]->type;
|
||||
result.column = GetWstringFromBstr(ppp[r][c]->column);
|
||||
result.content = GetBytesFromBstr(ppp[r][c]->content);
|
||||
vResult.push_back(result);
|
||||
midl_user_free(ppp[r][c]);
|
||||
}
|
||||
vvResults.push_back(vResult);
|
||||
midl_user_free(ppp[r]);
|
||||
}
|
||||
if (ppp) {
|
||||
midl_user_free(ppp);
|
||||
}
|
||||
|
||||
return vvResults;
|
||||
}
|
||||
|
||||
+2
-1
@@ -8,4 +8,5 @@
|
||||
WxSendImageMsg
|
||||
WxGetContacts
|
||||
WxGetDbNames
|
||||
WxGetDbTables
|
||||
WxGetDbTables
|
||||
WxExecDbQuery
|
||||
|
||||
@@ -33,9 +33,16 @@ typedef struct WxDbTable {
|
||||
wstring sql; // 建表 SQL
|
||||
} WxDbTable_t;
|
||||
|
||||
typedef struct WxSqlResult {
|
||||
int type;
|
||||
wstring column;
|
||||
string content;
|
||||
} WxSqlResult_t;
|
||||
|
||||
typedef map<int, wstring> MsgTypesMap_t;
|
||||
typedef map<wstring, WxContact_t> ContactMap_t;
|
||||
typedef vector<WxDbTable_t> DbTableVector_t;
|
||||
typedef vector<vector<WxSqlResult_t>> SqlRetVector_t;
|
||||
|
||||
int WxInitSDK();
|
||||
int WxDestroySDK();
|
||||
@@ -47,3 +54,4 @@ ContactMap_t WxGetContacts();
|
||||
MsgTypesMap_t WxGetMsgTypes();
|
||||
vector<wstring> WxGetDbNames();
|
||||
DbTableVector_t WxGetDbTables(wstring db);
|
||||
SqlRetVector_t WxExecDbQuery(wstring db, wstring sql);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Shlwapi.h"
|
||||
#include "framework.h"
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string.h>
|
||||
#include <strsafe.h>
|
||||
#include <tlhelp32.h>
|
||||
@@ -12,6 +14,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static wstring_convert<codecvt_utf8<wchar_t>, wchar_t> S_WS_Converter;
|
||||
|
||||
wstring String2Wstring(string s) { return S_WS_Converter.from_bytes(s); }
|
||||
string Wstring2String(wstring ws) { return S_WS_Converter.to_bytes(ws); }
|
||||
|
||||
static int GetWeChatPath(wchar_t *path)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -221,6 +228,44 @@ BSTR GetBstrFromWstring(wstring ws)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BSTR GetBstrFromStringBuffer(const char *str, int length)
|
||||
{
|
||||
int wslen = MultiByteToWideChar(CP_ACP, 0, str, length, 0, 0);
|
||||
BSTR bstr = SysAllocStringLen(0, wslen);
|
||||
MultiByteToWideChar(CP_ACP, 0, str, length, bstr, wslen);
|
||||
|
||||
return bstr;
|
||||
}
|
||||
|
||||
BSTR GetBstrFromByteArray(const byte *b, int len)
|
||||
{
|
||||
BSTR bstr = SysAllocStringLen(0, len);
|
||||
if (bstr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy((byte *)bstr, b, len);
|
||||
|
||||
return bstr;
|
||||
}
|
||||
|
||||
string GetBytesFromBstr(BSTR bstr)
|
||||
{
|
||||
string s = "";
|
||||
if (bstr) {
|
||||
int len = SysStringByteLen(bstr) / 2;
|
||||
char *tmp = new char[len];
|
||||
char *p = (char *)bstr;
|
||||
for (int i = 0; i < len; i++) {
|
||||
tmp[i] = p[i];
|
||||
}
|
||||
SysFreeString(bstr);
|
||||
s = string(tmp, len);
|
||||
delete[] tmp;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void GetRpcMessage(WxMessage_t *wxMsg, RpcMessage_t rpcMsg)
|
||||
{
|
||||
wxMsg->self = rpcMsg.self;
|
||||
|
||||
+7
-2
@@ -17,10 +17,15 @@
|
||||
int OpenWeChat(DWORD *pid);
|
||||
int GetWeChatVersion(wchar_t *version);
|
||||
int GetWstringByAddress(DWORD address, wchar_t *buffer, DWORD buffer_size);
|
||||
BSTR GetBstrByAddress(DWORD address);
|
||||
void GetRpcMessage(WxMessage_t *wxMsg, RpcMessage_t rpcMsg);
|
||||
DWORD GetMemoryIntByAddress(HANDLE hProcess, DWORD address);
|
||||
std::wstring GetWstringFromBstr(BSTR p);
|
||||
BSTR GetBstrByAddress(DWORD address);
|
||||
BSTR GetBstrFromString(const char *str);
|
||||
BSTR GetBstrFromWstring(std::wstring ws);
|
||||
BSTR GetBstrFromByteArray(const byte *b, int len);
|
||||
BSTR GetBstrFromStringBuffer(const char *str, int length);
|
||||
std::string GetBytesFromBstr(BSTR bstr);
|
||||
std::wstring GetWstringFromBstr(BSTR bstr);
|
||||
std::wstring GetUnicodeInfoByAddress(HANDLE hProcess, DWORD address);
|
||||
std::wstring String2Wstring(std::string s);
|
||||
std::string Wstring2String(std::wstring ws);
|
||||
|
||||
Reference in New Issue
Block a user