2
* Tests for error diagnostics (SQLGetDiagRec)
10
int main(int argc, char **argv)
13
HSTMT hstmt = SQL_NULL_HSTMT;
14
HSTMT hstmt2 = SQL_NULL_HSTMT;
24
rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
25
if (!SQL_SUCCEEDED(rc))
27
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
32
* Execute an erroneous query, and call SQLGetDiagRec twice on the
33
* statement. Should get the same result both times; SQLGetDiagRec is
34
* not supposed to change the state of the statement.
36
rc = SQLExecDirect(hstmt, (SQLCHAR *) "broken query ", SQL_NTS);
37
print_diag("SQLExecDirect", SQL_HANDLE_STMT, hstmt);
38
print_diag("get same message again", SQL_HANDLE_STMT, hstmt);
40
rc = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_ROLLBACK);
41
CHECK_STMT_RESULT(rc, "SQLEndTran failed", hstmt);
43
rc = SQLFreeStmt(hstmt, SQL_DROP);
44
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
46
/* kill this connection */
47
printf ("killing connection...\n");
48
rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
49
if (!SQL_SUCCEEDED(rc))
51
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
55
rc = SQLExecDirect(hstmt, (SQLCHAR *) "select pg_terminate_backend(pg_backend_pid()) ", SQL_NTS);
56
print_diag(NULL, SQL_HANDLE_STMT, hstmt);
59
* Test SQLGetDiagRec on the connection, after the backend connection is
60
* dead. Twice, again to check that the first call doesn't clear the
63
print_diag("SQLGetDiagRec on connection says:", SQL_HANDLE_DBC, conn);
64
print_diag("SQLGetDiagRec called again:", SQL_HANDLE_DBC, conn);