Skip to content

Commit 6273188

Browse files
jackcclaude
andcommitted
Fix batch result format corruption when using cached prepared statements
Copy ResultFormats slice before passing to SendQueryStatement, which stores it for later use. The extended query builder reuses the backing array on the next loop iteration, corrupting format codes stored for earlier queries in the batch. Fixes the bug exposed by the test in jackc#2524. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f7b90c2 commit 6273188

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

conn.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,11 @@ func (c *Conn) sendBatchExtendedWithDescription(ctx context.Context, b *Batch, d
12351235
if bi.sd.Name == "" {
12361236
pipeline.SendQueryParams(bi.sd.SQL, c.eqb.ParamValues, bi.sd.ParamOIDs, c.eqb.ParamFormats, c.eqb.ResultFormats)
12371237
} else {
1238-
pipeline.SendQueryStatement(bi.sd, c.eqb.ParamValues, c.eqb.ParamFormats, c.eqb.ResultFormats)
1238+
// Copy ResultFormats because SendQueryStatement stores the slice for later use, and eqb.Build reuses the
1239+
// backing array on the next iteration.
1240+
resultFormats := make([]int16, len(c.eqb.ResultFormats))
1241+
copy(resultFormats, c.eqb.ResultFormats)
1242+
pipeline.SendQueryStatement(bi.sd, c.eqb.ParamValues, c.eqb.ParamFormats, resultFormats)
12391243
}
12401244
}
12411245

0 commit comments

Comments
 (0)