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

Function getStatementWithResultLimit

backend/plugin/db/pg/query.go:216–224  ·  view source on GitHub ↗

getStatementWithResultLimit returns the statement with LIMIT clause if not exists.

(statement string, limit int)

Source from the content-addressed store, hash-verified

214
215// getStatementWithResultLimit returns the statement with LIMIT clause if not exists.
216func getStatementWithResultLimit(statement string, limit int) string {
217 stmt, err := getStatementWithResultLimitInline(statement, limit)
218 if err != nil {
219 slog.Error("fail to add limit clause", slog.String("statement", statement), log.BBError(err))
220 // Fallback to CTE approach for problematic queries
221 return fmt.Sprintf("WITH result AS (\n%s\n) SELECT * FROM result LIMIT %d;", util.TrimStatement(statement), limit)
222 }
223 return stmt
224}
225
226func getStatementWithResultLimitInline(statement string, limitCount int) (string, error) {
227 if strings.TrimSpace(statement) == "" {

Callers 2

QueryConnMethod · 0.70

Calls 5

BBErrorFunction · 0.92
TrimStatementFunction · 0.92
StringMethod · 0.65
ErrorMethod · 0.45

Tested by 1