Skip to content

Commit c4b83e9

Browse files
committed
SqlLockType proper translation for MySql v8.0
1 parent ba977c3 commit c4b83e9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Orm/Xtensive.Orm.MySql/Sql.Drivers.MySql/v8_0/Translator.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ namespace Xtensive.Sql.Drivers.MySql.v8_0
1212
{
1313
internal class Translator : v5_7.Translator
1414
{
15+
/// <inheritdoc/>
16+
public override void Translate(IOutput output, SqlLockType lockType)
17+
{
18+
var forShare = lockType.Supports(SqlLockType.Shared);
19+
var forUpdate = lockType.SupportsAny(SqlLockType.Update | SqlLockType.Exclusive);
20+
21+
if (!forShare && !forUpdate) {
22+
throw new NotSupportedException($"Lock '{lockType.ToString(true)}' is not supported.");
23+
}
24+
25+
_ = output
26+
.Append(forShare ? "FOR SHARE" : "FOR UPDATE")
27+
.Append(lockType.Supports(SqlLockType.SkipLocked)
28+
? " SKIP LOCKED"
29+
: lockType.Supports(SqlLockType.ThrowIfLocked)
30+
? " NOWAIT"
31+
: string.Empty);
32+
}
33+
1534
// Constructors
1635

1736
public Translator(SqlDriver driver)

Orm/Xtensive.Orm/Sql/Dml/Extensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public static bool Supports(this SqlLockType available, SqlLockType required)
3333
return (available & required)==required;
3434
}
3535

36+
public static bool SupportsAny(this SqlLockType available, SqlLockType required)
37+
{
38+
return (available | required) == required;
39+
}
40+
3641
public static string ToString(this SqlLockType lockType, bool humanReadable)
3742
{
3843
if (!humanReadable)

0 commit comments

Comments
 (0)