From db0978af99fd8e7f3050b705d2f88d6385bac583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=A0=87?= Date: Mon, 16 Jan 2023 13:23:27 +0800 Subject: [PATCH] fix(statement): The primary key type is not int, but string or uuid (#5984) --- statement.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/statement.go b/statement.go index 781f14e6..c7b0b593 100644 --- a/statement.go +++ b/statement.go @@ -287,7 +287,12 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) [] return nil } - // The primary key type is not int, but string or uuid (#5984) + //The primary key type is not int, but string or uuid (#5984) + if len(args) == 0 && (!strings.Contains(s, "?") && !strings.Contains(s, "@")) { + // if it is a string, then treats it as primary key + return []clause.Expression{clause.IN{Column: clause.PrimaryColumn, Values: []interface{}{s}}} + } + if len(args) == 0 || (len(args) > 0 && strings.Contains(s, "?")) { // looks like a where condition return []clause.Expression{clause.Expr{SQL: s, Vars: args}}