mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix pg_prepared_statements.result_types for DML statements
Amendment to 84ad713cf8: Not all
prepared statements have a result descriptor.  As currently coded,
this would crash when reading pg_prepared_statements.  Make those
cases return null for result_types instead.  Also add a test case for
it.
			
			
This commit is contained in:
		@@ -684,15 +684,10 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
 | 
			
		||||
		while ((prep_stmt = hash_seq_search(&hash_seq)) != NULL)
 | 
			
		||||
		{
 | 
			
		||||
			TupleDesc	result_desc;
 | 
			
		||||
			Oid		   *result_types;
 | 
			
		||||
			Datum		values[8];
 | 
			
		||||
			bool		nulls[8];
 | 
			
		||||
 | 
			
		||||
			result_desc = prep_stmt->plansource->resultDesc;
 | 
			
		||||
			result_types = (Oid *) palloc(result_desc->natts * sizeof(Oid));
 | 
			
		||||
 | 
			
		||||
			for (int i = 0; i < result_desc->natts; i++)
 | 
			
		||||
				result_types[i] = result_desc->attrs[i].atttypid;
 | 
			
		||||
 | 
			
		||||
			MemSet(nulls, 0, sizeof(nulls));
 | 
			
		||||
 | 
			
		||||
@@ -701,7 +696,20 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
 | 
			
		||||
			values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
 | 
			
		||||
			values[3] = build_regtype_array(prep_stmt->plansource->param_types,
 | 
			
		||||
											prep_stmt->plansource->num_params);
 | 
			
		||||
			values[4] = build_regtype_array(result_types, result_desc->natts);
 | 
			
		||||
			if (result_desc)
 | 
			
		||||
			{
 | 
			
		||||
				Oid		   *result_types;
 | 
			
		||||
 | 
			
		||||
				result_types = (Oid *) palloc(result_desc->natts * sizeof(Oid));
 | 
			
		||||
				for (int i = 0; i < result_desc->natts; i++)
 | 
			
		||||
					result_types[i] = result_desc->attrs[i].atttypid;
 | 
			
		||||
				values[4] = build_regtype_array(result_types, result_desc->natts);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				/* no result descriptor (for example, DML statement) */
 | 
			
		||||
				nulls[4] = true;
 | 
			
		||||
			}
 | 
			
		||||
			values[5] = BoolGetDatum(prep_stmt->from_sql);
 | 
			
		||||
			values[6] = Int64GetDatumFast(prep_stmt->plansource->num_generic_plans);
 | 
			
		||||
			values[7] = Int64GetDatumFast(prep_stmt->plansource->num_custom_plans);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user