1 /* 2 * This file and its contents are licensed under the Timescale License. 3 * Please see the included NOTICE for copyright information and 4 * LICENSE-TIMESCALE for a copy of the license. 5 */ 6 #include <postgres.h> 7 #include <catalog/pg_type.h> 8 9 #include "export.h" 10 #include "compat/compat.h" 11 #include "remote/data_format.h" 12 #include "remote/stmt_params.h" 13 #include "test_utils.h" 14 15 TS_FUNCTION_INFO_V1(ts_test_stmt_params_format); 16 17 Datum ts_test_stmt_params_format(PG_FUNCTION_ARGS)18ts_test_stmt_params_format(PG_FUNCTION_ARGS) 19 { 20 StmtParams *params; 21 const int *formats; 22 int i; 23 TupleDesc tuple_desc; 24 List *target_attr_nums; 25 bool binary = PG_GETARG_BOOL(0); 26 Form_pg_attribute *attrs = palloc(sizeof(Form_pg_attribute) * 2); 27 attrs[0] = &(FormData_pg_attribute){ 28 .atttypid = INT4OID, 29 }; 30 attrs[1] = &(FormData_pg_attribute){ 31 .atttypid = BOOLOID, 32 }; 33 34 tuple_desc = CreateTupleDesc(2, attrs); 35 target_attr_nums = list_make2_int(1, 2); 36 37 params = stmt_params_create(target_attr_nums, false, tuple_desc, 2); 38 formats = stmt_params_formats(params); 39 TestAssertTrue(stmt_params_num_params(params) == 2); 40 if (binary) 41 for (i = 0; i < 4; i++) 42 TestAssertTrue(formats[i] == FORMAT_BINARY); 43 else 44 for (i = 0; i < 4; i++) 45 TestAssertTrue(formats[i] == FORMAT_TEXT); 46 47 PG_RETURN_VOID(); 48 } 49