c++ - Function causes mysql_close() to leave connection thread open -
The work given below was found to be responsible for a heavy connection leakage, because each thread passes the cone as the parameter The connection was uncharted.
Work all the queries as expected, just the mysql_close ()
function can not stop the connection thread.
This function is fine and I do not remember to change anything since finally working. Just the project was changed where it was used and there were some compiler flags.
I read it in:
mysql_close () Deals the connection handle is indicated by mysql if mysql_init () handle Was allocated automatically by mysql_connect ().
But do not understand, and do not know how to test.
int mysql_get_item_id (MYSQL * conn, const char * item_e, const unscripted long * ip_nr, bool * is_new_item = NULL) {char ip_nr_string [10]; Std :: sprintf (ip_nr_string, "% lu", * ip_nr); String query = "SELECT id FROM item_unique WHERE item = '" + (string) item_e + "' LIMIT 1 '; if (mysql_real_query (conn, & query [0], query.size ())) {cout & lt; end L << mysql_get_item_id - & gt; Query failed: & lt; "& Gt; & gt;" & Lt; & Lt; Endl; Fprintf (stderr, "% s \ n", mysql_error (conn)); Return 0; } And if (DEBUG_QUERY & gt; 2) {cout & lt; & Lt; "Debug_query"> 0) {if ((line = mysql_fetch_row (result)) = = faucet} {if (line [0]! = NULL) {long l = atoi (row [0]); Mysql_free_result (results); Returns L; }}} // if no! = NULL entered query = "item_unique (item, host_ip_nr) VALUES (enter 'IGNORE' ('+ string ()' item_e +" ',' + (string ip_nr_string + "'); if (mysql_real_query (conn, & query [0] ], Query.size ())) {cout "mysql_get_item_id -> Query failed: & lt; "& Gt; & gt;" & Lt; & Lt; Endl; Fprintf (stderr, "% s \ n", mysql_error (conn)); Return 0; } And if (DEBUG_QUERY & gt; 2) {cout & lt; & Lt; "Debug_query"> 0) {if (n_new_item! = NULL) * is_new_item = TRUE; Return mysql_insert_id (conn); } And {return 0; } Return 0; }
Comments
Post a Comment