googleapis/mcp-toolbox · error

unable to execute query: %w

Error message

unable to execute query: %w

What it means

Wraps the database/sql error returned by QueryContext when executing a statement against the Firebird pool in RunSQL. This includes Firebird SQL syntax errors, permission failures, and driver-level connection errors at query time.

Source

Thrown at internal/sources/firebird/firebird.go:107

	return false
}

func (s *Source) SourceType() string {
	return SourceType
}

func (s *Source) ToConfig() sources.SourceConfig {
	return s.Config
}

func (s *Source) FirebirdDB() *sql.DB {
	return s.Db
}

func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
	rows, err := s.FirebirdDB().QueryContext(ctx, statement, params...)
	if err != nil {
		return nil, fmt.Errorf("unable to execute query: %w", err)
	}
	defer rows.Close()

	cols, err := rows.Columns()
	if err != nil {
		return nil, fmt.Errorf("unable to get columns: %w", err)
	}

	values := make([]any, len(cols))
	scanArgs := make([]any, len(values))
	for i := range values {
		scanArgs[i] = &values[i]
	}

	out := []any{}
	for rows.Next() {

		err = rows.Scan(scanArgs...)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Run the statement in isql with the same user to get the native Firebird error (ISC code)
  2. Check Firebird dialect compatibility of the SQL syntax (e.g. use FIRST n SKIP m instead of LIMIT)
  3. Verify the table/column exists and the user has SELECT privilege
  4. Test parameters count/placeholders match the statement

Example fix

// before
rows, err := s.FirebirdDB().QueryContext(ctx, statement, params...)
if err != nil {
    return nil, fmt.Errorf("unable to execute query: %w", err)
}
// after
rows, err := s.FirebirdDB().QueryContext(ctx, statement, params...)
if err != nil {
    var fbErr *retriableError
    if errors.As(err, &fbErr) {
        return nil, fmt.Errorf("unable to execute query (transient): %w", err)
    }
    return nil, fmt.Errorf("unable to execute query: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate statement is non-empty before invoking
if strings.TrimSpace(statement) == "" { return errors.New("empty SQL statement") }

Type guard

func isFirebirdSyntaxErr(err error) bool {
    return strings.Contains(err.Error(), "Dynamic SQL Error") || strings.Contains(err.Error(), "Token unknown")
}

Try / catch

rows, err := s.FirebirdDB().QueryContext(ctx, statement, params...)
if err != nil {
    if isFirebirdSyntaxErr(err) {
        return nil, fmt.Errorf("invalid Firebird SQL: %w", err)
    }
    if ctx.Err() != nil {
        return nil, fmt.Errorf("query cancelled: %w", ctx.Err())
    }
    return nil, fmt.Errorf("unable to execute query: %w", err)
}

Prevention

When it happens

Trigger: RunSQL called with a statement that is invalid Firebird SQL, references a missing table/column, uses unsupported parameter placeholders, or the pooled connection has been dropped (server restart, ConnMaxLifetime expiry race).

Common situations: MySQL/Postgres-style syntax (LIMIT, double quotes) used against Firebird dialect; missing table in the configured database; user lacking SELECT grants; stale connections after server restart; passing named parameters where positional ? expected.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/578088546402b3ce. Report an issue: GitHub.