diff --git a/site/tests/services.uce b/site/tests/services.uce index c8a5ee0..a59b2bf 100644 --- a/site/tests/services.uce +++ b/site/tests/services.uce @@ -115,6 +115,15 @@ RENDER(Request& context) parsed_underscore.find("'Ada'") != String::npos && parsed_underscore.find("_name") == String::npos ? "pass" : "fail", parsed_underscore ); + MySQL unavailable_mysql; + unavailable_mysql.connect("127.0.0.1", "__uce_intentionally_missing__", "not-a-real-password"); + unavailable_mysql.query("SELECT 1"); + String unavailable_mysql_error = unavailable_mysql.error(); + mark( + "mysql query after failed connect retains the connection error", + unavailable_mysql_error != "" ? "pass" : "fail", + unavailable_mysql_error + ); MySQL mysql; mysql.connect("127.0.0.1", "root", ""); diff --git a/src/lib/mysql-connector.cpp b/src/lib/mysql-connector.cpp index 31c6873..34bd542 100644 --- a/src/lib/mysql-connector.cpp +++ b/src/lib/mysql-connector.cpp @@ -226,8 +226,10 @@ DValue MySQL::query(String q) } if(!connection) { - _preload_next_error_code = CR_UNKNOWN_ERROR; - statement_info = "mysql connection is not open"; + if(_preload_next_error_code == 0) + _preload_next_error_code = CR_UNKNOWN_ERROR; + if(statement_info == "") + statement_info = "mysql connection is not open"; return(DValue()); } _preload_next_error_code = mysql_query((MYSQL*)connection, q.c_str()); diff --git a/src/wasm/core.cpp b/src/wasm/core.cpp index 7c9c563..ce37190 100644 --- a/src/wasm/core.cpp +++ b/src/wasm/core.cpp @@ -287,6 +287,14 @@ DValue MySQL::query(String q) statement_info = "mysql positional ? placeholders are not supported; use named :name placeholders"; return(DValue()); } + if(!connection) + { + if(_preload_next_error_code == 0) + _preload_next_error_code = 2000; + if(statement_info == "") + statement_info = "mysql connection is not open"; + return(DValue()); + } DValue request; request["op"] = "query"; request["handle"] = (f64)(uintptr_t)connection;