1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.86 2009/08/07 10:51:20 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.87 2009/09/03 10:24:48 meskes Exp $ */
22
33/*
44 * The aim is to get a simpler inteface to the database routines.
@@ -469,8 +469,8 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
469469char * newcopy = NULL ;
470470
471471/*
472- * arrays are not possible unless the attribute is an array too FIXME: we
473- * do not know if the attribute is an array here
472+ * arrays are not possible unless the attribute is an array too
473+ *FIXME: we do not know if the attribute is an array here
474474 */
475475#if 0
476476if (var -> arrsize > 1 && ...)
@@ -818,6 +818,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
818818
819819if (var -> arrsize > 1 )
820820{
821+ if (!(mallocedval = ecpg_strdup ("array [" ,lineno )))
822+ return false;
823+
821824for (element = 0 ;element < var -> arrsize ;element ++ )
822825{
823826nval = PGTYPESnumeric_new ();
@@ -833,15 +836,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
833836slen = strlen (str );
834837PGTYPESnumeric_free (nval );
835838
836- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + sizeof ( "array [] " ) ,lineno )))
839+ if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
837840{
838841ecpg_free (str );
839842return false;
840843}
841844
842- if (!element )
843- strcpy (mallocedval ,"array [" );
844-
845845strncpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
846846strcpy (mallocedval + strlen (mallocedval ),"," );
847847ecpg_free (str );
@@ -885,22 +885,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
885885
886886if (var -> arrsize > 1 )
887887{
888+ if (!(mallocedval = ecpg_strdup ("array [" ,lineno )))
889+ return false;
890+
888891for (element = 0 ;element < var -> arrsize ;element ++ )
889892{
890893str = quote_postgres (PGTYPESinterval_to_asc ((interval * ) ((var + var -> offset * element )-> value )),quote ,lineno );
891894if (!str )
892895return false;
893896slen = strlen (str );
894897
895- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + sizeof ( "array [],interval " ) ,lineno )))
898+ if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
896899{
897900ecpg_free (str );
898901return false;
899902}
900903
901- if (!element )
902- strcpy (mallocedval ,"array [" );
903-
904904strncpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
905905strcpy (mallocedval + strlen (mallocedval ),"," );
906906ecpg_free (str );
@@ -936,22 +936,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
936936
937937if (var -> arrsize > 1 )
938938{
939+ if (!(mallocedval = ecpg_strdup ("array [" ,lineno )))
940+ return false;
941+
939942for (element = 0 ;element < var -> arrsize ;element ++ )
940943{
941944str = quote_postgres (PGTYPESdate_to_asc (* (date * ) ((var + var -> offset * element )-> value )),quote ,lineno );
942945if (!str )
943946return false;
944947slen = strlen (str );
945948
946- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + sizeof ( "array [],date " ) ,lineno )))
949+ if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
947950{
948951ecpg_free (str );
949952return false;
950953}
951954
952- if (!element )
953- strcpy (mallocedval ,"array [" );
954-
955955strncpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
956956strcpy (mallocedval + strlen (mallocedval ),"," );
957957ecpg_free (str );
@@ -987,6 +987,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
987987
988988if (var -> arrsize > 1 )
989989{
990+ if (!(mallocedval = ecpg_strdup ("array [" ,lineno )))
991+ return false;
992+
990993for (element = 0 ;element < var -> arrsize ;element ++ )
991994{
992995str = quote_postgres (PGTYPEStimestamp_to_asc (* (timestamp * ) ((var + var -> offset * element )-> value )),quote ,lineno );
@@ -995,15 +998,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
995998
996999slen = strlen (str );
9971000
998- if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + sizeof ( "array [], timestamp " ) ,lineno )))
1001+ if (!(mallocedval = ecpg_realloc (mallocedval ,strlen (mallocedval )+ slen + 2 ,lineno )))
9991002{
10001003ecpg_free (str );
10011004return false;
10021005}
10031006
1004- if (!element )
1005- strcpy (mallocedval ,"array [" );
1006-
10071007strncpy (mallocedval + strlen (mallocedval ),str ,slen + 1 );
10081008strcpy (mallocedval + strlen (mallocedval ),"," );
10091009ecpg_free (str );