@@ -823,23 +823,23 @@ static bool is_vops_type(Oid typeid)
823
823
Datum vops_##TYPE##_output(PG_FUNCTION_ARGS) \
824
824
{ \
825
825
vops_##TYPE* tile = (vops_##TYPE*)PG_GETARG_POINTER(0); \
826
- char buf[MAX_TILE_STRLEN]; \
827
- int p = 0; \
826
+ StringInfoData str; \
828
827
char sep = '{'; \
829
828
int i; \
829
+ initStringInfo(&str); \
830
830
for (i = 0; i < TILE_SIZE; i++) { \
831
831
if (tile->hdr.empty_mask & ((uint64)1 << i)) { \
832
- p += sprintf(buf + p , "%c", sep); \
832
+ appendStringInfo(&str , "%c", sep); \
833
833
} else if (tile->hdr.null_mask & ((uint64)1 << i)) { \
834
- p += sprintf(buf + p , "%c?", sep); \
834
+ appendStringInfo(&str , "%c?", sep); \
835
835
} 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]); \
837
837
} \
838
838
sep = ','; \
839
839
} \
840
- strcpy(buf + p , "}"); \
841
- PG_RETURN_CSTRING(pstrdup(buf)); \
842
- }
840
+ appendStringInfo(&str , "}"); \
841
+ PG_RETURN_CSTRING(str.data); \
842
+ }
843
843
844
844
845
845
@@ -2497,7 +2497,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
2497
2497
char * sql ;
2498
2498
char sep ;
2499
2499
TupleDesc spi_tupdesc ;
2500
- int i , j , n , n_attrs ;
2500
+ int i , j , n_attrs ;
2501
2501
vops_type_info * types ;
2502
2502
Datum * values ;
2503
2503
bool * nulls ;
@@ -2508,7 +2508,7 @@ Datum vops_populate(PG_FUNCTION_ARGS)
2508
2508
int64 loaded ;
2509
2509
bool type_checked = false;
2510
2510
static Oid self_oid = InvalidOid ;
2511
- char stmt [ MAX_SQL_STMT_LEN ] ;
2511
+ StringInfoData stmt ;
2512
2512
2513
2513
/* Detect case when extension is drop and created several times */
2514
2514
if (fcinfo -> flinfo -> fn_oid != self_oid )
@@ -2533,7 +2533,8 @@ Datum vops_populate(PG_FUNCTION_ARGS)
2533
2533
values = (Datum * )palloc (sizeof (Datum )* n_attrs );
2534
2534
nulls = (bool * )palloc0 (sizeof (bool )* n_attrs );
2535
2535
2536
- n = sprintf (stmt , "select" );
2536
+ initStringInfo (& stmt );
2537
+ appendStringInfo (& stmt , "select" );
2537
2538
sep = ' ' ;
2538
2539
spi_tupdesc = SPI_tuptable -> tupdesc ;
2539
2540
for (i = 0 ; i < n_attrs ; i ++ ) {
@@ -2549,25 +2550,26 @@ Datum vops_populate(PG_FUNCTION_ARGS)
2549
2550
elog (ERROR , "Size of column %s is unknown" , name );
2550
2551
}
2551
2552
}
2552
- n += sprintf ( stmt + n , "%c%s" , sep , name );
2553
+ appendStringInfo ( & stmt , "%c%s" , sep , name );
2553
2554
sep = ',' ;
2554
2555
SPI_freetuple (spi_tuple );
2555
2556
}
2556
2557
SPI_freetuptable (SPI_tuptable );
2557
2558
2558
- n += sprintf ( stmt + n , " from %s.%s" ,
2559
+ appendStringInfo ( & stmt , " from %s.%s" ,
2559
2560
get_namespace_name (get_rel_namespace (source )),
2560
2561
get_rel_name (source ));
2561
2562
if (predicate && * predicate ) {
2562
- n += sprintf ( stmt + n , " where %s" , predicate );
2563
+ appendStringInfo ( & stmt , " where %s" , predicate );
2563
2564
}
2564
2565
if (sort && * sort ) {
2565
- n += sprintf ( stmt + n , " order by %s" , sort );
2566
+ appendStringInfo ( & stmt , " order by %s" , sort );
2566
2567
}
2567
- plan = SPI_prepare (stmt , 0 , NULL );
2568
+ plan = SPI_prepare (stmt . data , 0 , NULL );
2568
2569
if (plan == NULL )
2569
2570
elog (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 );
2571
2573
portal = SPI_cursor_open (NULL , plan , NULL , NULL , true);
2572
2574
2573
2575
begin_batch_insert (destination );
0 commit comments