{"record":{"id":"1edefc7401020ea0","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-dml-statement-w","errorCode":null,"errorMessage":"unable to execute DML statement: %w","messagePattern":"unable to execute DML statement: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/oracle/oracle.go","lineNumber":149,"sourceCode":"}\n\nfunc (s *Source) SourceType() string {\n\treturn SourceType\n}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) OracleDB() *sql.DB {\n\treturn s.DB\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any, readOnly bool) (any, error) {\n\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","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/oracle/oracle.go#L131-L167","documentation":"Returned by Source.RunSQL when a non-readOnly statement is executed with ExecContext and the Oracle driver reports an execution error. The statement reached the database (or attempted to) but failed to execute — SQL syntax errors, ORA-xxxxx errors, permission errors, or connection drops are wrapped here. It applies to INSERT/UPDATE/DELETE/DDL/PL-SQL executed through the execute-sql tool path.","triggerScenarios":"RunSQL(ctx, statement, params, readOnly=false) calling s.OracleDB().ExecContext where the driver returns an error: ORA-00942 table or view does not exist, ORA-00911 invalid character (e.g. trailing semicolon), ORA-01013 user requested cancel, ORA-01031 insufficient privileges, or parameter count/type mismatch.","commonSituations":"LLM-generated SQL containing a trailing semicolon (ORA-00911); querying a table without schema qualification or grants; referencing a dropped/renamed table; sending a parameterized statement with wrong number of placeholders; session killed by DBA or network interruption mid-execution.","solutions":["Inspect the wrapped ORA-xxxxx code; look up its meaning (e.g. ORA-00911 → remove trailing semicolon or invalid characters).","Run the exact statement in SQL Developer/sqlplus as the same user to confirm it is valid SQL, not a driver issue.","Verify the connected user has the required object privileges (SELECT/INSERT/etc.) and the object is schema-qualified if needed.","Check that the number of ? placeholders matches len(params).","If it was a transient network error, verify connectivity and retry the statement."],"exampleFix":"// before (LLM sent trailing semicolon → ORA-00911)\nstatement: \"UPDATE employees SET salary = salary * 1.1;\"\n// after\nstatement: \"UPDATE employees SET salary = salary * 1.1\"","handlingStrategy":"try-catch","validationCode":"// strip trailing semicolons and empty statements before invoking RunSQL\nstmt := strings.TrimSpace(statement)\nstmt = strings.TrimSuffix(stmt, \";\")\nif stmt == \"\" {\n\treturn fmt.Errorf(\"empty statement\")\n}","typeGuard":"func isDMLExecError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"unable to execute DML statement\")\n}","tryCatchPattern":"result, err := src.RunSQL(ctx, stmt, params, false)\nif err != nil {\n\tif isDMLExecError(err) {\n\t\tvar oraCode string\n\t\tif m := regexp.MustCompile(`ORA-\\d{5}`).FindStringSubmatch(err.Error()); m != nil {\n\t\t\toraCode = m[0]\n\t\t}\n\t\tlog.Printf(\"DML failed (%s): %v\", oraCode, err)\n\t\treturn fmt.Errorf(\"statement rejected by oracle (%s): %w\", oraCode, err)\n\t}\n\treturn err\n}","preventionTips":["Strip trailing semicolons from tool-supplied SQL (Oracle rejects them with ORA-00911).","Grant the toolbox user only the privileges it needs on exactly the intended objects.","Count placeholders and parameters before executing parameterized statements.","Log the wrapped ORA-xxxxx code for every failure to speed up diagnosis."],"tags":["oracle","sql","dml","execution"],"backgroundTag":"sql-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"}