{"record":{"id":"1e687e5fa8bea07b","repo":"t8y2/dbx","slug":"sql-is-required-1e687e","errorCode":null,"errorMessage":"sql is required","messagePattern":"sql is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/iotdb/query.go","lineNumber":48,"sourceCode":"\ttruncated bool\n}\n\nfunc (s *server) validateConnection() error {\n\tvalues, err := s.queryValues(\"SHOW VERSION\", \"\", 1, 0)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(values.Rows) == 0 {\n\t\treturn errors.New(\"IoTDB SHOW VERSION returned no rows\")\n\t}\n\treturn nil\n}\n\nfunc (s *server) executeQuery(options queryOptions) (queryResult, error) {\n\tstarted := time.Now()\n\tsql := trimStatementSQL(options.SQL)\n\tif sql == \"\" {\n\t\treturn queryResult{}, errors.New(\"sql is required\")\n\t}\n\tif !isQueryStatement(sql) {\n\t\tif err := s.executeNonQuery(sql, effectiveDatabase(options), options.TimeoutSecs); err != nil {\n\t\t\treturn queryResult{}, err\n\t\t}\n\t\treturn queryResult{\n\t\t\tColumns:         []string{},\n\t\t\tColumnTypes:     []string{},\n\t\t\tRows:            [][]any{},\n\t\t\tAffectedRows:    0,\n\t\t\tExecutionTimeMS: time.Since(started).Milliseconds(),\n\t\t}, nil\n\t}\n\n\tlimit := options.MaxRows\n\tif limit <= 0 {\n\t\tlimit = defaultMaxRows\n\t}","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/iotdb/query.go#L30-L66","documentation":"Returned by server.executeQuery in the IoTDB driver when, after trimStatementSQL, the SQL text is empty. The query entry point requires at least one non-whitespace statement; an empty 'sql' field or a whitespace/semicolon-only string triggers this validation before any statement classification or execution.","triggerScenarios":"Calling executeQuery with options.SQL empty or whitespace-only (spaces/newlines count as empty after trimming).","commonSituations":"Request builders that omit the sql field; UIs or scripts forwarding user input without checking it; queries built by string templates that interpolated nothing.","solutions":["Provide a non-empty SQL string in the query options before calling.","Trim/validate the SQL at the call site and skip the call if it is blank.","Fix the code path that builds options.SQL so it always populates the statement."],"exampleFix":"// before\nsrv.executeQuery(queryOptions{SQL: \"   \"})\n// after\nsql := strings.TrimSpace(userSQL)\nif sql == \"\" { return errors.New(\"no statement given\") }\nsrv.executeQuery(queryOptions{SQL: sql})","handlingStrategy":"validation","validationCode":"sql := strings.TrimSpace(options.SQL)\nif sql == \"\" {\n\treturn errors.New(\"refusing to query: empty SQL\")\n}","typeGuard":"func hasSQL(options queryOptions) bool { return strings.TrimSpace(options.SQL) != \"\" }","tryCatchPattern":"res, err := srv.executeQuery(opts)\nif err != nil {\n\tif strings.Contains(err.Error(), \"sql is required\") {\n\t\treturn fmt.Errorf(\"empty query: ensure the sql field is set before calling executeQuery\")\n\t}\n\treturn err\n}","preventionTips":["Validate/trim user-supplied SQL before building queryOptions.","Guard template-driven query builders against interpolating empty strings.","Add unit tests asserting the sql field is populated for every request path."],"tags":["iotdb","sql","validation","empty-input"],"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"}