handleFetchCursorExtended handles FETCH in the Extended Query protocol.
(p *portal)
| 441 | if !ok { |
| 442 | c.sendError("ERROR", "34000", fmt.Sprintf("cursor %q does not exist", p.stmt.cursorName)) |
| 443 | return |
| 444 | } |
| 445 | |
| 446 | // Open cursor on first FETCH |
| 447 | if cursor.rows == nil { |
| 448 | if err := c.openCursor(cursor); err != nil { |
| 449 | if c.isCallerCancellation(err) { |
| 450 | c.sendError("ERROR", "57014", "canceling statement due to user request") |
| 451 | } else { |
| 452 | c.sendError("ERROR", "42000", err.Error()) |
| 453 | } |
| 454 | c.setTxError() |
| 455 | return |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | howMany := p.stmt.fetchCount |
| 460 | |
| 461 | // MOVE: advance position without returning rows (mirrors the |
| 462 | // simple-protocol path in handleFetchCursor). |
| 463 | if p.stmt.cursorIsMove { |
| 464 | moveCount := int64(0) |
| 465 | for moveCount < howMany && cursor.rows.Next() { |
| 466 | // Read the row to advance position, but don't send it |
| 467 | values := make([]interface{}, len(cursor.cols)) |
| 468 | valuePtrs := make([]interface{}, len(cursor.cols)) |
| 469 | for i := range values { |
| 470 | valuePtrs[i] = &values[i] |
| 471 | } |
| 472 | _ = cursor.rows.Scan(valuePtrs...) |
| 473 | moveCount++ |
| 474 | } |
| 475 | _ = wire.WriteCommandComplete(c.writer, fmt.Sprintf("MOVE %d", moveCount)) |
| 476 | return |
| 477 | } |
| 478 | |
| 479 | // Send RowDescription if Describe wasn't already called |
| 480 | if !p.described && len(cursor.cols) > 0 { |
| 481 | if err := c.sendRowDescriptionWithFormats(cursor.cols, cursor.colTypes, p.resultFormats); err != nil { |
| 482 | return |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | // Stream rows |
| 487 | rowCount := int64(0) |
| 488 | for rowCount < howMany && cursor.rows.Next() { |
| 489 | values := make([]interface{}, len(cursor.cols)) |
| 490 | valuePtrs := make([]interface{}, len(cursor.cols)) |
| 491 | for i := range values { |
| 492 | valuePtrs[i] = &values[i] |
| 493 | } |
| 494 | |
| 495 | if err := cursor.rows.Scan(valuePtrs...); err != nil { |
| 496 | c.sendError("ERROR", "42000", err.Error()) |
| 497 | c.setTxError() |
| 498 | return |
| 499 | } |
| 500 |
no test coverage detected