{"record":{"id":"4179016f943a2442","repo":"googleapis/mcp-toolbox","slug":"unable-to-prepare-statement-w","errorCode":null,"errorMessage":"unable to prepare statement: %w","messagePattern":"unable to prepare statement: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigtable/bigtable.go","lineNumber":180,"sourceCode":"\t\t}\n\t\tbtParamTypes[p.GetName()] = paramType\n\t}\n\treturn btParamTypes, nil\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, configParam parameters.Parameters, params parameters.ParamValues) (any, error) {\n\tmapParamsType, err := getMapParamsType(configParam)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"fail to get map params: %w\", err)\n\t}\n\n\tps, err := s.BigtableClient().PrepareStatement(\n\t\tctx,\n\t\tstatement,\n\t\tmapParamsType,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to prepare statement: %w\", err)\n\t}\n\n\tbs, err := ps.Bind(params.AsMap())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to bind: %w\", err)\n\t}\n\n\tout := []any{}\n\tvar rowErr error\n\terr = bs.Execute(ctx, func(resultRow bigtable.ResultRow) bool {\n\t\tvMap := make(map[string]any)\n\t\tcols := resultRow.Metadata.Columns\n\n\t\tfor _, c := range cols {\n\t\t\tvar columValue any\n\t\t\tif err = resultRow.GetByName(c.Name, &columValue); err != nil {\n\t\t\t\trowErr = err\n\t\t\t\treturn false","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigtable/bigtable.go#L162-L198","documentation":"The Bigtable client's PrepareStatement failed while compiling the SQL statement with the computed parameter type map. Bigtable SQL (via the client library) rejects statements it cannot parse or whose parameter placeholders don't match the declared types. The error is wrapped so the underlying gRPC/API error names the exact problem.","triggerScenarios":"RunSQL calls s.BigtableClient().PrepareStatement(ctx, statement, mapParamsType); Bigtable returns an error for invalid SQL syntax, unknown tables/columns, mismatched placeholder (@param) names versus the declared type map, or unsupported statement kinds.","commonSituations":"Typos in SQL or table names; using syntax unsupported by Bigtable SQL (dialect differences vs. other SQL engines); param names in the query not matching the tool's declared parameter names; the tool's statement template producing malformed SQL after rendering.","solutions":["Inspect the wrapped underlying error for the specific Bigtable SQL parse/resolution message","Validate the SQL in Bigtable Studio / `cbt` or another client before putting it in the tool config","Ensure every @placeholder in the statement has a corresponding declared parameter with the same name and a supported type","Simplify unsupported SQL constructs (joins/functions) to those Bigtable SQL supports"],"exampleFix":"// before\nstatement: \"SELECT * FROM users WHERE id = ?\"\n// after (named placeholders matching declared params)\nstatement: \"SELECT * FROM users WHERE id = @user_id\"","handlingStrategy":"validation","validationCode":"// before running, verify placeholders match declared params\nfunc validatePlaceholders(statement string, declared []string) error {\n\tre := regexp.MustCompile(`@[A-Za-z_][A-Za-z0-9_]*`)\n\tfound := map[string]bool{}\n\tfor _, m := range re.FindAllString(statement, -1) {\n\t\tfound[m[1:]] = true\n\t}\n\tfor name := range found {\n\t\tif !slices.Contains(declared, name) {\n\t\t\treturn fmt.Errorf(\"placeholder @%s has no declared parameter\", name)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"out, err := src.RunSQL(ctx, statement, cfgParams, values)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unable to prepare statement\") {\n\t\tlog.Printf(\"invalid Bigtable SQL: %v\", err) // surface wrapped API message\n\t}\n\treturn err\n}","preventionTips":["Test the statement against Bigtable SQL in a console before adding it to tools.yaml","Use named @placeholders that exactly match declared parameter names","Stick to Bigtable-SQL-supported syntax (avoid dialect-specific constructs)","Render templated statements carefully so parameters survive rendering"],"tags":["bigtable","sql","prepare-statement"],"backgroundTag":"sql-prepare-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"}