Skip to content

Commit f2ddb33

Browse files
committed
issue #189 merge oracle compilers
move extension classes initial merge of oracle compilers update unit tests part one rename test cs file remove commented / obsolete tests
1 parent acc482e commit f2ddb33

16 files changed

Lines changed: 105 additions & 292 deletions

QueryBuilder.Tests/OracleLegacyLimit.cs

Lines changed: 0 additions & 89 deletions
This file was deleted.

QueryBuilder.Tests/Oracle11gLimitTests.cs renamed to QueryBuilder.Tests/OracleLegacyLimitTests.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,15 @@
55

66
namespace SqlKata.Tests
77
{
8-
public class Oracle11gLimitTests
8+
public class OracleLegacyLimitTests
99
{
1010
private const string TableName = "Table";
1111
private const string SqlPlaceholder = "GENERATED_SQL";
1212

13-
private Oracle11gCompiler compiler = new Oracle11gCompiler();
14-
15-
[Fact]
16-
public void CompileLimitThrowsException()
13+
private OracleCompiler compiler = new OracleCompiler()
1714
{
18-
// Arrange:
19-
var query = new Query(TableName);
20-
var ctx = new SqlResult { Query = query };
21-
22-
// Act:
23-
Assert.Throws<NotSupportedException>(() => compiler.CompileLimit(ctx));
24-
25-
// Assert: Assertion is handled by Throws
26-
}
15+
UseLegacyPagination = true
16+
};
2717

2818
[Fact]
2919
public void WithNoLimitNorOffset()
@@ -33,7 +23,7 @@ public void WithNoLimitNorOffset()
3323
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
3424

3525
// Act:
36-
compiler.ApplyLimit(ctx);
26+
compiler.ApplyLegacyLimit(ctx);
3727

3828
// Assert:
3929
Assert.Equal(SqlPlaceholder, ctx.RawSql);
@@ -47,7 +37,7 @@ public void WithNoOffset()
4737
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
4838

4939
// Act:
50-
compiler.ApplyLimit(ctx);
40+
compiler.ApplyLegacyLimit(ctx);
5141

5242
// Assert:
5343
Assert.Matches($"SELECT \\* FROM \\({SqlPlaceholder}\\) WHERE ROWNUM <= ?", ctx.RawSql);
@@ -63,7 +53,7 @@ public void WithNoLimit()
6353
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
6454

6555
// Act:
66-
compiler.ApplyLimit(ctx);
56+
compiler.ApplyLegacyLimit(ctx);
6757

6858
// Assert:
6959
Assert.Matches($"SELECT \\* FROM \\(SELECT \"(SqlKata_.*__)\"\\.\\*, ROWNUM \"(SqlKata_.*__)\" FROM \\({SqlPlaceholder}\\) \"(SqlKata_.*__)\"\\) WHERE \"(SqlKata_.*__)\" > \\?", ctx.RawSql);
@@ -79,7 +69,7 @@ public void WithLimitAndOffset()
7969
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
8070

8171
// Act:
82-
compiler.ApplyLimit(ctx);
72+
compiler.ApplyLegacyLimit(ctx);
8373

8474
// Assert:
8575
Assert.Matches($"SELECT \\* FROM \\(SELECT \"(SqlKata_.*__)\"\\.\\*, ROWNUM \"(SqlKata_.*__)\" FROM \\({SqlPlaceholder}\\) \"(SqlKata_.*__)\" WHERE ROWNUM <= \\?\\) WHERE \"(SqlKata_.*__)\" > \\?", ctx.RawSql);

QueryBuilder.Tests/QueryBuilderTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SqlKata.Execution;
44
using SqlKata;
55
using SqlKata.Compilers;
6+
using SqlKata.Compilers.Extensions;
67
using Xunit;
78

89
namespace SqlKata.Tests
@@ -12,7 +13,7 @@ public class QueryBuilderTest
1213
private readonly Compiler pgsql;
1314
private readonly MySqlCompiler mysql;
1415
private readonly FirebirdCompiler fbsql;
15-
private readonly Oracle11gCompiler oracle;
16+
private readonly OracleCompiler oracle;
1617
public SqlServerCompiler mssql { get; private set; }
1718

1819
private string[] Compile(Query q)
@@ -23,7 +24,7 @@ private string[] Compile(Query q)
2324
mysql.Compile(q.Clone()).ToString(),
2425
pgsql.Compile(q.Clone()).ToString(),
2526
fbsql.Compile(q.Clone()).ToString(),
26-
oracle.Compile(q.Clone()).ToString(),
27+
oracle.Compile(q.Clone()).ToString()
2728
};
2829
}
2930

@@ -33,7 +34,7 @@ public QueryBuilderTest()
3334
mysql = new MySqlCompiler();
3435
pgsql = new PostgresCompiler();
3536
fbsql = new FirebirdCompiler();
36-
oracle = new Oracle11gCompiler();
37+
oracle = new OracleCompiler();
3738
}
3839

3940
[Fact]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class FirebirdCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "firebird";
8+
9+
public static Query ForFirebird(this Query src, Func<Query, Query> fn)
10+
{
11+
return src.For(FirebirdCompilerExtensions.ENGINE_CODE, fn);
12+
}
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class MySqlCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "mysql";
8+
public static Query ForMySql(this Query src, Func<Query, Query> fn)
9+
{
10+
return src.For(MySqlCompilerExtensions.ENGINE_CODE, fn);
11+
}
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class OracleCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "oracle";
8+
9+
public static Query ForOracle(this Query src, Func<Query, Query> fn)
10+
{
11+
return src.For(ENGINE_CODE, fn);
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class PostgresCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "postgres";
8+
9+
public static Query ForPostgres(this Query src, Func<Query, Query> fn)
10+
{
11+
return src.For(PostgresCompilerExtensions.ENGINE_CODE, fn);
12+
}
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class SqlServerCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "sqlsrv";
8+
public static Query ForSqlServer(this Query src, Func<Query, Query> fn)
9+
{
10+
return src.For(SqlServerCompilerExtensions.ENGINE_CODE, fn);
11+
}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace SqlKata.Compilers.Extensions
4+
{
5+
public static class SqliteCompilerExtensions
6+
{
7+
public static string ENGINE_CODE = "sqlite";
8+
public static Query ForSqlite(this Query src, Func<Query, Query> fn)
9+
{
10+
return src.For(SqliteCompilerExtensions.ENGINE_CODE, fn);
11+
}
12+
}
13+
}

QueryBuilder/Compilers/FirebirdCompiler.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Text.RegularExpressions;
@@ -154,14 +153,4 @@ public override string CompileFalse()
154153
return "0";
155154
}
156155
}
157-
158-
public static class FirebirdCompilerExtensions
159-
{
160-
public static string ENGINE_CODE = "firebird";
161-
162-
public static Query ForFirebird(this Query src, Func<Query, Query> fn)
163-
{
164-
return src.For(FirebirdCompilerExtensions.ENGINE_CODE, fn);
165-
}
166-
}
167156
}

0 commit comments

Comments
 (0)