| 192 | } |
| 193 | |
| 194 | void dut_monetdb::test(const std::string &stmt) |
| 195 | { |
| 196 | MapiHdl hdl = mapi_query(dbh,"CALL sys.settimeout(1)"); |
| 197 | mapi_close_handle(hdl); |
| 198 | hdl = mapi_query(dbh,stmt.c_str()); |
| 199 | |
| 200 | if (mapi_error(dbh)!=MOK) { |
| 201 | |
| 202 | try { |
| 203 | const char *error_string = mapi_result_error(hdl); |
| 204 | |
| 205 | if (!error_string) |
| 206 | error_string = "unknown error"; |
| 207 | |
| 208 | const char *sqlstate = mapi_result_errorcode(hdl); |
| 209 | if (!sqlstate) |
| 210 | sqlstate = "XXXXX"; |
| 211 | |
| 212 | /* monetdb appears to report sqlstate 42000 for all |
| 213 | errors, so we need to match the error string to |
| 214 | figure out actual syntax errors */ |
| 215 | |
| 216 | static regex re_syntax("^syntax error,.*", regex::extended); |
| 217 | |
| 218 | if (mapi_error(dbh)==MERROR) |
| 219 | throw dut::syntax(error_string, sqlstate); |
| 220 | else if (mapi_error(dbh)==MTIMEOUT) |
| 221 | throw dut::timeout(error_string, sqlstate); |
| 222 | else if (regex_match(error_string, re_syntax)) |
| 223 | throw dut::syntax(error_string, sqlstate); |
| 224 | else |
| 225 | throw dut::failure(error_string, sqlstate); |
| 226 | |
| 227 | } catch (dut::failure &e) { |
| 228 | mapi_close_handle(hdl); |
| 229 | throw; |
| 230 | } |
| 231 | } |
| 232 | mapi_close_handle(hdl); |
| 233 | } |