{"record":{"id":"f1560e8bb868c5e0","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-f1560e","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/mindsdb/mindsdb.go","lineNumber":114,"sourceCode":"}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) MindsDBPool() *sql.DB {\n\treturn s.Pool\n}\n\nfunc (s *Source) MySQLPool() *sql.DB {\n\treturn s.Pool\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {\n\t// MindsDB now supports MySQL prepared statements natively\n\tresults, err := s.MindsDBPool().QueryContext(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\n\tcols, err := results.Columns()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to retrieve rows column name: %w\", err)\n\t}\n\n\t// create an array of values for each column, which can be re-used to scan each row\n\trawValues := make([]any, len(cols))\n\tvalues := make([]any, len(cols))\n\tfor i := range rawValues {\n\t\tvalues[i] = &rawValues[i]\n\t}\n\tdefer results.Close()\n\n\tcolTypes, err := results.ColumnTypes()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get column types: %w\", err)","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mindsdb/mindsdb.go#L96-L132","documentation":"RunSQL executes the statement through the pool with QueryContext (MindsDB supports MySQL prepared statements natively). Any driver- or server-level failure during execution is wrapped as \"unable to execute query\". This covers syntax errors, unknown tables/models, permission failures, and context cancellations.","triggerScenarios":"s.MindsDBPool().QueryContext(ctx, statement, params...) returns a non-nil error: SQL syntax error, unknown MindsDB model/table, parameter count mismatch, or ctx cancelled/timed out mid-query.","commonSituations":"Queries referencing a MindsDB model or database that doesn't exist; wrong number of ? placeholders vs params; long-running predictions hitting the query timeout; SQL that MySQL grammar rejects.","solutions":["Check the wrapped driver error text for the underlying MySQL/MindsDB error code and message","Validate the statement in a MindsDB SQL client before wiring it into the tool config","Match the number of ? placeholders with the params slice length","Increase query timeout if long-running MindsDB predictions hit the context deadline"],"exampleFix":"// before\nparams: [\"model_a\"]\nstatement: \"SELECT * FROM mindsdb.??\"  # placeholder mismatch\n// after\nstatement: \"SELECT * FROM mindsdb.model_a\"\nparams: []","handlingStrategy":"try-catch","validationCode":"var exists int\nerr := pool.QueryRowContext(ctx, \"SHOW TABLES IN mindsdb LIKE ?\", modelName).Scan(&exists)\n_ = exists // validate model/table existence before running queries against it","typeGuard":null,"tryCatchPattern":"results, err := pool.QueryContext(ctx, statement, params...)\nif err != nil {\n    var mysqlErr *mysql.MySQLError\n    if errors.As(err, &mysqlErr) {\n        switch mysqlErr.Number {\n        case 1146: // unknown table/model\n        case 1064: // syntax error\n        }\n    }\n    if errors.Is(err, context.DeadlineExceeded) { /* raise timeout */ }\n    return err\n}","preventionTips":["Test statements in the MindsDB SQL editor before adding them to tool configs","Keep placeholder (?) count in sync with params length","Set realistic query timeouts for long-running predictions"],"tags":["mindsdb","sql","query-execution","mysql"],"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"}