mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-05 04:54:59 +02:00
sqldb+invoices: fix ordering bug in FilterInvoices
Previously if the `reverse` named arg was unset (value of NULL), then SQL would order by NULL instead of ID causing undifined ordering of the returned rows. To fix that we check for NULL and also make sure to set the `reverse` arg in the code explicitly as it in the generated code it is an `interface{}` instead of `bool`.
This commit is contained in:
@ -82,19 +82,19 @@ WHERE (
|
||||
$7 IS NULL
|
||||
) AND (
|
||||
CASE
|
||||
WHEN $8=TRUE THEN (state = 0 OR state = 3)
|
||||
WHEN $8 = TRUE THEN (state = 0 OR state = 3)
|
||||
ELSE TRUE
|
||||
END
|
||||
)
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN $9 = FALSE THEN id
|
||||
ELSE NULL
|
||||
CASE
|
||||
WHEN $9 = FALSE OR $9 IS NULL THEN id
|
||||
ELSE NULL
|
||||
END ASC,
|
||||
CASE
|
||||
WHEN $9 = TRUE THEN id
|
||||
ELSE NULL
|
||||
END DESC
|
||||
CASE
|
||||
WHEN $9 = TRUE THEN id
|
||||
ELSE NULL
|
||||
END DESC
|
||||
LIMIT $11 OFFSET $10
|
||||
`
|
||||
|
||||
|
@ -73,19 +73,19 @@ WHERE (
|
||||
sqlc.narg('created_before') IS NULL
|
||||
) AND (
|
||||
CASE
|
||||
WHEN sqlc.narg('pending_only')=TRUE THEN (state = 0 OR state = 3)
|
||||
WHEN sqlc.narg('pending_only') = TRUE THEN (state = 0 OR state = 3)
|
||||
ELSE TRUE
|
||||
END
|
||||
)
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN sqlc.narg('reverse') = FALSE THEN id
|
||||
ELSE NULL
|
||||
CASE
|
||||
WHEN sqlc.narg('reverse') = FALSE OR sqlc.narg('reverse') IS NULL THEN id
|
||||
ELSE NULL
|
||||
END ASC,
|
||||
CASE
|
||||
WHEN sqlc.narg('reverse') = TRUE THEN id
|
||||
ELSE NULL
|
||||
END DESC
|
||||
CASE
|
||||
WHEN sqlc.narg('reverse') = TRUE THEN id
|
||||
ELSE NULL
|
||||
END DESC
|
||||
LIMIT @num_limit OFFSET @num_offset;
|
||||
|
||||
-- name: UpdateInvoiceState :execresult
|
||||
|
Reference in New Issue
Block a user