#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 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;
}
