Line data Source code
1 : /*
2 : * This test verifies that ecpg functions properly handle NULL connections
3 : * (i.e., when a connection name doesn't exist or has been disconnected).
4 : * Before the fix, these operations would cause a segmentation fault.
5 : */
6 :
7 : #include <stdlib.h>
8 : #include <string.h>
9 : #include <stdio.h>
10 :
11 : exec sql include ../regression;
12 :
13 : int
14 2 : main(void)
15 : {
16 : exec sql begin declare section;
17 2 : int val1output = 2;
18 2 : int val1 = 1;
19 2 : char val2[6] = "data1";
20 2 : char *stmt1 = "SELECT * from test1 where a = $1 and b = $2";
21 : exec sql end declare section;
22 :
23 2 : ECPGdebug(1, stderr);
24 :
25 : /* Connect to the database */
26 2 : exec sql connect to REGRESSDB1 as myconn;
27 :
28 : /* Test 1: Try to get descriptor on a disconnected connection */
29 2 : printf("Test 1: Try to get descriptor on a disconnected connection\n");
30 2 : exec sql create table test1 (a int, b text);
31 2 : exec sql insert into test1 (a,b) values (1, 'data1');
32 :
33 2 : exec sql allocate descriptor indesc;
34 2 : exec sql allocate descriptor outdesc;
35 :
36 2 : exec sql prepare foo2 from :stmt1;
37 :
38 2 : exec sql set descriptor indesc value 1 DATA = :val1;
39 2 : exec sql set descriptor indesc value 2 DATA = :val2;
40 :
41 2 : exec sql execute foo2 using sql descriptor indesc into sql descriptor outdesc;
42 :
43 2 : exec sql rollback;
44 2 : exec sql disconnect;
45 2 : exec sql get descriptor outdesc value 1 :val1output = DATA;
46 2 : printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
47 :
48 : /* Test 2: Try to deallocate all on a non-existent connection */
49 2 : printf("Test 2: deallocate all with non-existent connection\n");
50 2 : exec sql at nonexistent deallocate all;
51 2 : printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
52 :
53 : /* Test 3: deallocate on disconnected connection */
54 2 : printf("Test 3: deallocate all on disconnected connection\n");
55 2 : exec sql deallocate all;
56 2 : printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
57 :
58 : /* Test 4: Use prepared statement from non-existent connection */
59 2 : printf("Test 4: Use prepared statement from non-existent connection\n");
60 2 : exec sql at nonexistent prepare stmt1 FROM "SELECT 1";
61 : exec sql at nonexistent declare cur1 cursor for stmt1;
62 2 : exec sql at nonexistent open cur1;
63 2 : printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
64 :
65 2 : printf("All tests completed !\n");
66 :
67 2 : return 0;
68 : }
|