{"record":{"id":"32c1850c8e280926","repo":"googleapis/mcp-toolbox","slug":"query-execution-error-w","errorCode":null,"errorMessage":"query execution error: %w","messagePattern":"query execution error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/oracle/oracle.go","lineNumber":177,"sourceCode":"\t\t\t\"rows_affected\": rowsAffected,\n\t\t}, nil\n\t}\n\trows, err := s.OracleDB().QueryContext(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\t// If Columns() errors, it might be a DDL/DML without an OUTPUT clause.\n\t// We proceed, and results.Err() will catch actual query execution errors.\n\t// 'out' will remain an empty slice if cols is empty or err is not nil here.\n\tcols, _ := rows.Columns()\n\n\t// Get Column types\n\tcolTypes, err := rows.ColumnTypes()\n\tif err != nil {\n\t\tif err := rows.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"query execution error: %w\", err)\n\t\t}\n\t\treturn []any{}, nil\n\t}\n\n\tout := []any{}\n\tfor rows.Next() {\n\t\tvalues := make([]any, len(cols))\n\t\tfor i, colType := range colTypes {\n\t\t\tswitch strings.ToUpper(colType.DatabaseTypeName()) {\n\t\t\tcase \"NUMBER\", \"FLOAT\", \"BINARY_FLOAT\", \"BINARY_DOUBLE\":\n\t\t\t\tif _, scale, ok := colType.DecimalSize(); ok && scale == 0 {\n\t\t\t\t\t// Scale is 0, treat it as an integer.\n\t\t\t\t\tvalues[i] = new(sql.NullInt64)\n\t\t\t\t} else {\n\t\t\t\t\t// Scale is non-zero or unknown, treat\n\t\t\t\t\t// it as a float.\n\t\t\t\t\tvalues[i] = new(sql.NullFloat64)\n\t\t\t\t}","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/oracle/oracle.go#L159-L195","documentation":"This error wraps a failure surfaced by database/sql's rows.Err() after rows.ColumnTypes() failed in the Oracle RunSQL read path. ColumnTypes() fails when the driver cannot describe the result set, which usually means the query failed during execution or the result set was already consumed/errored. The code first checks rows.Err() to distinguish a real query error from an empty/undescribable result; only a non-nil rows.Err() becomes this error.","triggerScenarios":"Calling RunSQL with readOnly=true where the query's result set becomes invalid mid-flight: the connection dropped while rows were being described, the query was canceled via context, or the driver failed to report column types because the server aborted the cursor (e.g. ORA-ORA-01722 mid-cursor, session killed, network reset).","commonSituations":"Long-running queries hitting Oracle session timeouts or firewall idle disconnects; context deadlines canceled while the query executes; TAF/connection failover breaking an open cursor; network instability between the MCP Toolbox server and the database.","solutions":["Inspect the wrapped %w cause in the error chain — it contains the driver's ORA- error code; address that root cause directly.","Increase context timeout or adjust query so it completes within the deadline if the cause is context cancellation.","Check network stability and Oracle session/idle timeout settings (SQLNET.EXPIRE_TIME, firewall idle limits) if disconnects recur.","Verify driver health: try the query in SQL*Plus or SQL Developer with the same user to confirm it runs server-side.","If using go-ora, consider UseOCI: true (godror) to rule out driver-specific cursor handling bugs."],"exampleFix":"// before\ncols, _ := rows.Columns()\ncolTypes, err := rows.ColumnTypes()\n\n// after: check rows.Err() first and add a sane timeout\nctx, cancel := context.WithTimeout(ctx, 30*time.Second)\ndefer cancel()\nrows, err := db.QueryContext(ctx, statement, params...)\nif err != nil { return nil, fmt.Errorf(\"unable to execute query: %w\", err) }","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"oracle connection unhealthy before query: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"out, err := source.RunSQL(ctx, stmt, params, true)\nvar qeErr *fmt.wrapError\nif err != nil && errors.As(err, &qeErr) && isRetryable(err) {\n    time.Sleep(backoff)\n    out, err = source.RunSQL(ctx, stmt, params, true)\n}\nif err != nil { return err }","preventionTips":["Always pass a context with an explicit, generous timeout to RunSQL.","Validate queries in SQL Developer against the same account before wiring them into tools.","Monitor network stability and configure Oracle keepalives for long queries.","Retry idempotent read-only queries on transient disconnect errors."],"tags":["oracle","database-sql","query-execution","network"],"backgroundTag":"query-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}