summaryrefslogtreecommitdiffstats
path: root/src/interfaces/ecpg/test/sql/dynalloc2.pgc
blob: 67d907723a94cef1fd18bd89a47cb198325b7c11 (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
#include <stdio.h>
exec sql include sqlca;
#include <stdlib.h>
exec sql include ../regression;

int main(void)
{
   exec sql begin declare section;
   int *ip1=0;
   char **cp2=0;
   int *ipointer1=0;
   int *ipointer2=0;
   int colnum;
   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 postgres;

   exec sql create table test (a int, b text);
   exec sql insert into test values (1, 'one');
   exec sql insert into test values (2, 'two');
   exec sql insert into test values (NULL, 'three');
   exec sql insert into test values (4, 'four');
   exec sql insert into test values (5, NULL);
   exec sql insert into test values (NULL, NULL);

   exec sql allocate descriptor mydesc;
   exec sql select * into sql descriptor mydesc from test;
   exec sql get descriptor mydesc :colnum=COUNT;
   exec sql get descriptor mydesc value 1 :ip1=DATA, :ipointer1=INDICATOR;
   exec sql get descriptor mydesc value 2 :cp2=DATA, :ipointer2=INDICATOR;

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

      if (ipointer2[i]) printf("NULL, ");
      else printf("'%s', ",cp2[i]);
      printf("\n");
   }
   ECPGfree_auto_mem();
   printf("\n");

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