1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.58 2006/08/09 09:08:31 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.59 2006/08/18 16:30:53 meskes Exp $ */
22
33/*
44 * The aim is to get a simpler inteface to the database routines.
@@ -572,19 +572,21 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
572572}
573573if (* * tobeinserted_p == '\0' )
574574{
575+ int asize = var -> arrsize ?var -> arrsize :1 ;
576+
575577switch (var -> type )
576578{
577579int element ;
578580
579581case ECPGt_short :
580- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
582+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
581583return false;
582584
583- if (var -> arrsize > 1 )
585+ if (asize > 1 )
584586{
585587strcpy (mallocedval ,"array [" );
586588
587- for (element = 0 ;element < var -> arrsize ;element ++ )
589+ for (element = 0 ;element < asize ;element ++ )
588590sprintf (mallocedval + strlen (mallocedval ),"%hd," , ((short * )var -> value )[element ]);
589591
590592strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -597,14 +599,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
597599break ;
598600
599601case ECPGt_int :
600- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
602+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
601603return false;
602604
603- if (var -> arrsize > 1 )
605+ if (asize > 1 )
604606{
605607strcpy (mallocedval ,"array [" );
606608
607- for (element = 0 ;element < var -> arrsize ;element ++ )
609+ for (element = 0 ;element < asize ;element ++ )
608610sprintf (mallocedval + strlen (mallocedval ),"%d," , ((int * )var -> value )[element ]);
609611
610612strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -617,14 +619,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
617619break ;
618620
619621case ECPGt_unsigned_short :
620- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
622+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
621623return false;
622624
623- if (var -> arrsize > 1 )
625+ if (asize > 1 )
624626{
625627strcpy (mallocedval ,"array [" );
626628
627- for (element = 0 ;element < var -> arrsize ;element ++ )
629+ for (element = 0 ;element < asize ;element ++ )
628630sprintf (mallocedval + strlen (mallocedval ),"%hu," , ((unsigned short * )var -> value )[element ]);
629631
630632strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -637,14 +639,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
637639break ;
638640
639641case ECPGt_unsigned_int :
640- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
642+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
641643return false;
642644
643- if (var -> arrsize > 1 )
645+ if (asize > 1 )
644646{
645647strcpy (mallocedval ,"array [" );
646648
647- for (element = 0 ;element < var -> arrsize ;element ++ )
649+ for (element = 0 ;element < asize ;element ++ )
648650sprintf (mallocedval + strlen (mallocedval ),"%u," , ((unsignedint * )var -> value )[element ]);
649651
650652strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -657,14 +659,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
657659break ;
658660
659661case ECPGt_long :
660- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
662+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
661663return false;
662664
663- if (var -> arrsize > 1 )
665+ if (asize > 1 )
664666{
665667strcpy (mallocedval ,"array [" );
666668
667- for (element = 0 ;element < var -> arrsize ;element ++ )
669+ for (element = 0 ;element < asize ;element ++ )
668670sprintf (mallocedval + strlen (mallocedval ),"%ld," , ((long * )var -> value )[element ]);
669671
670672strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -677,14 +679,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
677679break ;
678680
679681case ECPGt_unsigned_long :
680- if (!(mallocedval = ECPGalloc (var -> arrsize * 20 ,lineno )))
682+ if (!(mallocedval = ECPGalloc (asize * 20 ,lineno )))
681683return false;
682684
683- if (var -> arrsize > 1 )
685+ if (asize > 1 )
684686{
685687strcpy (mallocedval ,"array [" );
686688
687- for (element = 0 ;element < var -> arrsize ;element ++ )
689+ for (element = 0 ;element < asize ;element ++ )
688690sprintf (mallocedval + strlen (mallocedval ),"%lu," , ((unsigned long * )var -> value )[element ]);
689691
690692strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -697,14 +699,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
697699break ;
698700#ifdef HAVE_LONG_LONG_INT_64
699701case ECPGt_long_long :
700- if (!(mallocedval = ECPGalloc (var -> arrsize * 30 ,lineno )))
702+ if (!(mallocedval = ECPGalloc (asize * 30 ,lineno )))
701703return false;
702704
703- if (var -> arrsize > 1 )
705+ if (asize > 1 )
704706{
705707strcpy (mallocedval ,"array [" );
706708
707- for (element = 0 ;element < var -> arrsize ;element ++ )
709+ for (element = 0 ;element < asize ;element ++ )
708710sprintf (mallocedval + strlen (mallocedval ),"%lld," , ((long long * )var -> value )[element ]);
709711
710712strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -717,14 +719,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
717719break ;
718720
719721case ECPGt_unsigned_long_long :
720- if (!(mallocedval = ECPGalloc (var -> arrsize * 30 ,lineno )))
722+ if (!(mallocedval = ECPGalloc (asize * 30 ,lineno )))
721723return false;
722724
723- if (var -> arrsize > 1 )
725+ if (asize > 1 )
724726{
725727strcpy (mallocedval ,"array [" );
726728
727- for (element = 0 ;element < var -> arrsize ;element ++ )
729+ for (element = 0 ;element < asize ;element ++ )
728730sprintf (mallocedval + strlen (mallocedval ),"%llu," , ((unsigned long long * )var -> value )[element ]);
729731
730732strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -737,14 +739,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
737739break ;
738740#endif /* HAVE_LONG_LONG_INT_64 */
739741case ECPGt_float :
740- if (!(mallocedval = ECPGalloc (var -> arrsize * 25 ,lineno )))
742+ if (!(mallocedval = ECPGalloc (asize * 25 ,lineno )))
741743return false;
742744
743- if (var -> arrsize > 1 )
745+ if (asize > 1 )
744746{
745747strcpy (mallocedval ,"array [" );
746748
747- for (element = 0 ;element < var -> arrsize ;element ++ )
749+ for (element = 0 ;element < asize ;element ++ )
748750sprintf (mallocedval + strlen (mallocedval ),"%.14g," , ((float * )var -> value )[element ]);
749751
750752strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );
@@ -757,14 +759,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
757759break ;
758760
759761case ECPGt_double :
760- if (!(mallocedval = ECPGalloc (var -> arrsize * 25 ,lineno )))
762+ if (!(mallocedval = ECPGalloc (asize * 25 ,lineno )))
761763return false;
762764
763- if (var -> arrsize > 1 )
765+ if (asize > 1 )
764766{
765767strcpy (mallocedval ,"array [" );
766768
767- for (element = 0 ;element < var -> arrsize ;element ++ )
769+ for (element = 0 ;element < asize ;element ++ )
768770sprintf (mallocedval + strlen (mallocedval ),"%.14g," , ((double * )var -> value )[element ]);
769771
770772strcpy (mallocedval + strlen (mallocedval )- 1 ,"]" );