Age Owner TLA Line data Source code
1 : #include <stdio.h>
2 : #include <stdlib.h>
3 : #include <string.h>
4 :
5 : EXEC SQL INCLUDE ../regression;
6 :
1852 meskes 7 CBC 3 : static void warn(void)
8 : {
9 3 : fprintf(stderr, "Warning: At least one column was truncated\n");
10 3 : }
11 :
12 : /* Compatible handling of char array to retrieve varchar field to char array
13 : should be fixed-length, blank-padded, then null-terminated.
14 : Conforms to the ANSI Fixed Character type. */
15 :
16 1 : int main() {
17 :
18 : EXEC SQL WHENEVER SQLWARNING do warn();
19 : EXEC SQL WHENEVER SQLERROR STOP;
20 :
21 1 : const char *ppppp = "XXXXX";
22 : int loopcount;
23 : EXEC SQL BEGIN DECLARE SECTION;
24 : char shortstr[5];
25 : char bigstr[11];
26 1 : short shstr_ind = 0;
27 1 : short bigstr_ind = 0;
28 : EXEC SQL END DECLARE SECTION;
29 :
30 1 : ECPGdebug(1, stderr);
31 1 : EXEC SQL CONNECT TO REGRESSDB1;
32 1 :
33 1 : EXEC SQL CREATE TABLE strdbase (strval varchar(10));
34 1 : EXEC SQL INSERT INTO strdbase values ('');
35 1 : EXEC SQL INSERT INTO strdbase values ('AB');
36 1 : EXEC SQL INSERT INTO strdbase values ('ABCD');
37 1 : EXEC SQL INSERT INTO strdbase values ('ABCDE');
38 1 : EXEC SQL INSERT INTO strdbase values ('ABCDEF');
39 1 : EXEC SQL INSERT INTO strdbase values ('ABCDEFGHIJ');
40 1 :
41 : EXEC SQL declare C cursor for select strval, strval from strdbase;
42 1 : EXEC SQL OPEN C;
43 1 :
44 : EXEC SQL WHENEVER NOT FOUND DO BREAK;
45 :
46 1 : printf("Full Str. : Short Ind.\n");
1536 tgl 47 7 : for (loopcount = 0; loopcount < 100; loopcount++) {
1852 meskes 48 7 : strncpy(shortstr, ppppp, sizeof shortstr);
49 7 : memset(bigstr, 0, sizeof bigstr);
50 7 : EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;
51 7 : printf("\"%s\": \"%s\" %d\n", bigstr, shortstr, shstr_ind);
52 : }
53 :
1844 peter_e 54 1 : EXEC SQL CLOSE C;
1852 meskes 55 1 : EXEC SQL DROP TABLE strdbase;
56 1 :
57 1 : printf("\nGOOD-BYE!!\n\n");
58 :
59 1 : EXEC SQL COMMIT WORK;
60 1 :
61 1 : EXEC SQL DISCONNECT ALL;
62 1 :
63 1 : return 0;
64 : }
|