From c6a02b850d97c4069b983f6f63395b27baeeaa36 Mon Sep 17 00:00:00 2001 From: John Guo Date: Thu, 13 Oct 2022 19:13:10 +0800 Subject: [PATCH] fix issue #1934 (#2193) --- contrib/drivers/mysql/mysql_model_test.go | 11 +++++++++++ database/gdb/gdb_func.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/contrib/drivers/mysql/mysql_model_test.go b/contrib/drivers/mysql/mysql_model_test.go index d31634ba3..5c2cea7f7 100644 --- a/contrib/drivers/mysql/mysql_model_test.go +++ b/contrib/drivers/mysql/mysql_model_test.go @@ -4688,3 +4688,14 @@ func Test_Builder_OmitEmptyWhere(t *testing.T) { t.Assert(count, TableSize) }) } + +func Test_Issue1934(t *testing.T) { + table := createInitTable() + defer dropTable(table) + + gtest.C(t, func(t *gtest.T) { + one, err := db.Model(table).Where(" id ", 1).One() + t.AssertNil(err) + t.Assert(one["id"], 1) + }) +} diff --git a/database/gdb/gdb_func.go b/database/gdb/gdb_func.go index 421700b56..b459d89fc 100644 --- a/database/gdb/gdb_func.go +++ b/database/gdb/gdb_func.go @@ -528,7 +528,7 @@ func formatWhereHolder(ctx context.Context, db DB, in formatWhereHolderInput) (n return } // Usually a string. - whereStr := gconv.String(in.Where) + whereStr := gstr.Trim(gconv.String(in.Where)) // Is `whereStr` a field name which composed as a key-value condition? // Eg: // Where("id", 1)