MCPcopy Create free account
hub / github.com/daodst/chat / RunLimitedVariablesQuery

Function RunLimitedVariablesQuery

internal/sqlutil/sql.go:132–154  ·  view source on GitHub ↗

RunLimitedVariablesQuery split up a query with more variables than the used database can handle in multiple queries.

(ctx context.Context, query string, qp QueryProvider, variables []interface{}, limit uint, rowHandler func(*sql.Rows) error)

Source from the content-addressed store, hash-verified

130
131// RunLimitedVariablesQuery split up a query with more variables than the used database can handle in multiple queries.
132func RunLimitedVariablesQuery(ctx context.Context, query string, qp QueryProvider, variables []interface{}, limit uint, rowHandler func(*sql.Rows) error) error {
133 var start int
134 for start < len(variables) {
135 n := minOfInts(len(variables)-start, int(limit))
136 nextQuery := strings.Replace(query, "($1)", QueryVariadic(n), 1)
137 rows, err := qp.QueryContext(ctx, nextQuery, variables[start:start+n]...)
138 if err != nil {
139 util.GetLogger(ctx).WithError(err).Error("QueryContext returned an error")
140 return err
141 }
142 err = rowHandler(rows)
143 if closeErr := rows.Close(); closeErr != nil {
144 util.GetLogger(ctx).WithError(closeErr).Error("RunLimitedVariablesQuery: failed to close rows")
145 return err
146 }
147 if err != nil {
148 util.GetLogger(ctx).WithError(err).Error("RunLimitedVariablesQuery: rowHandler returned error")
149 return err
150 }
151 start = start + n
152 }
153 return nil
154}
155
156// StatementList is a list of SQL statements to prepare and a pointer to where to store the resulting prepared statement.
157type StatementList []struct {

Calls 5

QueryVariadicFunction · 0.85
QueryContextMethod · 0.80
minOfIntsFunction · 0.70
CloseMethod · 0.65
ErrorMethod · 0.45