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 $ */
2
2
3
3
/*
4
4
* 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
469
469
char * newcopy = NULL ;
470
470
471
471
/*
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
474
474
*/
475
475
#if 0
476
476
if (var -> arrsize > 1 && ...)
@@ -818,6 +818,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
818
818
819
819
if (var -> arrsize > 1 )
820
820
{
821
+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
822
+ return false;
823
+
821
824
for (element = 0 ; element < var -> arrsize ; element ++ )
822
825
{
823
826
nval = PGTYPESnumeric_new ();
@@ -833,15 +836,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
833
836
slen = strlen (str );
834
837
PGTYPESnumeric_free (nval );
835
838
836
- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [] " ) , lineno )))
839
+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
837
840
{
838
841
ecpg_free (str );
839
842
return false;
840
843
}
841
844
842
- if (!element )
843
- strcpy (mallocedval , "array [" );
844
-
845
845
strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
846
846
strcpy (mallocedval + strlen (mallocedval ), "," );
847
847
ecpg_free (str );
@@ -885,22 +885,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
885
885
886
886
if (var -> arrsize > 1 )
887
887
{
888
+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
889
+ return false;
890
+
888
891
for (element = 0 ; element < var -> arrsize ; element ++ )
889
892
{
890
893
str = quote_postgres (PGTYPESinterval_to_asc ((interval * ) ((var + var -> offset * element )-> value )), quote , lineno );
891
894
if (!str )
892
895
return false;
893
896
slen = strlen (str );
894
897
895
- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [],interval " ) , lineno )))
898
+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
896
899
{
897
900
ecpg_free (str );
898
901
return false;
899
902
}
900
903
901
- if (!element )
902
- strcpy (mallocedval , "array [" );
903
-
904
904
strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
905
905
strcpy (mallocedval + strlen (mallocedval ), "," );
906
906
ecpg_free (str );
@@ -936,22 +936,22 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
936
936
937
937
if (var -> arrsize > 1 )
938
938
{
939
+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
940
+ return false;
941
+
939
942
for (element = 0 ; element < var -> arrsize ; element ++ )
940
943
{
941
944
str = quote_postgres (PGTYPESdate_to_asc (* (date * ) ((var + var -> offset * element )-> value )), quote , lineno );
942
945
if (!str )
943
946
return false;
944
947
slen = strlen (str );
945
948
946
- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [],date " ) , lineno )))
949
+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
947
950
{
948
951
ecpg_free (str );
949
952
return false;
950
953
}
951
954
952
- if (!element )
953
- strcpy (mallocedval , "array [" );
954
-
955
955
strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
956
956
strcpy (mallocedval + strlen (mallocedval ), "," );
957
957
ecpg_free (str );
@@ -987,6 +987,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
987
987
988
988
if (var -> arrsize > 1 )
989
989
{
990
+ if (!(mallocedval = ecpg_strdup ("array [" , lineno )))
991
+ return false;
992
+
990
993
for (element = 0 ; element < var -> arrsize ; element ++ )
991
994
{
992
995
str = 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
995
998
996
999
slen = strlen (str );
997
1000
998
- if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + sizeof ( "array [], timestamp " ) , lineno )))
1001
+ if (!(mallocedval = ecpg_realloc (mallocedval , strlen (mallocedval ) + slen + 2 , lineno )))
999
1002
{
1000
1003
ecpg_free (str );
1001
1004
return false;
1002
1005
}
1003
1006
1004
- if (!element )
1005
- strcpy (mallocedval , "array [" );
1006
-
1007
1007
strncpy (mallocedval + strlen (mallocedval ), str , slen + 1 );
1008
1008
strcpy (mallocedval + strlen (mallocedval ), "," );
1009
1009
ecpg_free (str );
0 commit comments