MCPcopy Create free account
hub / github.com/PostHog/duckgres / handleFetchCursorExtended

Method handleFetchCursorExtended

server/conn_cursor.go:443–522  ·  view source on GitHub ↗

handleFetchCursorExtended handles FETCH in the Extended Query protocol.

(p *portal)

Source from the content-addressed store, hash-verified

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

Callers 1

handleExecuteMethod · 0.95

Calls 12

sendErrorMethod · 0.95
openCursorMethod · 0.95
isCallerCancellationMethod · 0.95
setTxErrorMethod · 0.95
writeCommandCompleteMethod · 0.95
WriteCommandCompleteFunction · 0.92
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected