Skip to content

Commit f9cc124

Browse files
committed
call error callback for each failed query
1 parent ef83f22 commit f9cc124

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/natives.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,25 @@ AMX_DECLARE_NATIVE(Native::mysql_tquery_file)
840840
return 0;
841841
}
842842

843-
auto func = [](Handle_t handle, string file_path, Callback_t callback)
843+
844+
std::function<void(std::string, unsigned int, std::string)> query_error_func
845+
= [amx, handle_id, callback_str]
846+
(string query_str, unsigned int errorid, string error)
847+
{
848+
CError<CCallback> error_cb_error;
849+
//forward OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle);
850+
Callback_t error_cb = CCallback::Create(error_cb_error, amx,
851+
"OnQueryError", "dsssd",
852+
errorid, error.c_str(),
853+
callback_str.c_str(),
854+
query_str.c_str(), handle_id);
855+
856+
if (!error_cb_error)
857+
error_cb->Execute();
858+
};
859+
860+
auto func = [](Handle_t handle, string file_path, Callback_t callback,
861+
decltype(query_error_func) query_error_func)
844862
{
845863
vector<string> queries;
846864
if (ParseQueriesFromFile(file_path, queries) && !queries.empty())
@@ -851,7 +869,8 @@ AMX_DECLARE_NATIVE(Native::mysql_tquery_file)
851869
auto results = std::make_shared<vector<ResultSet_t>>();
852870
for (auto i = queries.begin(); i != queries.end(); i++)
853871
{
854-
Query_t query = CQuery::Create(*i);
872+
string query_str = *i;
873+
Query_t query = CQuery::Create(query_str);
855874

856875
if (callback != nullptr)
857876
{
@@ -871,12 +890,15 @@ AMX_DECLARE_NATIVE(Native::mysql_tquery_file)
871890
}
872891
});
873892
}
893+
query->OnError(std::bind(query_error_func,
894+
query_str, std::placeholders::_1, std::placeholders::_2));
874895

875896
handle->Execute(CHandle::ExecutionType::THREADED, query);
876897
}
877898
}
878899
};
879-
std::async(std::launch::async, std::move(func), handle, filepath, callback);
900+
std::async(std::launch::async, std::move(func),
901+
handle, filepath, callback, query_error_func);
880902

881903

882904
CLog::Get()->LogNative(LogLevel::DEBUG, "return value: '1'");

0 commit comments

Comments
 (0)