Line data Source code
1 : #include <stdio.h>
2 : #include <stdlib.h>
3 :
4 : EXEC SQL include ../regression;
5 :
6 : EXEC SQL typedef long mmInteger;
7 : EXEC SQL typedef char mmChar;
8 : EXEC SQL typedef short access; /* matches an unreserved SQL keyword */
9 : EXEC SQL typedef access access_renamed;
10 :
11 : exec sql type string is char[11];
12 : typedef char string[11];
13 :
14 : exec sql type c is char reference;
15 : typedef char* c;
16 :
17 : EXEC SQL BEGIN DECLARE SECTION;
18 : struct TBempl
19 : {
20 : mmInteger idnum;
21 : mmChar name[21];
22 : access accs;
23 : };
24 : EXEC SQL END DECLARE SECTION;
25 :
26 : int
27 4 : main (void)
28 : {
29 : EXEC SQL BEGIN DECLARE SECTION;
30 : struct TBempl empl;
31 : string str;
32 4 : access accs_val = 320;
33 4 : c ptr = NULL;
34 : struct varchar
35 : {
36 : int len;
37 : char text[10];
38 : } vc;
39 : EXEC SQL END DECLARE SECTION;
40 :
41 : EXEC SQL var vc is varchar[10];
42 4 : ECPGdebug (1, stderr);
43 :
44 4 : empl.idnum = 1;
45 4 : EXEC SQL connect to REGRESSDB1;
46 4 : if (sqlca.sqlcode)
47 : {
48 0 : printf ("connect error = %ld\n", sqlca.sqlcode);
49 0 : exit (sqlca.sqlcode);
50 : }
51 :
52 4 : EXEC SQL create table empl
53 : (idnum integer, name char(20), accs smallint, string1 char(10), string2 char(10), string3 char(10));
54 4 : if (sqlca.sqlcode)
55 : {
56 0 : printf ("create error = %ld\n", sqlca.sqlcode);
57 0 : exit (sqlca.sqlcode);
58 : }
59 :
60 4 : EXEC SQL insert into empl values (1, 'user name', :accs_val, 'first str', 'second str', 'third str');
61 4 : if (sqlca.sqlcode)
62 : {
63 0 : printf ("insert error = %ld\n", sqlca.sqlcode);
64 0 : exit (sqlca.sqlcode);
65 : }
66 :
67 4 : EXEC SQL select idnum, name, accs, string1, string2, string3
68 : into :empl, :str, :ptr, :vc
69 : from empl
70 : where idnum =:empl.idnum;
71 4 : if (sqlca.sqlcode)
72 : {
73 0 : printf ("select error = %ld\n", sqlca.sqlcode);
74 0 : exit (sqlca.sqlcode);
75 : }
76 4 : printf ("id=%ld name='%s' accs=%d str='%s' ptr='%s' vc='%10.10s'\n", empl.idnum, empl.name, empl.accs, str, ptr, vc.text);
77 :
78 4 : EXEC SQL disconnect;
79 :
80 4 : free(ptr);
81 4 : exit (0);
82 : }
|