mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user