{"record":{"id":"151601bc800cff44","repo":"t8y2/dbx","slug":"sql-is-required","errorCode":null,"errorMessage":"SQL is required","messagePattern":"SQL is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/metadata.go","lineNumber":801,"sourceCode":"\t\t}\n\t\tlines := make([]string, 0, len(result.Rows))\n\t\tfor _, row := range result.Rows {\n\t\t\tif line := firstRowValue(row); line != \"\" {\n\t\t\t\tlines = append(lines, line)\n\t\t\t}\n\t\t}\n\t\tif len(lines) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\treturn strings.Join(lines, \"\\n\") + \"\\n\", nil\n\t}\n\treturn \"\", nil\n}\n\nfunc (server *server) getExplainInfo(sqlText string) (string, error) {\n\tsqlText = trimStatementSQL(sqlText)\n\tif sqlText == \"\" {\n\t\treturn \"\", errors.New(\"SQL is required\")\n\t}\n\tresult, err := server.executeQuery(queryOptions{SQL: \"EXPLAIN \" + sqlText, MaxRows: metadataQueryLimit})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tlines := make([]string, 0, len(result.Rows))\n\tfor _, row := range result.Rows {\n\t\tlines = append(lines, firstRowValue(row))\n\t}\n\treturn strings.Join(lines, \"\\n\"), nil\n}\n\nfunc (server *server) completionAssistantSearch(input completionAssistantRequest) (completionAssistantResponse, error) {\n\tmaxResults := input.MaxResults\n\tif maxResults <= 0 {\n\t\tmaxResults = 200\n\t}\n\tschemas := []string{firstNonEmpty(input.Schema, input.Database, server.config.Database)}","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/metadata.go#L783-L819","documentation":"getExplainInfo prefixes EXPLAIN to a SQL statement and executes it to capture the query plan. The statement text is trimmed (trimStatementSQL) and must be non-empty; an empty statement has nothing to explain, so this error is returned before touching the connection.","triggerScenarios":"Calling getExplainInfo with \"\", whitespace-only text, or a string that consists solely of comments/terminators that trimStatementSQL strips away.","commonSituations":"Client sends explain request with an empty editor buffer; the SQL variable was never populated from a template; statement contained only a comment ('-- hint') which trims to empty; copy-paste lost the query text.","solutions":["Provide the actual SQL statement text in the explain request","Check the input after trimming — statements made only of comments count as empty","Ensure the calling UI/tool passes the current query buffer, not a stale empty variable","Add client-side validation that the SQL field is non-blank before sending"],"exampleFix":"// before\nplan, err := server.getExplainInfo(userInput) // userInput = \"-- nothing\"\n// after\nif strings.TrimSpace(strings.TrimPrefix(userInput, \"--\")) == \"\" {\n    return errors.New(\"SQL is required\")\n}\nplan, err := server.getExplainInfo(userInput)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(strings.TrimPrefix(sqlText, \"--\")) == \"\" {\n    return errors.New(\"SQL is required\")\n}","typeGuard":null,"tryCatchPattern":"plan, err := server.getExplainInfo(sqlText)\nif err != nil && err.Error() == \"SQL is required\" {\n    return fmt.Errorf(\"cannot EXPLAIN empty statement\")\n}","preventionTips":["Validate the SQL buffer is non-empty in the client","Remember comment-only statements trim to empty and are rejected","Pass the live query text, not stale empty variables","Strip terminators carefully so real SQL is not lost"],"tags":["validation","explain","sql"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}