From 6316c2e46a4bd102b5e1cec4155fc3e972076060 Mon Sep 17 00:00:00 2001 From: Jille Timmermans Date: Sat, 24 Jun 2023 23:42:10 +0200 Subject: [PATCH] Add a testcase for BETWEEN sqlc.arg(min) AND sqlc.arg(max) issue #2277 --- .../between_args/mysql/go/query.sql.go | 29 +++++++++++++++++++ .../testdata/between_args/mysql/query.sql | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/internal/endtoend/testdata/between_args/mysql/go/query.sql.go b/internal/endtoend/testdata/between_args/mysql/go/query.sql.go index a4c2221847..e93e04852d 100644 --- a/internal/endtoend/testdata/between_args/mysql/go/query.sql.go +++ b/internal/endtoend/testdata/between_args/mysql/go/query.sql.go @@ -43,6 +43,35 @@ func (q *Queries) GetBetweenPrices(ctx context.Context, arg GetBetweenPricesPara return items, nil } +const getBetweenPricesNamed = `-- name: GetBetweenPricesNamed :many +SELECT id, name, price +FROM products +WHERE price BETWEEN sqlc.arg(min_price) AND sqlc.arg(max_price) +` + +func (q *Queries) GetBetweenPricesNamed(ctx context.Context) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getBetweenPricesNamed) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan(&i.ID, &i.Name, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getBetweenPricesTable = `-- name: GetBetweenPricesTable :many SELECT id, name, price FROM products diff --git a/internal/endtoend/testdata/between_args/mysql/query.sql b/internal/endtoend/testdata/between_args/mysql/query.sql index 1e38765622..7458e0ecb5 100644 --- a/internal/endtoend/testdata/between_args/mysql/query.sql +++ b/internal/endtoend/testdata/between_args/mysql/query.sql @@ -19,3 +19,8 @@ WHERE products.price BETWEEN ? AND ?; SELECT * FROM products as p WHERE p.price BETWEEN ? AND ?; + +-- name: GetBetweenPricesNamed :many +SELECT * +FROM products +WHERE price BETWEEN sqlc.arg(min_price) AND sqlc.arg(max_price);