~ubuntu-branches/ubuntu/wily/psqlodbc/wily-proposed

« back to all changes in this revision

Viewing changes to test/src/diagnostic-test.c

  • Committer: Package Import Robot
  • Author(s): Christoph Berg
  • Date: 2014-05-29 23:17:25 UTC
  • mfrom: (16.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20140529231725-nhpolx85545e4rk8
Tags: 1:09.03.0300-1
* New upstream release.
* Patch bogus expected output of test catalogfunctions.
* Set team as maintainer.
* Bump to dh 9.
* Use /usr/share/cdbs/1/rules/autoreconf.mk. Closes: #744650.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Tests for error diagnostics (SQLGetDiagRec)
 
3
 */
 
4
#include <string.h>
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
 
 
8
#include "common.h"
 
9
 
 
10
int main(int argc, char **argv)
 
11
{
 
12
        int rc;
 
13
        HSTMT hstmt = SQL_NULL_HSTMT;
 
14
        HSTMT hstmt2 = SQL_NULL_HSTMT;
 
15
        char sql[100000];
 
16
        char *sqlend;
 
17
        int i;
 
18
        SQLCHAR dsn[1024];
 
19
        SQLCHAR str[1024];
 
20
        SQLSMALLINT strl;
 
21
 
 
22
        test_connect();
 
23
 
 
24
        rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
 
25
        if (!SQL_SUCCEEDED(rc))
 
26
        {
 
27
                print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
 
28
                exit(1);
 
29
        }
 
30
 
 
31
        /*
 
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.
 
35
         */
 
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);
 
39
 
 
40
        rc = SQLEndTran(SQL_HANDLE_DBC, conn, SQL_ROLLBACK);
 
41
        CHECK_STMT_RESULT(rc, "SQLEndTran failed", hstmt);
 
42
 
 
43
        rc = SQLFreeStmt(hstmt, SQL_DROP);
 
44
        CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
 
45
 
 
46
        /* kill this connection */
 
47
        printf ("killing connection...\n");
 
48
        rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
 
49
        if (!SQL_SUCCEEDED(rc))
 
50
        {
 
51
                print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
 
52
                exit(1);
 
53
        }
 
54
 
 
55
        rc = SQLExecDirect(hstmt, (SQLCHAR *) "select pg_terminate_backend(pg_backend_pid()) ", SQL_NTS);
 
56
        print_diag(NULL, SQL_HANDLE_STMT, hstmt);
 
57
 
 
58
        /*
 
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
 
61
         * error.
 
62
         */
 
63
        print_diag("SQLGetDiagRec on connection says:", SQL_HANDLE_DBC, conn);
 
64
        print_diag("SQLGetDiagRec called again:", SQL_HANDLE_DBC, conn);
 
65
}