c++ - MySQL server-side timeout -
i have connection code causes timeout when queries take long. connection options setup (timeout
integer):
sql::connectoptionsmap com; com["hostname"] = url; // string com["username"] = user; // string com["password"] = pwd; // string com["opt_reconnect"] = true; com["opt_read_timeout"] = timeout; // 1 (second) com["opt_write_timeout"] = timeout; // 1 (second)
after testing timeout setup above found throw occur mysql continues trying execute query. in other words, below try
goes catch
after configured timeout error code 2013 doesn't stop mysql trying execute query (2013 error code related lost connection):
// other code try { stmt = con->createstatement(); stmt->execute("drop database if exists mysqlmanagertest_timeoutread"); stmt->execute("create database mysqlmanagertest_timeoutread"); stmt->execute("use mysqlmanagertest_timeoutread"); stmt->execute("create table foo (bar int)"); (int = 0; < 100; i++) stmt->execute("insert foo (bar) values (" + lc(i) + ")"); // bit of playing needed in loop condition // make longer second not long // using 10000 seems take 5 seconds stmt->execute( "create function waitawhile() " "returns int reads sql data " "begin " "declare baz int default 0; " "while baz < 10000 " "set baz = baz + 1; " "end while; " "return baz; " "end;" ); res = stmt->executequery("select 1 foo bar = waitawhile()"); } catch (sql::sqlexception &e) { std::cout << e.geterrorcode() << std::endl; } // other code
i able notice mysql did not stop running "top" @ same time above testing code. making above mysql waitawhile()
function instead infinite loop further confirmed mysql not stopping because had kill mysql process make stop
this kind of timeout not wanted, wanted mysql give on query if took long. can done (so both execution , mysql stop doing work)? additionally, can specified insert queries?
you can in regular sql having sql server set max query execution time. however, doesn't mysql supports this; see following accepted answer more details: mysql - can limit maximum time allowed query run?
Comments
Post a Comment