forked from sqlkata/querybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySqlCompiler.cs
More file actions
49 lines (37 loc) · 1.26 KB
/
MySqlCompiler.cs
File metadata and controls
49 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace SqlKata.Compilers
{
public class MySqlCompiler : Compiler
{
public MySqlCompiler()
{
OpeningIdentifier = ClosingIdentifier = "`";
LastId = "SELECT last_insert_id() as Id";
}
public override string EngineCode { get; } = EngineCodes.MySql;
public override string CompileLimit(SqlResult ctx)
{
var limit = ctx.Query.GetLimit(EngineCode);
var offset = ctx.Query.GetOffset(EngineCode);
if (offset == 0 && limit == 0)
{
return null;
}
if (offset == 0)
{
ctx.Bindings.Add(limit);
return $"LIMIT {parameterPlaceholder}";
}
if (limit == 0)
{
// MySql will not accept offset without limit, so we will put a large number
// to avoid this error.
ctx.Bindings.Add(offset);
return $"LIMIT 18446744073709551615 OFFSET {parameterPlaceholder}";
}
// We have both values
ctx.Bindings.Add(limit);
ctx.Bindings.Add(offset);
return $"LIMIT {parameterPlaceholder} OFFSET {parameterPlaceholder}";
}
}
}