(ctx context.Context, b *Batch, distinctNewQueries []*pgconn.StatementDescription, sdCache stmtcache.Cache)
| 1156 | } |
| 1157 | |
| 1158 | func (c *Conn) sendBatchExtendedWithDescription(ctx context.Context, b *Batch, distinctNewQueries []*pgconn.StatementDescription, sdCache stmtcache.Cache) (pbr *pipelineBatchResults) { |
| 1159 | pipeline := c.pgConn.StartPipeline(ctx) |
| 1160 | defer func() { |
| 1161 | if pbr != nil && pbr.err != nil { |
| 1162 | pipeline.Close() |
| 1163 | } |
| 1164 | }() |
| 1165 | |
| 1166 | // Prepare any needed queries |
| 1167 | if len(distinctNewQueries) > 0 { |
| 1168 | err := func() (err error) { |
| 1169 | for _, sd := range distinctNewQueries { |
| 1170 | pipeline.SendPrepare(sd.Name, sd.SQL, nil) |
| 1171 | } |
| 1172 | |
| 1173 | // Store all statements we are preparing into the cache. It's fine if it overflows because HandleInvalidated will |
| 1174 | // clean them up later. |
| 1175 | if sdCache != nil { |
| 1176 | for _, sd := range distinctNewQueries { |
| 1177 | sdCache.Put(sd) |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | // If something goes wrong preparing the statements, we need to invalidate the cache entries we just added. |
| 1182 | defer func() { |
| 1183 | if err != nil && sdCache != nil { |
| 1184 | for _, sd := range distinctNewQueries { |
| 1185 | sdCache.Invalidate(sd.SQL) |
| 1186 | } |
| 1187 | } |
| 1188 | }() |
| 1189 | |
| 1190 | err = pipeline.Sync() |
| 1191 | if err != nil { |
| 1192 | return err |
| 1193 | } |
| 1194 | |
| 1195 | for _, sd := range distinctNewQueries { |
| 1196 | results, err := pipeline.GetResults() |
| 1197 | if err != nil { |
| 1198 | return newErrPreprocessingBatch("prepare", sd.SQL, err) |
| 1199 | } |
| 1200 | |
| 1201 | resultSD, ok := results.(*pgconn.StatementDescription) |
| 1202 | if !ok { |
| 1203 | return fmt.Errorf("expected statement description, got %T", results) |
| 1204 | } |
| 1205 | |
| 1206 | // Fill in the previously empty / pending statement descriptions. |
| 1207 | sd.ParamOIDs = resultSD.ParamOIDs |
| 1208 | sd.Fields = resultSD.Fields |
| 1209 | } |
| 1210 | |
| 1211 | results, err := pipeline.GetResults() |
| 1212 | if err != nil { |
| 1213 | return err |
| 1214 | } |
| 1215 |
no test coverage detected