t8y2/dbx · error

SQL is required

Error message

SQL is required

What it means

executeQuery() normalizes options.SQL with trimStatementSQL and rejects empty statements before acquiring a connection. Any dispatch-style query with blank SQL fails immediately with "SQL is required" — a request-shape validation error, not a server error.

Source

Thrown at agents/drivers/hive-go/query.go:33

func (server *server) validateConnection() error {
	connection, err := server.requireConnection()
	if err != nil {
		return err
	}
	ctx, cancel := context.WithTimeout(context.Background(), server.config.ConnectTimeout)
	defer cancel()
	return connection.PingContext(ctx)
}

func (server *server) executeQuery(options queryOptions) (queryResult, error) {
	started := time.Now()
	if options.FetchSize <= 0 {
		options.FetchSize = server.effectiveFetchSize()
	}
	sqlText := trimStatementSQL(options.SQL)
	if sqlText == "" {
		return queryResult{}, errors.New("SQL is required")
	}
	maxRows := options.MaxRows
	if maxRows <= 0 {
		maxRows = defaultMaxRows
	}
	connection, err := server.requireConnection()
	if err != nil {
		return queryResult{}, err
	}

	ctx, cancel := queryContext(options.TimeoutSecs)
	server.setActiveOperation(cancel)
	defer server.clearActiveOperation(cancel)
	if err := server.applySchemaContext(ctx, connection, effectiveSchema(options)); err != nil {
		return queryResult{}, err
	}
	rows, affected, hasResultSet, err := executeHiveStatement(ctx, connection, sqlText, options.FetchSize)
	if err != nil {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Set a non-empty SQL string in queryOptions before calling executeQuery.
  2. Validate/trim the SQL in your caller and return a client-side error when blank.
  3. Check the code path that builds queryOptions for listDatabases/listTables etc. — a config field feeding the probe query may be empty.
  4. Ensure trimStatementSQL isn't unexpectedly emptying statements that are comment-only.

Example fix

// before
res, err := executeQuery(queryOptions{SQL: ""})
// after
sql := strings.TrimSpace(userSQL)
if sql == "" {
    return errors.New("please provide a SQL statement")
}
res, err := executeQuery(queryOptions{SQL: sql})
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(sql) == "" {
    return errors.New("SQL statement is required")
}

Try / catch

res, err := srv.Dispatch(queryOptions{SQL: sql})
if err != nil && strings.Contains(err.Error(), "SQL is required") {
    return fmt.Errorf("empty query rejected: check SQL builder output")
}

Prevention

When it happens

Trigger: Calling executeQuery (directly or via dispatch, connectionInfo, listDatabases, listTables, listRoutines, getColumns paths) with options.SQL empty, whitespace-only, or containing only content that trims away.

Common situations: Template-driven SQL builders emitting empty strings when parameters are missing; request handlers forwarding empty body SQL; connectionInfo built from a config where the probe query variable is unset.

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/74d3f195f6168c63. Report an issue: GitHub.