MCPcopy Create free account
hub / github.com/apecloud/myduckserver / handleQuery

Method handleQuery

pgserver/connection_handler.go:451–504  ·  view source on GitHub ↗

handleQuery handles a query message, and returns a boolean flag, |endOfMessages| indicating if no other messages are expected as part of this query, in which case the server will send a READY FOR QUERY message back to the client so that it can send its next query.

(message *pgproto3.Query)

Source from the content-addressed store, hash-verified

449// expected as part of this query, in which case the server will send a READY FOR QUERY message back to the client so
450// that it can send its next query.
451func (h *ConnectionHandler) handleQuery(message *pgproto3.Query) (endOfMessages bool, err error) {
452 // usql use ";" to test if the connection is alive. If we don't handle it, this will return an error. So we need to
453 // manually handle it here.
454 if message.String == ";" {
455 err := h.send(makeCommandComplete("", 0))
456 if err != nil {
457 return true, err
458 }
459 return true, nil
460 }
461
462 handled, err := h.handledPSQLCommands(message.String)
463 if handled || err != nil {
464 return true, err
465 }
466
467 // TODO: Remove this once we support `SELECT * FROM function()` syntax
468 // Github issue: https://github.com/dolthub/doltgresql/issues/464
469 handled, err = h.handledWorkbenchCommands(message.String)
470 if handled || err != nil {
471 return true, err
472 }
473
474 statements, err := h.convertQuery(message.String)
475 if err != nil {
476 return true, err
477 }
478
479 // A query message destroys the unnamed statement and the unnamed portal
480 h.deletePreparedStatement("")
481 h.deletePortal("")
482
483 for _, statement := range statements {
484 statement.IsExtendedQuery = false
485 // Certain statement types get handled directly by the handler instead of being passed to the engine
486 handled, endOfMessages, err = h.handleStatementOutsideEngine(statement)
487 if handled {
488 if err != nil {
489 h.logger.Warnf("Failed to handle statement %v outside engine: %v", statement, err)
490 return true, err
491 }
492 } else {
493 if err != nil {
494 h.logger.Warnf("Failed to handle statement %v outside engine: %v", statement, err)
495 }
496 endOfMessages, err = true, h.run(statement)
497 if err != nil {
498 return true, err
499 }
500 }
501 }
502
503 return endOfMessages, nil
504}
505
506// handleStatementOutsideEngine handles any queries that should be handled by the handler directly, rather than being
507// passed to the engine. The response parameter |handled| is true if the query was handled, |endOfMessages| is true

Callers 1

handleMessageMethod · 0.95

Calls 9

sendMethod · 0.95
handledPSQLCommandsMethod · 0.95
convertQueryMethod · 0.95
deletePortalMethod · 0.95
runMethod · 0.95
makeCommandCompleteFunction · 0.85

Tested by

no test coverage detected