Skip to content

Commit 643e450

Browse files
committed
fix(database): Crashes
1 parent d636e42 commit 643e450

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

src/plugins/core/scripting/database.cpp

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include <deque>
44
#include <thread>
5-
#include <rapidjson/document.h>
6-
#include <rapidjson/writer.h>
7-
#include <rapidjson/stringbuffer.h>
5+
6+
#include <vector>
7+
#include <map>
88

99
std::string FetchPluginName(lua_State* state);
1010
#define FetchPluginByState(state) g_pluginManager->FetchPlugin(FetchPluginName(state))
@@ -39,45 +39,16 @@ void DatabaseQueryThread()
3939
if (queue.plugin->GetKind() == PluginKind_t::Lua)
4040
{
4141
lua_State* state = ((LuaPlugin*)queue.plugin)->GetState();
42-
luabridge::LuaRef tbl = luabridge::LuaRef::newTable(state);
42+
std::vector<std::map<std::string, luabridge::LuaRef>> tbl;
43+
4344
for (uint32_t i = 0; i < queryResult.size(); i++)
4445
{
45-
luabridge::LuaRef rowTbl = luabridge::LuaRef::newTable(state);
46+
std::map<std::string, luabridge::LuaRef> rowTbl;
4647

4748
for (std::map<const char*, std::any>::iterator it = queryResult[i].begin(); it != queryResult[i].end(); ++it)
48-
{
49-
const char* key = it->first;
50-
std::any value = it->second;
51-
52-
if (value.type() == typeid(const char*))
53-
rowTbl[key] = std::string(std::any_cast<const char*>(value));
54-
else if (value.type() == typeid(std::string))
55-
rowTbl[key] = std::any_cast<std::string>(value);
56-
else if (value.type() == typeid(uint64))
57-
rowTbl[key] = std::any_cast<uint64>(value);
58-
else if (value.type() == typeid(uint32))
59-
rowTbl[key] = std::any_cast<uint32>(value);
60-
else if (value.type() == typeid(uint16))
61-
rowTbl[key] = std::any_cast<uint16>(value);
62-
else if (value.type() == typeid(uint8))
63-
rowTbl[key] = std::any_cast<uint8>(value);
64-
else if (value.type() == typeid(int64))
65-
rowTbl[key] = std::any_cast<int64>(value);
66-
else if (value.type() == typeid(int32))
67-
rowTbl[key] = std::any_cast<int32>(value);
68-
else if (value.type() == typeid(int16))
69-
rowTbl[key] = std::any_cast<int16>(value);
70-
else if (value.type() == typeid(int8))
71-
rowTbl[key] = std::any_cast<int8>(value);
72-
else if (value.type() == typeid(bool))
73-
rowTbl[key] = std::any_cast<bool>(value);
74-
else if (value.type() == typeid(float))
75-
rowTbl[key] = std::any_cast<float>(value);
76-
else if (value.type() == typeid(double))
77-
rowTbl[key] = std::any_cast<double>(value);
78-
}
49+
rowTbl.insert({ it->first, LuaSerializeData(it->second, state) });
7950

80-
if (rowTbl.isTable()) tbl.append(rowTbl);
51+
tbl.push_back(rowTbl);
8152
}
8253

8354
luabridge::LuaRef ref = *(luabridge::LuaRef*)queue.callback;

0 commit comments

Comments
 (0)