Skip to content

Commit fd324b4

Browse files
author
Soumya Mohapatra
committed
Fix ambiguous column names in token-transaction SQL JOINs
Signed-off-by: Soumya Mohapatra <mohapatras@microsoft.com>
1 parent 70a9e69 commit fd324b4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

  • token/services/storage/db/sql/common

token/services/storage/db/sql/common/tokens.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -644,16 +644,16 @@ func (db *TokenStore) ListRedeemedTokens(ctx context.Context, tokenType token.Ty
644644
cond.Eq("action_type", int(driver.Redeem)),
645645
}
646646
if len(tokenType) != 0 {
647-
conds = append(conds, cond.Eq("token_type", tokenType))
647+
conds = append(conds, cond.CmpVal(tokTable.Field("token_type"), "=", tokenType))
648648
}
649649
if len(issuerRaw) != 0 {
650650
conds = append(conds, cond.Eq("issuer_raw", issuerRaw))
651651
}
652652
if from != nil {
653-
conds = append(conds, cond.Gte("stored_at", from.UTC()))
653+
conds = append(conds, cond.CmpVal(tokTable.Field("stored_at"), ">=", from.UTC()))
654654
}
655655
if to != nil {
656-
conds = append(conds, cond.Lte("stored_at", to.UTC()))
656+
conds = append(conds, cond.CmpVal(tokTable.Field("stored_at"), "<=", to.UTC()))
657657
}
658658
sel := q.Select().
659659
Fields(
@@ -668,9 +668,9 @@ func (db *TokenStore) ListRedeemedTokens(ctx context.Context, tokenType token.Ty
668668
var args []any
669669
if sortBy == tdriver.SortByQuantity {
670670
if sortDirection == tdriver.SortDescending {
671-
query, args = sel.OrderBy(q.Desc(common3.FieldName("amount"))).Format(db.ci)
671+
query, args = sel.OrderBy(q.Desc(tokTable.Field("amount"))).Format(db.ci)
672672
} else {
673-
query, args = sel.OrderBy(q.Asc(common3.FieldName("amount"))).Format(db.ci)
673+
query, args = sel.OrderBy(q.Asc(tokTable.Field("amount"))).Format(db.ci)
674674
}
675675
} else {
676676
query, args = sel.Format(db.ci)
@@ -704,19 +704,19 @@ func (db *TokenStore) RedeemedBalance(ctx context.Context, tokenType token.Type,
704704
cond.Eq("action_type", int(driver.Redeem)),
705705
}
706706
if len(tokenType) != 0 {
707-
conds = append(conds, cond.Eq("token_type", tokenType))
707+
conds = append(conds, cond.CmpVal(tokTable.Field("token_type"), "=", tokenType))
708708
}
709709
if len(issuerRaw) != 0 {
710710
conds = append(conds, cond.Eq("issuer_raw", issuerRaw))
711711
}
712712
if from != nil {
713-
conds = append(conds, cond.Gte("stored_at", from.UTC()))
713+
conds = append(conds, cond.CmpVal(tokTable.Field("stored_at"), ">=", from.UTC()))
714714
}
715715
if to != nil {
716-
conds = append(conds, cond.Lte("stored_at", to.UTC()))
716+
conds = append(conds, cond.CmpVal(tokTable.Field("stored_at"), "<=", to.UTC()))
717717
}
718718
query, args := q.Select().
719-
FieldsByName("SUM(amount)").
719+
FieldsByName(common3.FieldName("SUM(" + db.table.Tokens + ".amount)")).
720720
From(tokTable.Join(txTable, cond.Cmp(tokTable.Field("spent_by"), "=", txTable.Field("tx_id")))).
721721
Where(cond.And(conds...)).
722722
Format(db.ci)

0 commit comments

Comments
 (0)