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 "char_array.pgc"
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14
15 #line 1 "regression.h"
16
17
18
19
20
21
22 #line 5 "char_array.pgc"
23
24
warn(void)25 static void warn(void)
26 {
27 fprintf(stderr, "Warning: At least one column was truncated\n");
28 }
29
30 /* Compatible handling of char array to retrieve varchar field to char array
31 should be fixed-length, blank-padded, then null-terminated.
32 Conforms to the ANSI Fixed Character type. */
33
main()34 int main() {
35
36 /* exec sql whenever sql_warning do warn ( ) ; */
37 #line 18 "char_array.pgc"
38
39 /* exec sql whenever sqlerror stop ; */
40 #line 19 "char_array.pgc"
41
42
43 const char *ppppp = "XXXXX";
44 int loopcount;
45 /* exec sql begin declare section */
46
47
48
49
50
51 #line 24 "char_array.pgc"
52 char shortstr [ 5 ] ;
53
54 #line 25 "char_array.pgc"
55 char bigstr [ 11 ] ;
56
57 #line 26 "char_array.pgc"
58 short shstr_ind = 0 ;
59
60 #line 27 "char_array.pgc"
61 short bigstr_ind = 0 ;
62 /* exec sql end declare section */
63 #line 28 "char_array.pgc"
64
65
66 ECPGdebug(1, stderr);
67 { ECPGconnect(__LINE__, 3, "ecpg1_regression" , NULL, NULL , NULL, 0);
68 #line 31 "char_array.pgc"
69
70 if (sqlca.sqlwarn[0] == 'W') warn ( );
71 #line 31 "char_array.pgc"
72
73 if (sqlca.sqlcode < 0) exit (1);}
74 #line 31 "char_array.pgc"
75
76
77 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "create table strdbase ( strval varchar ( 10 ) )", ECPGt_EOIT, ECPGt_EORT);
78 #line 33 "char_array.pgc"
79
80 if (sqlca.sqlwarn[0] == 'W') warn ( );
81 #line 33 "char_array.pgc"
82
83 if (sqlca.sqlcode < 0) exit (1);}
84 #line 33 "char_array.pgc"
85
86 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( '' )", ECPGt_EOIT, ECPGt_EORT);
87 #line 34 "char_array.pgc"
88
89 if (sqlca.sqlwarn[0] == 'W') warn ( );
90 #line 34 "char_array.pgc"
91
92 if (sqlca.sqlcode < 0) exit (1);}
93 #line 34 "char_array.pgc"
94
95 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'AB' )", ECPGt_EOIT, ECPGt_EORT);
96 #line 35 "char_array.pgc"
97
98 if (sqlca.sqlwarn[0] == 'W') warn ( );
99 #line 35 "char_array.pgc"
100
101 if (sqlca.sqlcode < 0) exit (1);}
102 #line 35 "char_array.pgc"
103
104 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCD' )", ECPGt_EOIT, ECPGt_EORT);
105 #line 36 "char_array.pgc"
106
107 if (sqlca.sqlwarn[0] == 'W') warn ( );
108 #line 36 "char_array.pgc"
109
110 if (sqlca.sqlcode < 0) exit (1);}
111 #line 36 "char_array.pgc"
112
113 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDE' )", ECPGt_EOIT, ECPGt_EORT);
114 #line 37 "char_array.pgc"
115
116 if (sqlca.sqlwarn[0] == 'W') warn ( );
117 #line 37 "char_array.pgc"
118
119 if (sqlca.sqlcode < 0) exit (1);}
120 #line 37 "char_array.pgc"
121
122 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEF' )", ECPGt_EOIT, ECPGt_EORT);
123 #line 38 "char_array.pgc"
124
125 if (sqlca.sqlwarn[0] == 'W') warn ( );
126 #line 38 "char_array.pgc"
127
128 if (sqlca.sqlcode < 0) exit (1);}
129 #line 38 "char_array.pgc"
130
131 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "insert into strdbase values ( 'ABCDEFGHIJ' )", ECPGt_EOIT, ECPGt_EORT);
132 #line 39 "char_array.pgc"
133
134 if (sqlca.sqlwarn[0] == 'W') warn ( );
135 #line 39 "char_array.pgc"
136
137 if (sqlca.sqlcode < 0) exit (1);}
138 #line 39 "char_array.pgc"
139
140
141 /* declare C cursor for select strval , strval from strdbase */
142 #line 41 "char_array.pgc"
143
144 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "declare C cursor for select strval , strval from strdbase", ECPGt_EOIT, ECPGt_EORT);
145 #line 42 "char_array.pgc"
146
147 if (sqlca.sqlwarn[0] == 'W') warn ( );
148 #line 42 "char_array.pgc"
149
150 if (sqlca.sqlcode < 0) exit (1);}
151 #line 42 "char_array.pgc"
152
153
154 /* exec sql whenever not found break ; */
155 #line 44 "char_array.pgc"
156
157
158 printf("Full Str. : Short Ind.\n");
159 for (loopcount = 0; loopcount < 100; loopcount++) {
160 strncpy(shortstr, ppppp, sizeof shortstr);
161 memset(bigstr, 0, sizeof bigstr);
162 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
163 ECPGt_char,(bigstr),(long)11,(long)1,(11)*sizeof(char),
164 ECPGt_short,&(bigstr_ind),(long)1,(long)1,sizeof(short),
165 ECPGt_char,(shortstr),(long)5,(long)1,(5)*sizeof(char),
166 ECPGt_short,&(shstr_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
167 #line 50 "char_array.pgc"
168
169 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
170 #line 50 "char_array.pgc"
171
172 if (sqlca.sqlwarn[0] == 'W') warn ( );
173 #line 50 "char_array.pgc"
174
175 if (sqlca.sqlcode < 0) exit (1);}
176 #line 50 "char_array.pgc"
177
178 printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind);
179 }
180
181 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
182 #line 54 "char_array.pgc"
183
184 if (sqlca.sqlwarn[0] == 'W') warn ( );
185 #line 54 "char_array.pgc"
186
187 if (sqlca.sqlcode < 0) exit (1);}
188 #line 54 "char_array.pgc"
189
190 { ECPGdo(__LINE__, 3, 1, NULL, 0, ECPGst_normal, "drop table strdbase", ECPGt_EOIT, ECPGt_EORT);
191 #line 55 "char_array.pgc"
192
193 if (sqlca.sqlwarn[0] == 'W') warn ( );
194 #line 55 "char_array.pgc"
195
196 if (sqlca.sqlcode < 0) exit (1);}
197 #line 55 "char_array.pgc"
198
199
200 printf("\nGOOD-BYE!!\n\n");
201
202 { ECPGtrans(__LINE__, NULL, "commit work");
203 #line 59 "char_array.pgc"
204
205 if (sqlca.sqlwarn[0] == 'W') warn ( );
206 #line 59 "char_array.pgc"
207
208 if (sqlca.sqlcode < 0) exit (1);}
209 #line 59 "char_array.pgc"
210
211
212 { ECPGdisconnect(__LINE__, "ALL");
213 #line 61 "char_array.pgc"
214
215 if (sqlca.sqlwarn[0] == 'W') warn ( );
216 #line 61 "char_array.pgc"
217
218 if (sqlca.sqlcode < 0) exit (1);}
219 #line 61 "char_array.pgc"
220
221
222 return 0;
223 }
224