Skip to content

Commit 3ef844d

Browse files
committed
Backport Mysql 5.7 provider
1 parent 7b6189d commit 3ef844d

6 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (C) 2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
// Created by: Alexey Kulakov
5+
// Created: 2022.02.03
6+
7+
using Xtensive.Sql.Compiler;
8+
using Xtensive.Sql.Dml;
9+
10+
namespace Xtensive.Sql.Drivers.MySql.v5_7
11+
{
12+
internal class Compiler : v5_6.Compiler
13+
{
14+
/// <inheritdoc/>
15+
public override void Visit(SqlQueryExpression node)
16+
{
17+
base.Visit(node);
18+
using (context.EnterScope(node)) {
19+
var wrapLeft = node.Left is SqlSelect sL
20+
&& (sL.OrderBy.Count > 0 || sL.HasLimit || sL.Lock != SqlLockType.Empty);
21+
var wrapRight = node.Left is SqlSelect sR
22+
&& (sR.OrderBy.Count > 0 || sR.HasLimit || sR.Lock != SqlLockType.Empty);
23+
24+
context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.Entry));
25+
if (wrapLeft) {
26+
context.Output.AppendText("(");
27+
node.Left.AcceptVisitor(this);
28+
context.Output.AppendText(")");
29+
}
30+
else {
31+
node.Left.AcceptVisitor(this);
32+
}
33+
34+
context.Output.AppendText(translator.Translate(node.NodeType));
35+
context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.All));
36+
37+
if (wrapLeft) {
38+
context.Output.AppendText("(");
39+
node.Right.AcceptVisitor(this);
40+
context.Output.AppendText(")");
41+
}
42+
else {
43+
node.Left.AcceptVisitor(this);
44+
}
45+
46+
context.Output.AppendText(translator.Translate(context, node, QueryExpressionSection.Exit));
47+
}
48+
}
49+
50+
// Constructors
51+
52+
public Compiler(SqlDriver driver)
53+
: base(driver)
54+
{
55+
}
56+
}
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (C) 2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
// Created by: Alexey Kulakov
5+
// Created: 2022.02.03
6+
7+
using Xtensive.Sql.Compiler;
8+
using Xtensive.Sql.Info;
9+
10+
namespace Xtensive.Sql.Drivers.MySql.v5_7
11+
{
12+
internal class Driver : MySql.Driver
13+
{
14+
protected override Sql.TypeMapper CreateTypeMapper()
15+
{
16+
return new TypeMapper(this);
17+
}
18+
19+
protected override SqlCompiler CreateCompiler()
20+
{
21+
return new Compiler(this);
22+
}
23+
24+
protected override SqlTranslator CreateTranslator()
25+
{
26+
return new Translator(this);
27+
}
28+
29+
protected override Model.Extractor CreateExtractor()
30+
{
31+
return new Extractor(this);
32+
}
33+
34+
protected override Info.ServerInfoProvider CreateServerInfoProvider()
35+
{
36+
return new ServerInfoProvider(this);
37+
}
38+
39+
// Constructors
40+
41+
public Driver(CoreServerInfo coreServerInfo)
42+
: base(coreServerInfo)
43+
{
44+
}
45+
}
46+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
// Created by: Alexey Kulakov
5+
// Created: 2022.02.03
6+
7+
namespace Xtensive.Sql.Drivers.MySql.v5_7
8+
{
9+
internal class Extractor : v5_6.Extractor
10+
{
11+
// Constructors
12+
13+
public Extractor(SqlDriver driver)
14+
: base(driver)
15+
{
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
// Created by: Alexey Kulakov
5+
// Created: 2022.02.03
6+
7+
namespace Xtensive.Sql.Drivers.MySql.v5_7
8+
{
9+
internal class ServerInfoProvider : v5_6.ServerInfoProvider
10+
{
11+
// Constructors
12+
13+
public ServerInfoProvider(SqlDriver driver)
14+
: base(driver)
15+
{
16+
}
17+
}
18+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) 2022 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
// Created by: Alexey Kulakov
5+
// Created: 2022.02.03
6+
7+
using System;
8+
using Xtensive.Sql.Compiler;
9+
using Xtensive.Sql.Dml;
10+
11+
namespace Xtensive.Sql.Drivers.MySql.v8_0
12+
{
13+
internal class Translator : v5_7.Translator
14+
{
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+
34+
// Constructors
35+
36+
public Translator(SqlDriver driver)
37+
: base(driver)
38+
{
39+
}
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2003-2010 Xtensive LLC.
2+
// All rights reserved.
3+
// For conditions of distribution and use, see license.
4+
// Created by: Alena Mikshina
5+
// Created: 2013.12.30
6+
7+
namespace Xtensive.Sql.Drivers.MySql.v5_6
8+
{
9+
internal class TypeMapper : v5_5.TypeMapper
10+
{
11+
// Constructors
12+
13+
public TypeMapper(SqlDriver driver)
14+
: base(driver)
15+
{
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)