MCPcopy Create free account
hub / github.com/bytebase/bytebase / getStatementWithResultLimit

Function getStatementWithResultLimit

backend/plugin/db/spanner/spanner.go:299–303  ·  view source on GitHub ↗

getStatementWithResultLimit wraps a SQL statement in a CTE to enforce a result limit. This is a simple approach that works for SELECT queries but has a critical limitation: Spanner does NOT support DML statements (INSERT/UPDATE/DELETE) inside CTEs. This function should ONLY be called for SELECT sta

(stmt string, limit int)

Source from the content-addressed store, hash-verified

297// For a more robust parser-based approach that can handle complex queries, see the
298// PostgreSQL/MySQL implementations which parse and inject LIMIT clauses directly.
299func getStatementWithResultLimit(stmt string, limit int) string {
300 stmt = strings.TrimRightFunc(stmt, utils.IsSpaceOrSemicolon)
301 limitPart := fmt.Sprintf(" LIMIT %d", limit)
302 return fmt.Sprintf("WITH result AS (%s) SELECT * FROM result%s;", stmt, limitPart)
303}
304
305func getDSN(host, database string) string {
306 return fmt.Sprintf("%s/databases/%s", host, database)

Callers 1

QueryConnMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected