@@ -823,23 +823,23 @@ static bool is_vops_type(Oid typeid)
823823Datum vops_##TYPE##_output(PG_FUNCTION_ARGS)\
824824{\
825825vops_##TYPE* tile = (vops_##TYPE*)PG_GETARG_POINTER(0);\
826- char buf[MAX_TILE_STRLEN]; \
827- int p = 0;\
826+ StringInfoData str;\
828827char sep = '{';\
829828int i;\
829+ initStringInfo(&str);\
830830for (i = 0; i < TILE_SIZE; i++) {\
831831if (tile->hdr.empty_mask & ((uint64)1 << i)) {\
832- p += sprintf(buf + p , "%c", sep);\
832+ appendStringInfo(&str , "%c", sep);\
833833} else if (tile->hdr.null_mask & ((uint64)1 << i)) {\
834- p += sprintf(buf + p , "%c?", sep);\
834+ appendStringInfo(&str , "%c?", sep);\
835835} else {\
836- p += sprintf(buf + p , "%c%.*" #FORMAT, sep, PREC, (STYPE)tile->payload[i]); \
836+ appendStringInfo(&str , "%c%.*" #FORMAT, sep, PREC, (STYPE)tile->payload[i]); \
837837}\
838838sep = ',';\
839839}\
840- strcpy(buf + p , "}"); \
841- PG_RETURN_CSTRING(pstrdup(buf)); \
842- }
840+ appendStringInfo(&str , "}");\
841+ PG_RETURN_CSTRING(str.data); \
842+ }
843843
844844
845845
@@ -2497,7 +2497,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
24972497char * sql ;
24982498char sep ;
24992499TupleDesc spi_tupdesc ;
2500- int i ,j ,n , n_attrs ;
2500+ int i ,j ,n_attrs ;
25012501vops_type_info * types ;
25022502Datum * values ;
25032503bool * nulls ;
@@ -2508,7 +2508,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
25082508int64 loaded ;
25092509bool type_checked = false;
25102510static Oid self_oid = InvalidOid ;
2511- char stmt [ MAX_SQL_STMT_LEN ] ;
2511+ StringInfoData stmt ;
25122512
25132513/* Detect case when extension is drop and created several times */
25142514if (fcinfo -> flinfo -> fn_oid != self_oid )
@@ -2533,7 +2533,8 @@ Datum vops_populate(PG_FUNCTION_ARGS)
25332533values = (Datum * )palloc (sizeof (Datum )* n_attrs );
25342534nulls = (bool * )palloc0 (sizeof (bool )* n_attrs );
25352535
2536- n = sprintf (stmt ,"select" );
2536+ initStringInfo (& stmt );
2537+ appendStringInfo (& stmt ,"select" );
25372538sep = ' ' ;
25382539spi_tupdesc = SPI_tuptable -> tupdesc ;
25392540for (i = 0 ;i < n_attrs ;i ++ ) {
@@ -2549,25 +2550,26 @@ Datum vops_populate(PG_FUNCTION_ARGS)
25492550elog (ERROR ,"Size of column %s is unknown" ,name );
25502551}
25512552}
2552- n += sprintf ( stmt + n ,"%c%s" ,sep ,name );
2553+ appendStringInfo ( & stmt ,"%c%s" ,sep ,name );
25532554sep = ',' ;
25542555SPI_freetuple (spi_tuple );
25552556}
25562557SPI_freetuptable (SPI_tuptable );
25572558
2558- n += sprintf ( stmt + n ," from %s.%s" ,
2559+ appendStringInfo ( & stmt ," from %s.%s" ,
25592560get_namespace_name (get_rel_namespace (source )),
25602561get_rel_name (source ));
25612562if (predicate && * predicate ) {
2562- n += sprintf ( stmt + n ," where %s" ,predicate );
2563+ appendStringInfo ( & stmt ," where %s" ,predicate );
25632564}
25642565if (sort && * sort ) {
2565- n += sprintf ( stmt + n ," order by %s" ,sort );
2566+ appendStringInfo ( & stmt ," order by %s" ,sort );
25662567}
2567- plan = SPI_prepare (stmt ,0 ,NULL );
2568+ plan = SPI_prepare (stmt . data ,0 ,NULL );
25682569if (plan == NULL )
25692570elog (ERROR ,"SPI_prepare(\"%s\") failed:%s" ,
2570- stmt ,SPI_result_code_string (SPI_result ));
2571+ stmt .data ,SPI_result_code_string (SPI_result ));
2572+ pfree (stmt .data );
25712573portal = SPI_cursor_open (NULL ,plan ,NULL ,NULL , true);
25722574
25732575begin_batch_insert (destination );