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)
| 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. |
| 299 | func 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 | |
| 305 | func getDSN(host, database string) string { |
| 306 | return fmt.Sprintf("%s/databases/%s", host, database) |