t8y2/dbx · error
sql is required
Error message
sql is required
What it means
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.
Source
Thrown at agents/drivers/iotdb/query.go:48
truncated bool
}
func (s *server) validateConnection() error {
values, err := s.queryValues("SHOW VERSION", "", 1, 0)
if err != nil {
return err
}
if len(values.Rows) == 0 {
return errors.New("IoTDB SHOW VERSION returned no rows")
}
return nil
}
func (s *server) executeQuery(options queryOptions) (queryResult, error) {
started := time.Now()
sql := trimStatementSQL(options.SQL)
if sql == "" {
return queryResult{}, errors.New("sql is required")
}
if !isQueryStatement(sql) {
if err := s.executeNonQuery(sql, effectiveDatabase(options), options.TimeoutSecs); err != nil {
return queryResult{}, err
}
return queryResult{
Columns: []string{},
ColumnTypes: []string{},
Rows: [][]any{},
AffectedRows: 0,
ExecutionTimeMS: time.Since(started).Milliseconds(),
}, nil
}
limit := options.MaxRows
if limit <= 0 {
limit = defaultMaxRows
}View on GitHub (pinned to c0390bff16)
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.
Example fix
// before
srv.executeQuery(queryOptions{SQL: " "})
// after
sql := strings.TrimSpace(userSQL)
if sql == "" { return errors.New("no statement given") }
srv.executeQuery(queryOptions{SQL: sql}) Defensive patterns
Strategy: validation
Validate before calling
sql := strings.TrimSpace(options.SQL)
if sql == "" {
return errors.New("refusing to query: empty SQL")
} Type guard
func hasSQL(options queryOptions) bool { return strings.TrimSpace(options.SQL) != "" } Try / catch
res, err := srv.executeQuery(opts)
if err != nil {
if strings.Contains(err.Error(), "sql is required") {
return fmt.Errorf("empty query: ensure the sql field is set before calling executeQuery")
}
return err
} Prevention
- 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.
When it happens
Trigger: Calling executeQuery with options.SQL empty or whitespace-only (spaces/newlines count as empty after trimming).
Common situations: Request builders that omit the sql field; UIs or scripts forwarding user input without checking it; queries built by string templates that interpolated nothing.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- SQL is empty
- runCommand requires a non-empty command document
- Index keys are required
- SQL is required
- SQL is required
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/1e687e5fa8bea07b.
Report an issue: GitHub.