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

  1. Provide a non-empty SQL string in the query options before calling.
  2. Trim/validate the SQL at the call site and skip the call if it is blank.
  3. 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

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


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/1e687e5fa8bea07b. Report an issue: GitHub.