fix: stabilize runtime follow-up regressions

This commit is contained in:
udo
2026-06-11 23:03:07 +00:00
parent 7f757654b6
commit 20db669589
37 changed files with 906 additions and 144 deletions
+29 -13
View File
@@ -3,16 +3,28 @@
#include <stdlib.h>
#include "mysql-connector.h"
static void mysql_register_request_connection(MySQL* db)
{
if(!context || !db)
return;
auto& connections = context->resources.mysql_connections;
if(std::find(connections.begin(), connections.end(), (void*)db) == connections.end())
connections.push_back(db);
}
bool MySQL::connect(String host, String username, String password)
{
// Register regardless of outcome: tracking is about the wrapper's
// lifetime, not the connection's. disconnect()/~MySQL() unregister.
mysql_register_request_connection(this);
//switch_to_system_alloc();
connection = mysql_init(NULL);
if (connection == NULL)
{
auto e = mysql_error((MYSQL*)connection);
fprintf(stderr, "%s\n", e);
fprintf(stderr, "mysql_init failed\n");
//switch_to_arena(context->mem);
statement_info.assign(e);
_preload_next_error_code = CR_OUT_OF_MEMORY;
statement_info = "mysql_init failed";
return(false);
}
@@ -21,9 +33,11 @@ bool MySQL::connect(String host, String username, String password)
{
auto e = mysql_error((MYSQL*)connection);
fprintf(stderr, "%s\n", e);
mysql_close((MYSQL*)connection);
//switch_to_arena(context->mem);
_preload_next_error_code = CR_UNKNOWN_ERROR;
statement_info.assign(e);
mysql_close((MYSQL*)connection);
connection = NULL;
//switch_to_arena(context->mem);
return(false);
}
@@ -37,8 +51,6 @@ bool MySQL::connect(String host, String username, String password)
*/
//switch_to_arena(context->mem);
statement_info = String("connected");
if(context)
context->resources.mysql_connections.push_back(this);
return(true);
}
@@ -192,6 +204,12 @@ DTree MySQL::query(String q)
statement_info = "mysql positional ? placeholders are not supported; use named :name placeholders";
return(DTree());
}
if(!connection)
{
_preload_next_error_code = CR_UNKNOWN_ERROR;
statement_info = "mysql connection is not open";
return(DTree());
}
_preload_next_error_code = mysql_query((MYSQL*)connection, q.c_str());
DTree result;
if(_preload_next_error_code == 0)
@@ -237,12 +255,8 @@ static bool mysql_has_unquoted_positional_placeholder(String query)
DTree MySQL::query(String q, StringMap params)
{
if(mysql_has_unquoted_positional_placeholder(q))
{
_preload_next_error_code = CR_UNKNOWN_ERROR;
statement_info = "mysql positional ? placeholders are not supported; use named :name placeholders";
return(DTree());
}
// Positional ? placeholders survive named substitution (values are always
// quoted by escape()), so the check in query(String) covers this path too.
return(query(
parse_query_parameters(q, params).c_str()
));
@@ -347,6 +361,8 @@ String MySQL::error()
_preload_next_error_code = 0;
return(p);
}
if(!connection)
return("");
const char* res = mysql_error((MYSQL*)connection);
if(res)
{