1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
int main(int argc, char **argv)
{
int rc;
HSTMT hstmt = SQL_NULL_HSTMT;
char *sql;
test_connect();
rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
sql =
"CREATE OR REPLACE FUNCTION raisenotice(s text) RETURNS void AS $$"
"begin\n"
" raise notice 'test notice: %',s;\n"
"end;\n"
"$$ LANGUAGE plpgsql";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLExecDirect failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLFreeStmt failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
/* Call the function that gives a NOTICE */
sql = "SELECT raisenotice('foo')";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLExecDirect failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
if (rc == SQL_SUCCESS_WITH_INFO)
print_diag("got SUCCESS_WITH_INFO", SQL_HANDLE_STMT, hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLFreeStmt failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
/*
* The same, with a really long notice.
*/
sql = "SELECT raisenotice(repeat('foo', 100))";
rc = SQLExecDirect(hstmt, (SQLCHAR *) sql, SQL_NTS);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLExecDirect failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
if (rc == SQL_SUCCESS_WITH_INFO)
print_diag("got SUCCESS_WITH_INFO", SQL_HANDLE_STMT, hstmt);
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("SQLFreeStmt failed", SQL_HANDLE_STMT, hstmt);
exit(1);
}
/* Clean up */
test_disconnect();
return 0;
}
|