From f326c7dfd088f112d0bc3150161862115d6fff63 Mon Sep 17 00:00:00 2001 From: Rotem Tamir Date: Tue, 17 Aug 2021 12:54:23 +0300 Subject: [PATCH] =?UTF-8?q?dialect/sql:=20report=20explicit=20error=20when?= =?UTF-8?q?=20trying=20to=20SELECT=20..=20FOR=20UPDAT=E2=80=A6=20(#1847)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * dialect/sql: report explicit error when trying to SELECT .. FOR UPDATE with sqlite * remove redundant assertion --- dialect/sql/builder.go | 3 +++ dialect/sql/builder_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/dialect/sql/builder.go b/dialect/sql/builder.go index 475418524..d12e57792 100644 --- a/dialect/sql/builder.go +++ b/dialect/sql/builder.go @@ -2363,6 +2363,9 @@ func WithLockClause(clause string) LockOption { // For sets the lock configuration for suffixing the `SELECT` // statement with the `FOR [SHARE | UPDATE] ...` clause. func (s *Selector) For(l LockStrength, opts ...LockOption) *Selector { + if s.Dialect() == dialect.SQLite { + s.AddError(errors.New("sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite")) + } s.lock = &LockOptions{Strength: l} for _, opt := range opts { opt(s.lock) diff --git a/dialect/sql/builder_test.go b/dialect/sql/builder_test.go index e5e9abec3..81c3b5ee4 100644 --- a/dialect/sql/builder_test.go +++ b/dialect/sql/builder_test.go @@ -1667,6 +1667,14 @@ func TestSelectWithLock(t *testing.T) { Query() require.Equal(t, "SELECT * FROM `users` WHERE `id` = ? LOCK IN SHARE MODE", query) require.Equal(t, 20, args[0]) + + s := Dialect(dialect.SQLite). + Select(). + From(Table("users")). + Where(EQ("id", 1)). + ForUpdate() + s.Query() + require.EqualError(t, s.Err(), "sql: SELECT .. FOR UPDATE/SHARE not supported in SQLite") } func TestSelector_UnionOrderBy(t *testing.T) {