MCPcopy Create free account
hub / github.com/anse1/sqlsmith / command

Method command

postgres.cc:358–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void dut_libpq::command(const std::string &stmt)
359{
360 if (!conn)
361 connect(conninfo_);
362 PGresult *res = PQexec(conn, stmt.c_str());
363
364 switch (PQresultStatus(res)) {
365
366 case PGRES_FATAL_ERROR:
367 default:
368 {
369 const char *errmsg = PQresultErrorMessage(res);
370 if (!errmsg || !strlen(errmsg))
371 errmsg = PQerrorMessage(conn);
372
373 const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
374 if (!sqlstate || !strlen(sqlstate))
375 sqlstate = (CONNECTION_OK != PQstatus(conn)) ? "08000" : "?????";
376
377 std::string error_string(errmsg);
378 std::string sqlstate_string(sqlstate);
379 PQclear(res);
380
381 if (CONNECTION_OK != PQstatus(conn)) {
382 PQfinish(conn);
383 conn = 0;
384 throw dut::broken(error_string.c_str(), sqlstate_string.c_str());
385 }
386 if (sqlstate_string == "42601")
387 throw dut::syntax(error_string.c_str(), sqlstate_string.c_str());
388 else
389 throw dut::failure(error_string.c_str(), sqlstate_string.c_str());
390 }
391
392 case PGRES_NONFATAL_ERROR:
393 case PGRES_TUPLES_OK:
394 case PGRES_SINGLE_TUPLE:
395 case PGRES_COMMAND_OK:
396 PQclear(res);
397 return;
398 }
399}
400
401void dut_libpq::test(const std::string &stmt)
402{

Callers

nothing calls this directly

Calls 3

brokenClass · 0.85
syntaxClass · 0.85
failureClass · 0.85

Tested by

no test coverage detected