{"record":{"id":"06768c7f62901f42","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-06768c","errorCode":null,"errorMessage":"unable to execute query: %w","messagePattern":"unable to execute query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/oracle/oracle.go","lineNumber":164,"sourceCode":"\tif !readOnly {\n\t\tresult, err := s.OracleDB().ExecContext(ctx, statement, params...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to execute DML statement: %w\", err)\n\t\t}\n\n\t\trowsAffected, err := result.RowsAffected()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to get rows affected: %w\", err)\n\t\t}\n\n\t\treturn map[string]any{\n\t\t\t\"status\":        \"success\",\n\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{}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/oracle/oracle.go#L146-L182","documentation":"Returned by Source.RunSQL on the readOnly path when QueryContext fails to run a SELECT statement. The query could not be executed at all — bad SQL syntax, missing privileges, invalid identifiers, or a connection failure — so no result rows are produced. All of these causes are wrapped under this single message with the ORA-xxxxx error preserved via %w.","triggerScenarios":"RunSQL(ctx, statement, params, readOnly=true) calling s.OracleDB().QueryContext where the driver errors: ORA-00942 table does not exist, ORA-00904 invalid identifier, ORA-00933/00923 syntax errors, ORA-01031 insufficient privileges, or context cancellation/timeouts.","commonSituations":"LLM-generated SELECTs with typos in column or table names; querying views the user has no grants on; dialect mistakes (e.g. MySQL LIMIT syntax instead of FETCH FIRST); statement timeout exceeded on large scans; connection dropped before query dispatch.","solutions":["Read the wrapped ORA-xxxxx code to identify the exact cause (invalid identifier, missing table, privilege, etc.).","Run the same SELECT in sqlplus/SQL Developer as the same DB user to validate syntax and grants.","Fix Oracle dialect issues: use FETCH FIRST n ROWS ONLY instead of LIMIT; qualify objects with the owning schema.","Grant SELECT on the referenced tables/views to the toolbox user if ORA-00942/01031 appears.","For timeouts, tune the query or increase the context deadline / add appropriate indexes."],"exampleFix":"// before (MySQL syntax → ORA-00933)\nstatement: \"SELECT * FROM employees ORDER BY hire_date LIMIT 10\"\n// after (Oracle dialect)\nstatement: \"SELECT * FROM employees ORDER BY hire_date FETCH FIRST 10 ROWS ONLY\"","handlingStrategy":"try-catch","validationCode":"// catch common Oracle-dialect mistakes before executing\ns := strings.ToLower(statement)\nif regexp.MustCompile(`\\blimit\\s+\\d+`).MatchString(s) {\n\treturn fmt.Errorf(\"Oracle uses FETCH FIRST n ROWS ONLY, not LIMIT\")\n}","typeGuard":"func isQueryExecError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"unable to execute query\")\n}","tryCatchPattern":"rows, err := src.RunSQL(ctx, stmt, params, true)\nif err != nil {\n\tif isQueryExecError(err) {\n\t\tswitch {\n\t\tcase strings.Contains(err.Error(), \"ORA-00942\"):\n\t\t\treturn fmt.Errorf(\"table or view not found; check schema qualification and grants: %w\", err)\n\t\tcase strings.Contains(err.Error(), \"ORA-00904\"):\n\t\t\treturn fmt.Errorf(\"invalid column name in query: %w\", err)\n\t\tcase errors.Is(err, context.DeadlineExceeded):\n\t\t\treturn fmt.Errorf(\"query timed out; optimize or raise deadline: %w\", err)\n\t\t}\n\t\treturn err\n\t}\n\treturn err\n}","preventionTips":["Prefer readOnly=true for all SELECT workloads so queries stay on the query path.","Verify table/column names and grants with the same DB user before exposing tools to LLMs.","Use Oracle dialect (FETCH FIRST, dual, etc.) in any hand-written or generated SQL.","Set sane statement timeouts and add indexes for large scans to avoid context cancellation."],"tags":["oracle","sql","query","select"],"backgroundTag":"sql-query-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"}