| 1 |
/* Processed by ecpg (regression mode) */ |
| 2 |
/* These include files are added by the preprocessor */ |
| 3 |
#include <ecpglib.h> |
| 4 |
#include <ecpgerrno.h> |
| 5 |
#include <sqlca.h> |
| 6 |
/* End of automatic include section */ |
| 7 |
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y)) |
| 8 |
|
| 9 |
#line 1 "test6.pgc" |
| 10 |
/* |
| 11 |
* This test verifies that ecpg functions properly handle NULL connections |
| 12 |
* (i.e., when a connection name doesn't exist or has been disconnected). |
| 13 |
* Before the fix, these operations would cause a segmentation fault. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include <stdlib.h> |
| 17 |
#include <string.h> |
| 18 |
#include <stdio.h> |
| 19 |
|
| 20 |
|
| 21 |
#line 1 "regression.h" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#line 11 "test6.pgc" |
| 29 |
|
| 30 |
|
| 31 |
int |
| 32 |
main(void) |
| 33 |
{ |
| 34 |
/* exec sql begin declare section */ |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#line 17 "test6.pgc" |
| 41 |
int val1output = 2 ; |
| 42 |
|
| 43 |
#line 18 "test6.pgc" |
| 44 |
int val1 = 1 ; |
| 45 |
|
| 46 |
#line 19 "test6.pgc" |
| 47 |
char val2 [ 6 ] = "data1" ; |
| 48 |
|
| 49 |
#line 20 "test6.pgc" |
| 50 |
char * stmt1 = "SELECT * from test1 where a = $1 and b = $2" ; |
| 51 |
/* exec sql end declare section */ |
| 52 |
#line 21 "test6.pgc" |
| 53 |
|
| 54 |
|
| 55 |
ECPGdebug(1, stderr); |
| 56 |
|
| 57 |
/* Connect to the database */ |
| 58 |
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "myconn", 0); } |
| 59 |
#line 26 "test6.pgc" |
| 60 |
|
| 61 |
|
| 62 |
/* Test 1: Try to get descriptor on a disconnected connection */ |
| 63 |
printf("Test 1: Try to get descriptor on a disconnected connection\n"); |
| 64 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test1 ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);} |
| 65 |
#line 30 "test6.pgc" |
| 66 |
|
| 67 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test1 ( a , b ) values ( 1 , 'data1' )", ECPGt_EOIT, ECPGt_EORT);} |
| 68 |
#line 31 "test6.pgc" |
| 69 |
|
| 70 |
|
| 71 |
ECPGallocate_desc(__LINE__, "indesc"); |
| 72 |
#line 33 "test6.pgc" |
| 73 |
|
| 74 |
ECPGallocate_desc(__LINE__, "outdesc"); |
| 75 |
#line 34 "test6.pgc" |
| 76 |
|
| 77 |
|
| 78 |
{ ECPGprepare(__LINE__, NULL, 0, "foo2", stmt1);} |
| 79 |
#line 36 "test6.pgc" |
| 80 |
|
| 81 |
|
| 82 |
{ ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data, |
| 83 |
ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT); |
| 84 |
} |
| 85 |
#line 38 "test6.pgc" |
| 86 |
|
| 87 |
{ ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data, |
| 88 |
ECPGt_char,(val2),(long)6,(long)1,(6)*sizeof(char), ECPGd_EODT); |
| 89 |
} |
| 90 |
#line 39 "test6.pgc" |
| 91 |
|
| 92 |
|
| 93 |
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo2", |
| 94 |
ECPGt_descriptor, "indesc", 1L, 1L, 1L, |
| 95 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, |
| 96 |
ECPGt_descriptor, "outdesc", 1L, 1L, 1L, |
| 97 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} |
| 98 |
#line 41 "test6.pgc" |
| 99 |
|
| 100 |
|
| 101 |
{ ECPGtrans(__LINE__, NULL, "rollback");} |
| 102 |
#line 43 "test6.pgc" |
| 103 |
|
| 104 |
{ ECPGdisconnect(__LINE__, "CURRENT");} |
| 105 |
#line 44 "test6.pgc" |
| 106 |
|
| 107 |
{ ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data, |
| 108 |
ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGd_EODT); |
| 109 |
} |
| 110 |
#line 45 "test6.pgc" |
| 111 |
|
| 112 |
printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode); |
| 113 |
|
| 114 |
/* Test 2: Try to deallocate all on a non-existent connection */ |
| 115 |
printf("Test 2: deallocate all with non-existent connection\n"); |
| 116 |
{ ECPGdeallocate_all(__LINE__, 0, "nonexistent");} |
| 117 |
#line 50 "test6.pgc" |
| 118 |
|
| 119 |
printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode); |
| 120 |
|
| 121 |
/* Test 3: deallocate on disconnected connection */ |
| 122 |
printf("Test 3: deallocate all on disconnected connection\n"); |
| 123 |
{ ECPGdeallocate_all(__LINE__, 0, NULL);} |
| 124 |
#line 55 "test6.pgc" |
| 125 |
|
| 126 |
printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode); |
| 127 |
|
| 128 |
/* Test 4: Use prepared statement from non-existent connection */ |
| 129 |
printf("Test 4: Use prepared statement from non-existent connection\n"); |
| 130 |
{ ECPGprepare(__LINE__, "nonexistent", 0, "stmt1", "SELECT 1");} |
| 131 |
#line 60 "test6.pgc" |
| 132 |
|
| 133 |
/* declare cur1 cursor for $1 */ |
| 134 |
#line 61 "test6.pgc" |
| 135 |
|
| 136 |
{ ECPGdo(__LINE__, 0, 1, "nonexistent", 0, ECPGst_normal, "declare cur1 cursor for $1", |
| 137 |
ECPGt_char_variable,(ECPGprepared_statement("nonexistent", "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), |
| 138 |
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);} |
| 139 |
#line 62 "test6.pgc" |
| 140 |
|
| 141 |
printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode); |
| 142 |
|
| 143 |
printf("All tests completed !\n"); |
| 144 |
|
| 145 |
return 0; |
| 146 |
} |