From 06d4267a762203feee3b7a83131ea1bf5b9d822c Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 30 Aug 2024 16:31:04 +0200 Subject: [PATCH] sqldb: fix end date filter when querying invoices Previously, the SQL implementation of the invoice query simply converted the start and end timestamps to time and used them in SQL queries to check for inclusivity. However, this logic failed when the start and end timestamps were equal. This commit addresses and corrects this issue. --- invoices/sql_store.go | 4 +++- sqldb/sqlc/invoices.sql.go | 2 +- sqldb/sqlc/queries/invoices.sql | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/invoices/sql_store.go b/invoices/sql_store.go index fa92ee56d..eb465eabb 100644 --- a/invoices/sql_store.go +++ b/invoices/sql_store.go @@ -925,8 +925,10 @@ func (i *SQLStore) QueryInvoices(ctx context.Context, } if q.CreationDateEnd != 0 { + // We need to add 1 to the end date as we're + // checking less than the end date in SQL. params.CreatedBefore = sqldb.SQLTime( - time.Unix(q.CreationDateEnd, 0).UTC(), + time.Unix(q.CreationDateEnd+1, 0).UTC(), ) } diff --git a/sqldb/sqlc/invoices.sql.go b/sqldb/sqlc/invoices.sql.go index 5849bca06..9e31380ab 100644 --- a/sqldb/sqlc/invoices.sql.go +++ b/sqldb/sqlc/invoices.sql.go @@ -78,7 +78,7 @@ WHERE ( created_at >= $6 OR $6 IS NULL ) AND ( - created_at <= $7 OR + created_at < $7 OR $7 IS NULL ) AND ( CASE diff --git a/sqldb/sqlc/queries/invoices.sql b/sqldb/sqlc/queries/invoices.sql index b03410a51..2a49553e6 100644 --- a/sqldb/sqlc/queries/invoices.sql +++ b/sqldb/sqlc/queries/invoices.sql @@ -76,7 +76,7 @@ WHERE ( created_at >= sqlc.narg('created_after') OR sqlc.narg('created_after') IS NULL ) AND ( - created_at <= sqlc.narg('created_before') OR + created_at < sqlc.narg('created_before') OR sqlc.narg('created_before') IS NULL ) AND ( CASE