|
7 | 7 | /* End of automatic include section */ |
8 | 8 |
|
9 | 9 | #line 1 "define.pgc" |
10 | | -#include <stdio.h> |
11 | 10 | #include <stdlib.h> |
| 11 | +#include <string.h> |
| 12 | +#include <stdlib.h> |
| 13 | +#include <stdio.h> |
12 | 14 |
|
13 | 15 |
|
14 | 16 | #line 1 "regression.h" |
|
18 | 20 |
|
19 | 21 |
|
20 | 22 |
|
21 | | -#line 4 "define.pgc" |
22 | | - |
23 | | - |
24 | | -typedef long mmInteger ; |
25 | | - |
26 | 23 | #line 6 "define.pgc" |
27 | 24 |
|
28 | | -#line 6 "define.pgc" |
29 | 25 |
|
30 | | -typedef char mmChar ; |
| 26 | +/* exec sql whenever sqlerror sqlprint ; */ |
| 27 | +#line 8 "define.pgc" |
31 | 28 |
|
32 | | -#line 7 "define.pgc" |
33 | 29 |
|
34 | | -#line 7 "define.pgc" |
35 | 30 |
|
36 | | -typedef short mmSmallInt ; |
37 | 31 |
|
38 | | -#line 8 "define.pgc" |
39 | 32 |
|
40 | | -#line 8 "define.pgc" |
| 33 | +/* exec sql type intarray is int [ 6 ] */ |
| 34 | +#line 13 "define.pgc" |
41 | 35 |
|
| 36 | +typedef int intarray[ 6]; |
42 | 37 |
|
| 38 | +int |
| 39 | +main(void) |
| 40 | +{ |
43 | 41 | /* exec sql begin declare section */ |
44 | | - |
45 | 42 |
|
46 | | - |
47 | | - |
48 | | - |
| 43 | + typedef char string [ 8 ] ; |
49 | 44 |
|
50 | | -struct TBempl { |
51 | | -#line 13 "define.pgc" |
52 | | - mmInteger idnum ; |
| 45 | +#line 21 "define.pgc" |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
53 | 50 |
|
54 | | -#line 14 "define.pgc" |
55 | | - mmChar name [ 21 ] ; |
| 51 | +#line 22 "define.pgc" |
| 52 | + intarray amount ; |
56 | 53 |
|
57 | | -#line 15 "define.pgc" |
58 | | - mmSmallInt accs ; |
59 | | - } ;/* exec sql end declare section */ |
60 | | -#line 17 "define.pgc" |
61 | | - |
62 | | - |
63 | | -int |
64 | | -main (void) |
65 | | -{ |
66 | | - /* exec sql begin declare section */ |
67 | | - |
68 | | - |
69 | 54 | #line 23 "define.pgc" |
70 | | - struct TBempl empl ; |
71 | | -/* exec sql end declare section */ |
| 55 | + char name [ 6 ] [ 8 ] ; |
| 56 | + |
72 | 57 | #line 24 "define.pgc" |
| 58 | + char letter [ 6 ] [ 1 ] ; |
| 59 | + |
| 60 | +#if 0 |
| 61 | + |
| 62 | +#line 26 "define.pgc" |
| 63 | + int not_used ; |
| 64 | + |
| 65 | +#endif |
| 66 | +/* exec sql end declare section */ |
| 67 | +#line 29 "define.pgc" |
73 | 68 |
|
| 69 | + int i,j; |
74 | 70 |
|
75 | | - ECPGdebug (1, stderr); |
| 71 | + ECPGdebug(1, stderr); |
76 | 72 |
|
77 | | - empl.idnum = 1; |
78 | | - { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); } |
79 | | -#line 29 "define.pgc" |
| 73 | + { ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , NULL, 0); |
| 74 | +#line 34 "define.pgc" |
| 75 | + |
| 76 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 77 | +#line 34 "define.pgc" |
80 | 78 |
|
81 | | - if (sqlca.sqlcode) |
82 | | - { |
83 | | - printf ("connect error = %ld\n", sqlca.sqlcode); |
84 | | - exit (sqlca.sqlcode); |
85 | | - } |
86 | 79 |
|
87 | | - { ECPGdo(__LINE__, 0, 1, NULL, "create table empl ( idnum integer , name char ( 20 ) , accs smallint ) ", ECPGt_EOIT, ECPGt_EORT);} |
| 80 | + { ECPGdo(__LINE__, 0, 1, NULL, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) ) ", ECPGt_EOIT, ECPGt_EORT); |
| 81 | +#line 36 "define.pgc" |
| 82 | + |
| 83 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 84 | +#line 36 "define.pgc" |
| 85 | + |
| 86 | + { ECPGtrans(__LINE__, NULL, "commit"); |
88 | 87 | #line 37 "define.pgc" |
89 | 88 |
|
90 | | - if (sqlca.sqlcode) |
91 | | - { |
92 | | - printf ("create error = %ld\n", sqlca.sqlcode); |
93 | | - exit (sqlca.sqlcode); |
94 | | - } |
95 | | - |
96 | | - { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values ( 1 , 'first user' , 320 ) ", ECPGt_EOIT, ECPGt_EORT);} |
97 | | -#line 44 "define.pgc" |
98 | | - |
99 | | - if (sqlca.sqlcode) |
100 | | - { |
101 | | - printf ("insert error = %ld\n", sqlca.sqlcode); |
102 | | - exit (sqlca.sqlcode); |
103 | | - } |
104 | | - |
105 | | - { ECPGdo(__LINE__, 0, 1, NULL, "select idnum , name , accs from empl where idnum = ? ", |
106 | | - ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), |
107 | | - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, |
108 | | - ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), |
| 89 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 90 | +#line 37 "define.pgc" |
| 91 | + |
| 92 | + |
| 93 | + { ECPGdo(__LINE__, 0, 1, NULL, "insert into Test ( name , amount , letter ) values ( 'false' , 1 , 'f' ) ", ECPGt_EOIT, ECPGt_EORT); |
| 94 | +#line 39 "define.pgc" |
| 95 | + |
| 96 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 97 | +#line 39 "define.pgc" |
| 98 | + |
| 99 | + { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( name , amount , letter ) values ( 'true' , 2 , 't' ) ", ECPGt_EOIT, ECPGt_EORT); |
| 100 | +#line 40 "define.pgc" |
| 101 | + |
| 102 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 103 | +#line 40 "define.pgc" |
| 104 | + |
| 105 | + { ECPGtrans(__LINE__, NULL, "commit"); |
| 106 | +#line 41 "define.pgc" |
| 107 | + |
| 108 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 109 | +#line 41 "define.pgc" |
| 110 | + |
| 111 | + |
| 112 | + { ECPGdo(__LINE__, 0, 1, NULL, "select * from test ", ECPGt_EOIT, |
| 113 | + ECPGt_char,(name),(long)8,(long)6,(8)*sizeof(char), |
109 | 114 | ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, |
110 | | - ECPGt_char,&(empl.name),(long)21,(long)1,(21)*sizeof(char), |
| 115 | + ECPGt_int,(amount),(long)1,(long)6,sizeof(int), |
111 | 116 | ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, |
112 | | - ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), |
113 | | - ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);} |
114 | | -#line 54 "define.pgc" |
| 117 | + ECPGt_char,(letter),(long)1,(long)6,(1)*sizeof(char), |
| 118 | + ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT); |
| 119 | +#line 43 "define.pgc" |
| 120 | + |
| 121 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 122 | +#line 43 "define.pgc" |
| 123 | + |
| 124 | + |
| 125 | + for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) |
| 126 | + { |
| 127 | + /* exec sql begin declare section */ |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +#line 48 "define.pgc" |
| 132 | + char n [ 8 ] , l = letter [ i ] [ 0 ] ; |
| 133 | + |
| 134 | +#line 49 "define.pgc" |
| 135 | + int a = amount [ i ] ; |
| 136 | +/* exec sql end declare section */ |
| 137 | +#line 50 "define.pgc" |
| 138 | + |
| 139 | + |
| 140 | + strncpy(n, name[i], 8); |
| 141 | + printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); |
| 142 | + } |
| 143 | + |
| 144 | + { ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT); |
| 145 | +#line 56 "define.pgc" |
| 146 | + |
| 147 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 148 | +#line 56 "define.pgc" |
| 149 | + |
| 150 | + { ECPGtrans(__LINE__, NULL, "commit"); |
| 151 | +#line 57 "define.pgc" |
| 152 | + |
| 153 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 154 | +#line 57 "define.pgc" |
| 155 | + |
| 156 | + { ECPGdisconnect(__LINE__, "CURRENT"); |
| 157 | +#line 58 "define.pgc" |
115 | 158 |
|
116 | | - if (sqlca.sqlcode) |
117 | | - { |
118 | | - printf ("select error = %ld\n", sqlca.sqlcode); |
119 | | - exit (sqlca.sqlcode); |
120 | | - } |
121 | | - printf ("id=%ld name=%s, accs=%d\n", empl.idnum, empl.name, empl.accs); |
| 159 | +if (sqlca.sqlcode < 0) sqlprint();} |
| 160 | +#line 58 "define.pgc" |
122 | 161 |
|
123 | | - { ECPGdisconnect(__LINE__, "CURRENT");} |
124 | | -#line 62 "define.pgc" |
125 | 162 |
|
126 | | - exit (0); |
| 163 | + return (0); |
127 | 164 | } |
0 commit comments