dialect/sql: report explicit error when trying to SELECT .. FOR UPDAT… (#1847)

* dialect/sql: report explicit error when trying to SELECT .. FOR UPDATE with sqlite

* remove redundant assertion
This commit is contained in:
Rotem Tamir
2021-08-17 12:54:23 +03:00
committed by GitHub
parent 22527cc281
commit f326c7dfd0
2 changed files with 11 additions and 0 deletions

View File

@@ -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)

View File

@@ -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) {