summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/dynalloc.pgc
blob: 8aa810f6c935ba27e854f9f407d13b19fcabe39e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
exec sql include sqlca;
#include <stdlib.h>
exec sql include ../regression;

int main(void)
{
   exec sql begin declare section;
   int     *d1=0;
   double  *d2=0;
   char **d3=0;
   char **d4=0;
   char **d5=0;
   char **d6=0;
   char **d7=0;
/*   char **d8=0; */
   char **d9=0;
   int *i1=0;
   int *i2=0;
   int *i3=0;
   int *i4=0;
   int *i5=0;
   int *i6=0;
   int *i7=0;
/*   int *i8=0; */
   int *i9=0;
   exec sql end declare section;
   int i;

   ECPGdebug(1, stderr);

   exec sql whenever sqlerror do sqlprint();
   exec sql connect to REGRESSDB1;

   exec sql set datestyle to mdy;

   exec sql create table test (a serial, b numeric(12,3), c varchar, d varchar(3), e char(4), f timestamptz, g boolean, h box, i inet);
   exec sql insert into test (b, c, d, e, f, g, h, i) values (23.456, 'varchar', 'v', 'c', '2003-03-03 12:33:07 PDT', true, '(1,2,3,4)', '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128');
   exec sql insert into test (b, c, d, e, f, g, h, i) values (2.446456, NULL, 'v', 'c', '2003-03-03 12:33:07 PDT', false, NULL, NULL);

   exec sql allocate descriptor mydesc;
   exec sql select a,b,c,d,e,f,g,h,i into sql descriptor mydesc from test order by a;
   exec sql get descriptor mydesc value 1 :d1=DATA, :i1=INDICATOR;
   exec sql get descriptor mydesc value 2 :d2=DATA, :i2=INDICATOR;
   exec sql get descriptor mydesc value 3 :d3=DATA, :i3=INDICATOR;
   exec sql get descriptor mydesc value 4 :d4=DATA, :i4=INDICATOR;
   exec sql get descriptor mydesc value 5 :d5=DATA, :i5=INDICATOR;
   exec sql get descriptor mydesc value 6 :d6=DATA, :i6=INDICATOR;
   exec sql get descriptor mydesc value 7 :d7=DATA, :i7=INDICATOR;
   /* skip box for now */
   /* exec sql get descriptor mydesc value 8 :d8=DATA, :i8=INDICATOR; */
   exec sql get descriptor mydesc value 9 :d9=DATA, :i9=INDICATOR;

   printf("Result:\n");
   for (i=0;i<sqlca.sqlerrd[2];++i)
   {
      if (i1[i]) printf("NULL, ");
      else printf("%d, ",d1[i]);

      if (i2[i]) printf("NULL, ");
      else printf("%f, ",d2[i]);

      if (i3[i]) printf("NULL, ");
      else printf("'%s', ",d3[i]);

      if (i4[i]) printf("NULL, ");
      else printf("'%s', ",d4[i]);

      if (i5[i]) printf("NULL, ");
      else printf("'%s', ",d5[i]);

      if (i6[i]) printf("NULL, ");
      else printf("'%s', ",d6[i]);

      if (i7[i]) printf("NULL, ");
      else printf("'%s', ",d7[i]);

      if (i9[i]) printf("NULL, ");
      else printf("'%s', ",d9[i]);

      printf("\n");
   }
   ECPGfree_auto_mem();
   printf("\n");

   exec sql deallocate descriptor mydesc;
   exec sql disconnect;
   return 0;
}