diff --git a/.editorconfig b/.editorconfig old mode 100755 new mode 100644 index b33fe946..b7c01309 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] charset = utf-8 -end_of_line = lf +end_of_line = crlf # Note: the trim_trailing_whitespace option is br0ken in visualstudio, it # simply does not follow the EditorConfig specification. Therefor you are # strongly encouraged to not rely on this setting alone, but please install @@ -16,13 +16,76 @@ end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true indent_style = tab -indent_size = 2 +indent_size = 4 [*.cs] # To match existing style indent_style = space indent_size = 4 +csharp_indent_labels = no_change +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_space_around_binary_operators = before_and_after [*.yml] indent_style = space + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 diff --git a/.gitignore b/.gitignore index 50290793..0d95f1c7 100644 --- a/.gitignore +++ b/.gitignore @@ -276,3 +276,4 @@ __pycache__/ # Thumbs Thumbs.db +*.received.* diff --git a/Program/Program.cs b/Program/Program.cs index 9b4c2845..021812cb 100644 --- a/Program/Program.cs +++ b/Program/Program.cs @@ -1,59 +1,28 @@ using System; -using System.Collections.Generic; -using SqlKata; using SqlKata.Compilers; using SqlKata.Execution; -using System.Data.SqlClient; -using System.Threading.Tasks; -using System.Linq; using Newtonsoft.Json; -using Npgsql; -using System.Data; -using Dapper; using System.Data.SQLite; -using static SqlKata.Expressions; using System.IO; namespace Program { class Program { - private class Loan + + static void Main() { - public string Id { get; set; } - public string Name { get; set; } - public List Installments { get; set; } = new List(); - } - - private class Installment - { - public string Id { get; set; } - public string LoanId { get; set; } - public int DaysCount { get; set; } - } - - static void Main(string[] args) - { - using (var db = SqlLiteQueryFactory()) - { - var query = db.Query("accounts") - .Where("balance", ">", 0) - .GroupBy("balance") + using var db = SqlLiteQueryFactory(); + var query = db.Query("accounts") + .Where("balance", ">", 0) + .GroupBy("balance") .Limit(10); - var accounts = query.Clone().Get(); - Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented)); + var accounts = query.Clone().Get(); + Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented)); - var exists = query.Clone().Exists(); - Console.WriteLine(exists); - } - } - - private static void log(Compiler compiler, Query query) - { - var compiled = compiler.Compile(query); - Console.WriteLine(compiled.ToString()); - Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings)); + var exists = query.Clone().Exists(); + Console.WriteLine(exists); } private static QueryFactory SqlLiteQueryFactory() @@ -93,22 +62,6 @@ private static QueryFactory SqlLiteQueryFactory() } - private static QueryFactory SqlServerQueryFactory() - { - var compiler = new PostgresCompiler(); - var connection = new SqlConnection( - "Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd" - ); - - var db = new QueryFactory(connection, compiler); - - db.Logger = result => - { - Console.WriteLine(result.ToString()); - }; - - return db; - } } } diff --git a/Program/Program.csproj b/Program/Program.csproj index 6341ecef..05e6a765 100644 --- a/Program/Program.csproj +++ b/Program/Program.csproj @@ -6,16 +6,16 @@ - - - - + + + + Exe false - netcoreapp2.0 + net7.0 diff --git a/QueryBuilder.Tests/AggregateTests.cs b/QueryBuilder.Tests/AggregateTests.cs index 68a69842..1bce8680 100644 --- a/QueryBuilder.Tests/AggregateTests.cs +++ b/QueryBuilder.Tests/AggregateTests.cs @@ -1,92 +1,94 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class AggregateTests : TestSupport { - public class AggregateTests : TestSupport + [Fact] + public void Count() { - [Fact] - public void Count() - { - var query = new Query("A").AsCount(); + var query = new Query("A").AsCount(); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT COUNT(*) AS [count] FROM [A]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT COUNT(*) AS `count` FROM `A`", c[EngineCodes.MySql]); - Assert.Equal("SELECT COUNT(*) AS \"count\" FROM \"A\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT COUNT(*) AS \"COUNT\" FROM \"A\"", c[EngineCodes.Firebird]); - } + Assert.Equal("SELECT COUNT(*) AS [count] FROM [A]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT COUNT(*) AS `count` FROM `A`", c[EngineCodes.MySql]); + Assert.Equal("SELECT COUNT(*) AS \"count\" FROM \"A\"", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT COUNT(*) AS \"COUNT\" FROM \"A\"", c[EngineCodes.Firebird]); + } - [Fact] - public void CountMultipleColumns() - { - var query = new Query("A").AsCount(new[] { "ColumnA", "ColumnB" }); + [Fact] + public void CountMultipleColumns() + { + var query = new Query("A").AsCount(new[] { "ColumnA", "ColumnB" }); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT 1 FROM [A] WHERE [ColumnA] IS NOT NULL AND [ColumnB] IS NOT NULL) AS [countQuery]", c[EngineCodes.SqlServer]); - } + Assert.Equal( + "SELECT COUNT(*) AS [count] FROM (SELECT 1 FROM [A] WHERE [ColumnA] IS NOT NULL AND [ColumnB] IS NOT NULL) AS [countQuery]", + c[EngineCodes.SqlServer]); + } - [Fact] - public void DistinctCount() - { - var query = new Query("A").Distinct().AsCount(); + [Fact] + public void DistinctCount() + { + var query = new Query("A").Distinct().AsCount(); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT * FROM [A]) AS [countQuery]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT * FROM [A]) AS [countQuery]", + c[EngineCodes.SqlServer]); + } - [Fact] - public void DistinctCountMultipleColumns() - { - var query = new Query("A").Distinct().AsCount(new[] { "ColumnA", "ColumnB" }); + [Fact] + public void DistinctCountMultipleColumns() + { + var query = new Query("A").Distinct().AsCount(new[] { "ColumnA", "ColumnB" }); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT [ColumnA], [ColumnB] FROM [A]) AS [countQuery]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT COUNT(*) AS [count] FROM (SELECT DISTINCT [ColumnA], [ColumnB] FROM [A]) AS [countQuery]", + c[EngineCodes.SqlServer]); + } - [Fact] - public void Average() - { - var query = new Query("A").AsAverage("TTL"); + [Fact] + public void Average() + { + var query = new Query("A").AsAverage("TTL"); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT AVG([TTL]) AS [avg] FROM [A]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT AVG([TTL]) AS [avg] FROM [A]", c[EngineCodes.SqlServer]); + } - [Fact] - public void Sum() - { - var query = new Query("A").AsSum("PacketsDropped"); + [Fact] + public void Sum() + { + var query = new Query("A").AsSum("PacketsDropped"); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT SUM([PacketsDropped]) AS [sum] FROM [A]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT SUM([PacketsDropped]) AS [sum] FROM [A]", c[EngineCodes.SqlServer]); + } - [Fact] - public void Max() - { - var query = new Query("A").AsMax("LatencyMs"); + [Fact] + public void Max() + { + var query = new Query("A").AsMax("LatencyMs"); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT MAX([LatencyMs]) AS [max] FROM [A]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT MAX([LatencyMs]) AS [max] FROM [A]", c[EngineCodes.SqlServer]); + } - [Fact] - public void Min() - { - var query = new Query("A").AsMin("LatencyMs"); + [Fact] + public void Min() + { + var query = new Query("A").AsMin("LatencyMs"); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT MIN([LatencyMs]) AS [min] FROM [A]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT MIN([LatencyMs]) AS [min] FROM [A]", c[EngineCodes.SqlServer]); } } diff --git a/QueryBuilder.Tests/ApprovalTests/CompileFlatColumns.cs b/QueryBuilder.Tests/ApprovalTests/CompileFlatColumns.cs new file mode 100644 index 00000000..ca76820e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/CompileFlatColumns.cs @@ -0,0 +1,792 @@ +using FluentAssertions; +using SqlKata.Compilers; +using SqlKata.Tests.ApprovalTests.Utils; + +namespace SqlKata.Tests.ApprovalTests +{ + [UsesVerify] + public sealed class CompileFrom + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task NoFrom(Compiler compiler) + { + return new Query().Select("a").Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileTableExpression + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task RawFromClause(Compiler compiler) + { + return new Query() + .FromRaw("(INNER {a} ?)", 5) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task SubQuery_No_Alias(Compiler compiler) + { + return new Query("X").From(new Query("Y")).Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileColumns + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Limit(Compiler compiler) + { + return new Query("X").Limit(3).Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Offset(Compiler compiler) + { + return new Query("X").Offset(4).Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Limit_Distinct(Compiler compiler) + { + return new Query("X").Distinct().Limit(3).Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileFlatColumns + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task All(Compiler compiler) + { + return new Query("X").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Specific(Compiler compiler) + { + return new Query("X").Select("a", "b", "c").Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileColumnList + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task RawColumn(Compiler compiler) + { + return new Query("X").SelectRaw("{1}, ?", "p").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task SubQuery(Compiler compiler) + { + return new Query("X").Select(new Query("Y"), "q").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Aggregate(Compiler compiler) + { + return new Query("X").SelectCount("*").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Aggregate_Alias(Compiler compiler) + { + return new Query("X").SelectCount("s.a as q").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Aggregate_Filter(Compiler compiler) + { + return new Query("X") + .SelectAggregate("t", "a", q => q.Where("b", 3)) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileColumnsAfterSelect + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Distinct(Compiler compiler) + { + return new Query("X").Distinct().Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Aggregate(Compiler compiler) + { + return new Query("X").AsMin("a").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Aggregate_Multiple_Columns(Compiler compiler) + { + return new Query("X") + .AsCount(new[] { "a", "b" }) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileJoin + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Without_Conditions(Compiler compiler) + { + return new Query("X").CrossJoin("Y").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task With_Conditions(Compiler compiler) + { + return new Query("X") + .Join("Y", on => on.On("a", "b")).Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileConditions + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task And_Condition(Compiler compiler) + { + return new Query("X") + .Where("a", 88).And().Where("b", 77) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Or_Condition(Compiler compiler) + { + return new Query("X") + .Where("a", 88).Or().Where("b", 77) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileRawCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task AppendRaw(Compiler compiler) + { + return new Query("X") + .WhereRaw("blah ? ? ?", 1, 2, 3) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileQueryCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task CompileSelectQuery(Compiler compiler) + { + return new Query("X") + .Where("a", "=", new Query("Y")) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileSubQueryCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task CompileSelectQuery(Compiler compiler) + { + return new Query("X") + .WhereSub(new Query("Y"), 52) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileBasicCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X").WhereNot("a", "k").Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileBasicStringCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Starts(Compiler compiler) + { + return new Query("X").WhereStarts("a", "k").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Ends(Compiler compiler) + { + return new Query("X").WhereEnds("a", "k").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Contains(Compiler compiler) + { + return new Query("X").WhereContains("a", "k").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task WhereLike(Compiler compiler) + { + return new Query("X").WhereLike("a", "k").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public void WhereNull(Compiler compiler) + { + Assert.Throws( + () => compiler.Compile( + new Query("X").WhereLike("a", null!))) + .Message.Should().Be("Expecting a non nullable string"); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public void WhereInt(Compiler compiler) + { + Assert.Throws( + () => compiler.Compile( + new Query("X").WhereLike("a", 123))) + .Message.Should().Be("Expecting a non nullable string"); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task WhereNotLike(Compiler compiler) + { + return new Query("X").WhereNotLike("a", "K").Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task CaseSensitive(Compiler compiler) + { + return new Query("X") + .WhereStarts("a", "K", true) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task EscapeCharacter(Compiler compiler) + { + return new Query("X") + .WhereStarts("a", "K*", escapeCharacter: '*') + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileBasicDateCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X").Not().WhereDatePart("year", "a", + new DateTime(2000, 1, 2, 3, 4, 5)).Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Time(Compiler compiler) + { + return new Query("X").Not().WhereDatePart("time", "a", + new DateTime(2000, 1, 2, 3, 4, 5)).Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Date(Compiler compiler) + { + return new Query("X").WhereDatePart("date", "a", + new DateTime(2000, 1, 2, 3, 4, 5)).Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Date_Not_DateTime(Compiler compiler) + { + return new Query("X") + .WhereDatePart("date", "a", "blah") + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Time_Not_DateTime(Compiler compiler) + { + return new Query("X") + .WhereDatePart("time", "a", "blah") + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Unknown_Part(Compiler compiler) + { + return new Query("X") + .WhereDatePart("BLAH", "a", 1) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileNestedCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .WhereNot(q => q.Where("a", 632)) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileTwoColumnsCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .Not().WhereColumns("a", "<>", "b") + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileBetweenCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Straight(Compiler compiler) + { + return new Query("X") + .WhereBetween("a", "aaa", "zzz") + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .WhereNotBetween("a", "0", "99") + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileInCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Straight(Compiler compiler) + { + return new Query("X") + .WhereIn("a", "aaa", "zzz") + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .OrWhereNotIn("a", "0", "99") + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Empty_Straight(Compiler compiler) + { + return new Query("X") + .WhereIn("a", Enumerable.Empty()) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Empty_Not(Compiler compiler) + { + return new Query("X") + .WhereNotIn("a", Enumerable.Empty()) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileInQueryCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Straight(Compiler compiler) + { + return new Query("X") + .WhereIn("a", new Query("Y")) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .WhereNotIn("a", new Query("Y")) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileNullCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Straight(Compiler compiler) + { + return new Query("X") + .WhereNull("a") + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Not(Compiler compiler) + { + return new Query("X") + .WhereNotNull("a") + .Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileBooleanCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Equal(Compiler compiler) + { + return new Query("X") + .WhereTrue("a") + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task NotEqual(Compiler compiler) + { + return new Query("X") + .Not().WhereTrue("a") + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task False(Compiler compiler) + { + return new Query("X") + .WhereTrue("a") + .OrWhereFalse("b") + .Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileExistsCondition + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Query(Compiler compiler) + { + return new Query("X") + .WhereExists(q => q.From("Y").Where("a", "=", 4)) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task SubQuery(Compiler compiler) + { + return new Query("X") + .WhereNotExists(new Query("Y")) + .Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileUnion + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Combine(Compiler compiler) + { + return new Query("X") + .Union(new Query("Y")) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Combine_All(Compiler compiler) + { + return new Query("X") + .ExceptAll(new Query("Y")) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Combine_Raw(Compiler compiler) + { + return new Query("X") + .CombineRaw("(Y ?)", 3) + .Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileCteQuery + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task RawFromClause(Compiler compiler) + { + return new Query("X") + .WithRaw("q", "{Y} ?", 70) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task QueryFromClause(Compiler compiler) + { + return new Query("X") + .With(q => q.Select("a").As("q")) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task AdHocTableFromClause(Compiler compiler) + { + return new Query("X") + .With("q", new[] { "a", "b", "c" }, + new[] + { + new object?[]{1, "k", null}, + new object?[]{2, null, "j"} + }) + .Verify(compiler); + } + + } + + [UsesVerify] + public sealed class CompileInsertQuery + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task SingleValue(Compiler compiler) + { + return new Query("X") + .AsInsert(new[] { "a" }, + new object?[] + { + new[] { 1 } + }) + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task MultiValue(Compiler compiler) + { + return new Query("X") + .AsInsert(new[] { "a" }, new[] + { + new object?[] { 1 }, + new object?[] { 2 } + }) + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task ReturnId(Compiler compiler) + { + return new Query("X") + .AsInsert(new { a = 3 }, true) + .Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task InsertQueryClause(Compiler compiler) + { + return new Query("X") + .AsInsert(new[] { "a" }, new Query("Y")) + .Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileDeleteQuery + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task No_Join(Compiler compiler) + { + return new Query("X").AsDelete().Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Join(Compiler compiler) + { + return new Query("X").CrossJoin("Y").AsDelete().Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public void Join_NoFrom(Compiler compiler) + { + Assert.Throws( + () => compiler.Compile(new Query().CrossJoin("Y").AsDelete())) + .Message.Should().Be("No table set to delete"); + } + } + + [UsesVerify] + public sealed class CompileUpdateQuery + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task CompileUpdate(Compiler compiler) + { + return new Query("X") + .AsUpdate(new { a = 1 }) + .Verify(compiler); + } + + [Theory] + [ClassData(typeof(AllCompilers))] + public Task CompileIncrement(Compiler compiler) + { + return new Query("X") + .AsIncrement("a") + .Verify(compiler); + } + } + [UsesVerify] + public sealed class WriteTable + { + [Theory] + [ClassData(typeof(AllCompilers))] + public void No_FromClause(Compiler compiler) + { + Assert.Throws( + () => compiler.Compile(new Query().AsDelete())) + .Message.Should().Be("No table set to delete"); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task RawFromClause(Compiler compiler) + { + return new Query() + .AsDelete() + .FromRaw("{X} ?", 1) + .Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileGroups + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Trivial(Compiler compiler) + { + return new Query().GroupBy("a").Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileOrders + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task OrderBy(Compiler compiler) + { + return new Query().OrderBy("a").Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task OrderByDesc(Compiler compiler) + { + return new Query().OrderByDesc("a").Verify(compiler); + } + [Theory] + [ClassData(typeof(AllCompilers))] + public Task OrderByRaw(Compiler compiler) + { + return new Query().OrderByRaw("{X} ?", 1).Verify(compiler); + } + } + + [UsesVerify] + public sealed class CompileHaving + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Trivial(Compiler compiler) + { + return new Query().Having("a", 1).Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileRaw + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task IsDistinct(Compiler compiler) + { + return new Query().AsMax("a").Distinct().Verify(compiler); + } + } + [UsesVerify] + public sealed class CompileLimit + { + [Theory] + [ClassData(typeof(AllCompilers))] + public Task Limit_Offset(Compiler compiler) + { + return new Query().Limit(1).Offset(7).Verify(compiler); + } + } +} diff --git a/QueryBuilder.Tests/ApprovalTests/Utils/AllCompilers.cs b/QueryBuilder.Tests/ApprovalTests/Utils/AllCompilers.cs new file mode 100644 index 00000000..b217a6ed --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/Utils/AllCompilers.cs @@ -0,0 +1,52 @@ +using System.Text; +using SqlKata.Compilers; + +namespace SqlKata.Tests.ApprovalTests.Utils +{ + public static class MyVerify + { + public static Task Verify(this Query query, + Compiler compiler) + { + var sqlResult = compiler.Compile(query); + var sb = new StringBuilder(); + sb.AppendLine("-------- ORIGINAL -----------"); + sb.Append(sqlResult); + sb.AppendLine(); + sb.AppendLine(); + sb.AppendLine("----------- RAW -------------"); + sb.Append(sqlResult.RawSql); + sb.AppendLine(); + sb.AppendLine(); + sb.AppendLine("--------PARAMETRIZED --------"); + sb.Append(sqlResult.Sql); + + var compilerName = compiler.GetType().Name; + if (compiler is SqlServerCompiler { UseLegacyPagination: true }) + compilerName += " with LegacyPagination"; + if (compiler is OracleCompiler { UseLegacyPagination: true }) + compilerName += " with LegacyPagination"; + if (!compiler.OmitSelectInsideExists ) + compilerName += " with SelectInsideExists"; + return Verifier.Verify(sb.ToString(), "sql") + .UseTextForParameters(compilerName) + .UseDirectory("../Output"); + } + } + public class AllCompilers : List + { + public AllCompilers() + { + Add(new object[] { new FirebirdCompiler() }); + Add(new object[] { new Compiler() }); + Add(new object[] { new Compiler {OmitSelectInsideExists = false}}); + Add(new object[] { new MySqlCompiler() }); + Add(new object[] { new OracleCompiler() }); + Add(new object[] { new PostgresCompiler() }); + Add(new object[] { new SqliteCompiler() }); + Add(new object[] { new SqlServerCompiler() }); + Add(new object[] { new SqlServerCompiler {UseLegacyPagination = true} }); + Add(new object[] { new OracleCompiler() {UseLegacyPagination = true} }); + } + } +} diff --git a/QueryBuilder.Tests/ApprovalTests/Utils/ModuleInitializer.cs b/QueryBuilder.Tests/ApprovalTests/Utils/ModuleInitializer.cs new file mode 100644 index 00000000..12fa3380 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/Utils/ModuleInitializer.cs @@ -0,0 +1,36 @@ +using System.Runtime.CompilerServices; +using DiffEngine; + +namespace SqlKata.Tests.ApprovalTests.Utils +{ + public static class ModuleInitializer + { + [ModuleInitializer] + public static void Initialize() => + VerifyDiffPlex.Initialize(); + + [ModuleInitializer] + public static void OtherInitialize() + { + DiffTools.AddToolBasedOn(DiffTool.AraxisMerge, "araxis"); + + VerifierSettings.InitializePlugins(); + VerifierSettings.ScrubLinesContaining("DiffEngineTray"); + VerifierSettings.IgnoreStackTrace(); + VerifierSettings.AddScrubber(x => x + .Replace("SELECT", "\nSELECT") + .Replace("INNER", "\nINNER") + .Replace("FROM", "\nFROM") + .Replace("WHERE", "\nWHERE") + .Replace("ORDER BY ", "\nORDER BY ") + .Replace("AND", "\nAND") + .Replace("OR ", "\nOR ") + .Replace("ROWS ", "\nROWS ") + .Replace("UNION ", "\nUNION ") + .Replace("VALUES ", "\nVALUES ") + .Replace("), (", "), \n(") + .Replace("AS tbl", "\nAS tbl") + ); + } + } +} diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..7ad45ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..7ad45ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..5163b85a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("A" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("A" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("A" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..dfaafbb1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT (`a` = 'k') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT (`a` = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT (`a` = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2f489f22 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..2f489f22 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..7ad45ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3e859e0f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT ([a] = 'k') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT ([a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT ([a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..3e859e0f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT ([a] = 'k') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT ([a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT ([a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..7ad45ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..6af3ae21 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE DATE("a") = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE DATE("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE DATE("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler.verified.sql new file mode 100644 index 00000000..6af3ae21 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE DATE("a") = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE DATE("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE DATE("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..0ca02fd8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_MySqlCompiler.verified.sql new file mode 100644 index 00000000..df2683a1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..d6b8a4e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE DATE("a") = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE DATE("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE DATE("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler.verified.sql new file mode 100644 index 00000000..d6b8a4e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE DATE("a") = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE DATE("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE DATE("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..285bb222 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE CAST("A" as DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_MySqlCompiler.verified.sql new file mode 100644 index 00000000..ce022101 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE DATE(`a`) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e90f6dbb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE('blah', 'YY-MM-DD'), 'YY-MM-DD') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE(:p0, 'YY-MM-DD'), 'YY-MM-DD') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler.verified.sql new file mode 100644 index 00000000..e90f6dbb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE('blah', 'YY-MM-DD'), 'YY-MM-DD') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(TO_DATE(:p0, 'YY-MM-DD'), 'YY-MM-DD') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_PostgresCompiler.verified.sql new file mode 100644 index 00000000..8ac52a2a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a"::date = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a"::date = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a"::date = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..9e3cf64d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..9e3cf64d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqliteCompiler.verified.sql new file mode 100644 index 00000000..445fc540 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_Not_DateTime_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast('blah' as text) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast(? as text) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast(@p0 as text) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..9b00aec4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR('2000-01-02 03:04:05', 'YY-MM-DD') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(?, 'YY-MM-DD') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(:p0, 'YY-MM-DD') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler.verified.sql new file mode 100644 index 00000000..9b00aec4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR('2000-01-02 03:04:05', 'YY-MM-DD') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(?, 'YY-MM-DD') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'YY-MM-DD') = TO_CHAR(:p0, 'YY-MM-DD') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_PostgresCompiler.verified.sql new file mode 100644 index 00000000..1988a2b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a"::date = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a"::date = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a"::date = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..613148be --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..613148be --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = '2000-01-02 03:04:05' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS DATE) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqliteCompiler.verified.sql new file mode 100644 index 00000000..47b279d7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Date_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast('2000-01-02 03:04:05' as text) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast(? as text) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE strftime('%Y-%m-%d', "a") = cast(@p0 as text) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..3ea6dd80 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..3ea6dd80 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (YEAR("a") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..ebe12de6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "A") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "A") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "A") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..3e71b3ff --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT (YEAR(`a`) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT (YEAR(`a`) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT (YEAR(`a`) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e6326a64 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..e6326a64 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (EXTRACT(YEAR +FROM "a") = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..2ad44030 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (DATE_PART('YEAR', "a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (DATE_PART('YEAR', "a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (DATE_PART('YEAR', "a") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4fffca74 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..4fffca74 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (DATEPART(YEAR, [a]) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..492ab1cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%Y', "a") = cast('2000-01-02 03:04:05' as text)) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%Y', "a") = cast(? as text)) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%Y', "a") = cast(@p0 as text)) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..fe82c5db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler.verified.sql new file mode 100644 index 00000000..fe82c5db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (TIME("a") = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..593f97a0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (CAST("A" as TIME) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (CAST("A" as TIME) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (CAST("A" as TIME) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_MySqlCompiler.verified.sql new file mode 100644 index 00000000..7725cdba --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT (TIME(`a`) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT (TIME(`a`) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT (TIME(`a`) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..e99a1950 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TIME("a") = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TIME("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TIME("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler.verified.sql new file mode 100644 index 00000000..e99a1950 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TIME("a") = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TIME("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TIME("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..078f25af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE CAST("A" as TIME) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE CAST("A" as TIME) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE CAST("A" as TIME) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_MySqlCompiler.verified.sql new file mode 100644 index 00000000..99dea93b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE TIME(`a`) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE TIME(`a`) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE TIME(`a`) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..1f761c33 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE('blah', 'HH24:MI:SS'), 'HH24:MI:SS') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE(:p0, 'HH24:MI:SS'), 'HH24:MI:SS') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler.verified.sql new file mode 100644 index 00000000..1f761c33 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE('blah', 'HH24:MI:SS'), 'HH24:MI:SS') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS') + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(TO_DATE(:p0, 'HH24:MI:SS'), 'HH24:MI:SS') \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4cf1ee0a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a"::time = 'blah' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a"::time = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a"::time = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..050f41f9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..050f41f9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = 'blah' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE CAST([a] AS TIME) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqliteCompiler.verified.sql new file mode 100644 index 00000000..99277401 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_Not_DateTime_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE strftime('%H:%M:%S', "a") = cast('blah' as text) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE strftime('%H:%M:%S', "a") = cast(? as text) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE strftime('%H:%M:%S', "a") = cast(@p0 as text) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..04735f59 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR('2000-01-02 03:04:05', 'HH24:MI:SS')) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(?, 'HH24:MI:SS')) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(:p0, 'HH24:MI:SS')) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler.verified.sql new file mode 100644 index 00000000..04735f59 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR('2000-01-02 03:04:05', 'HH24:MI:SS')) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(?, 'HH24:MI:SS')) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (TO_CHAR("a", 'HH24:MI:SS') = TO_CHAR(:p0, 'HH24:MI:SS')) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_PostgresCompiler.verified.sql new file mode 100644 index 00000000..e174faea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a"::time = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a"::time = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a"::time = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2c65b8df --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..2c65b8df --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = '2000-01-02 03:04:05') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (CAST([a] AS TIME) = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqliteCompiler.verified.sql new file mode 100644 index 00000000..f05b9cb7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Time_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%H:%M:%S', "a") = cast('2000-01-02 03:04:05' as text)) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%H:%M:%S', "a") = cast(? as text)) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (strftime('%H:%M:%S', "a") = cast(@p0 as text)) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..bed1701b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE BLAH("a") = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE BLAH("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE BLAH("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler.verified.sql new file mode 100644 index 00000000..bed1701b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE BLAH("a") = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE BLAH("a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE BLAH("a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..bb2115ad --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXTRACT(BLAH +FROM "A") = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXTRACT(BLAH +FROM "A") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXTRACT(BLAH +FROM "A") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_MySqlCompiler.verified.sql new file mode 100644 index 00000000..5d54bbdd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE BLAH(`a`) = 1 + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE BLAH(`a`) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE BLAH(`a`) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4e41ffbf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler.verified.sql new file mode 100644 index 00000000..4e41ffbf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_PostgresCompiler.verified.sql new file mode 100644 index 00000000..e1f83950 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE DATE_PART('BLAH', "a") = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE DATE_PART('BLAH', "a") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE DATE_PART('BLAH', "a") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b8b5ab0f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = 1 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..b8b5ab0f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = 1 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE DATEPART(BLAH, [a]) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqliteCompiler.verified.sql new file mode 100644 index 00000000..2c1edd13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicDateCondition.Unknown_Part_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..54f4bed2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler.verified.sql new file mode 100644 index 00000000..54f4bed2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..c7c8d43a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_MySqlCompiler.verified.sql new file mode 100644 index 00000000..bb087e89 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` like 'K%' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..681a4453 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler.verified.sql new file mode 100644 index 00000000..681a4453 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_PostgresCompiler.verified.sql new file mode 100644 index 00000000..54f4bed2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5882dbe5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] like 'K%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..5882dbe5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] like 'K%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqliteCompiler.verified.sql new file mode 100644 index 00000000..54f4bed2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.CaseSensitive_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" like 'K%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..53c82ad5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler.verified.sql new file mode 100644 index 00000000..53c82ad5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..63f224a8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("A") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("A") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("A") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_MySqlCompiler.verified.sql new file mode 100644 index 00000000..edd63e17 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like '%k%' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a0f5b7b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler.verified.sql new file mode 100644 index 00000000..a0f5b7b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_PostgresCompiler.verified.sql new file mode 100644 index 00000000..2f670742 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" ilike '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" ilike ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" ilike @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4437e01d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like '%k%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..4437e01d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like '%k%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqliteCompiler.verified.sql new file mode 100644 index 00000000..53c82ad5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Contains_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..f0eafa55 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler.verified.sql new file mode 100644 index 00000000..f0eafa55 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..47f11e6f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("A") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("A") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("A") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_MySqlCompiler.verified.sql new file mode 100644 index 00000000..5ae9c0a1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like '%k' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6cec0e72 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler.verified.sql new file mode 100644 index 00000000..6cec0e72 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_PostgresCompiler.verified.sql new file mode 100644 index 00000000..7475992d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" ilike '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" ilike ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" ilike @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8f6ca9e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like '%k' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..8f6ca9e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like '%k' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqliteCompiler.verified.sql new file mode 100644 index 00000000..f0eafa55 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Ends_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like '%k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..e8abf7d2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler.verified.sql new file mode 100644 index 00000000..e8abf7d2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..ea6b27d0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("A") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("A") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("A") like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_MySqlCompiler.verified.sql new file mode 100644 index 00000000..9aa74ec8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..0f328d27 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler.verified.sql new file mode 100644 index 00000000..0f328d27 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_PostgresCompiler.verified.sql new file mode 100644 index 00000000..df7f1f5f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" ilike 'K*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" ilike ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" ilike @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3210ecd6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..3210ecd6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqliteCompiler.verified.sql new file mode 100644 index 00000000..e8abf7d2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.EscapeCharacter_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k*%' ESCAPE '*' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? ESCAPE '*' + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 ESCAPE '*' \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..828ffa3d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler.verified.sql new file mode 100644 index 00000000..828ffa3d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..12a290e3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("A") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("A") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("A") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_MySqlCompiler.verified.sql new file mode 100644 index 00000000..170f23a1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like 'k%' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..956a7e1b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler.verified.sql new file mode 100644 index 00000000..956a7e1b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_PostgresCompiler.verified.sql new file mode 100644 index 00000000..fc20bd35 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" ilike 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" ilike ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" ilike @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..26a6c307 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..26a6c307 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k%' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqliteCompiler.verified.sql new file mode 100644 index 00000000..828ffa3d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.Starts_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k%' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..1300f398 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler.verified.sql new file mode 100644 index 00000000..1300f398 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..0e6a81eb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("A") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("A") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("A") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_MySqlCompiler.verified.sql new file mode 100644 index 00000000..24aff5c5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like 'k' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE LOWER(`a`) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4550a6e9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler.verified.sql new file mode 100644 index 00000000..4550a6e9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_PostgresCompiler.verified.sql new file mode 100644 index 00000000..b3ece0be --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" ilike 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" ilike ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" ilike @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6a4c55e9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..6a4c55e9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like 'k' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE LOWER([a]) like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqliteCompiler.verified.sql new file mode 100644 index 00000000..1300f398 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereLike_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE LOWER("a") like 'k' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE LOWER("a") like ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE LOWER("a") like @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..e99edead --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler.verified.sql new file mode 100644 index 00000000..e99edead --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..c0a79122 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("A") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("A") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("A") like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_MySqlCompiler.verified.sql new file mode 100644 index 00000000..19f9af28 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT (LOWER(`a`) like 'k') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT (LOWER(`a`) like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT (LOWER(`a`) like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c04ec48e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler.verified.sql new file mode 100644 index 00000000..c04ec48e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_PostgresCompiler.verified.sql new file mode 100644 index 00000000..6f57a19a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" ilike 'K') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" ilike ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" ilike @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f4957b81 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like 'k') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..f4957b81 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like 'k') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT (LOWER([a]) like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqliteCompiler.verified.sql new file mode 100644 index 00000000..e99edead --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBasicStringCondition.WhereNotLike_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like 'k') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT (LOWER("a") like @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..38e4c2c9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..38e4c2c9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..9e998934 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..fbc1a2e6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b488a067 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN :p0 +AND :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..b488a067 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN :p0 +AND :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..38e4c2c9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4e31a7dc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..4e31a7dc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..38e4c2c9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN '0' +AND '99' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..5905b651 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler.verified.sql new file mode 100644 index 00000000..5905b651 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..8dcb07b4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_MySqlCompiler.verified.sql new file mode 100644 index 00000000..53a859c3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e2116f8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN :p0 +AND :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler.verified.sql new file mode 100644 index 00000000..e2116f8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN :p0 +AND :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_PostgresCompiler.verified.sql new file mode 100644 index 00000000..5905b651 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8014c43f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..8014c43f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqliteCompiler.verified.sql new file mode 100644 index 00000000..5905b651 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBetweenCondition.Straight_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN 'aaa' +AND 'zzz' + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..cd470104 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler.verified.sql new file mode 100644 index 00000000..cd470104 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..a0758b27 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" = 1 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" = 1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_MySqlCompiler.verified.sql new file mode 100644 index 00000000..533ac1d7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` = true + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` = true + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..cd470104 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler.verified.sql new file mode 100644 index 00000000..cd470104 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_PostgresCompiler.verified.sql new file mode 100644 index 00000000..cd470104 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..55ef631a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..55ef631a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqliteCompiler.verified.sql new file mode 100644 index 00000000..2b04818c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.Equal_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = 1 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = 1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..f6613f9c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler.verified.sql new file mode 100644 index 00000000..f6613f9c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..3315f543 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" = 1 +OR "B" = 0 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" = 1 +OR "B" = 0 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" = 1 +OR "B" = 0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_MySqlCompiler.verified.sql new file mode 100644 index 00000000..88873f39 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` = true +OR `b` = false + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` = true +OR `b` = false + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` = true +OR `b` = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f6613f9c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler.verified.sql new file mode 100644 index 00000000..f6613f9c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_PostgresCompiler.verified.sql new file mode 100644 index 00000000..f6613f9c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = true +OR "b" = false \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..97ac8491 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..97ac8491 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = cast(1 as bit) +OR [b] = cast(0 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqliteCompiler.verified.sql new file mode 100644 index 00000000..66e5ba1b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.False_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 1 +OR "b" = 0 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = 1 +OR "b" = 0 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = 1 +OR "b" = 0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..784631d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler.verified.sql new file mode 100644 index 00000000..784631d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..31b94d06 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" != 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" != 1 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" != 1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_MySqlCompiler.verified.sql new file mode 100644 index 00000000..2561ec1f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` != true + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` != true + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..784631d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler.verified.sql new file mode 100644 index 00000000..784631d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_PostgresCompiler.verified.sql new file mode 100644 index 00000000..784631d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != true + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != true + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != true \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2fd23a03 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..2fd23a03 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] != cast(1 as bit) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqliteCompiler.verified.sql new file mode 100644 index 00000000..3088b20f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileBooleanCondition.NotEqual_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" != 1 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" != 1 + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" != 1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..481b82a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler.verified.sql new file mode 100644 index 00000000..481b82a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..70a68a80 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("S"."A") AS "Q" +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("S"."A") AS "Q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("S"."A") AS "Q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_MySqlCompiler.verified.sql new file mode 100644 index 00000000..2ba1a205 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(`s`.`a`) AS `q` +FROM `X` + +----------- RAW ------------- + +SELECT COUNT(`s`.`a`) AS `q` +FROM `X` + +--------PARAMETRIZED -------- + +SELECT COUNT(`s`.`a`) AS `q` +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5187a672 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a" "q") +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a" "q") +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a" "q") +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler.verified.sql new file mode 100644 index 00000000..5187a672 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a" "q") +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a" "q") +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a" "q") +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_PostgresCompiler.verified.sql new file mode 100644 index 00000000..481b82a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..88205b69 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] + +----------- RAW ------------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..88205b69 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] + +----------- RAW ------------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT COUNT([s].[a]) AS [q] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqliteCompiler.verified.sql new file mode 100644 index 00000000..481b82a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Alias_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT("s"."a") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..678a4950 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN "b" = 3 THEN "a" END) +FROM "X" + +----------- RAW ------------- + +SELECT T(CASE WHEN "b" = ? THEN "a" END) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN "b" = @p0 THEN "a" END) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler.verified.sql new file mode 100644 index 00000000..678a4950 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN "b" = 3 THEN "a" END) +FROM "X" + +----------- RAW ------------- + +SELECT T(CASE WHEN "b" = ? THEN "a" END) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN "b" = @p0 THEN "a" END) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..bbb0c8d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN "B" = 3 THEN "A" END) +FROM "X" + +----------- RAW ------------- + +SELECT T(CASE WHEN "B" = ? THEN "A" END) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN "B" = @p0 THEN "A" END) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_MySqlCompiler.verified.sql new file mode 100644 index 00000000..9a7d071f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN `b` = 3 THEN `a` END) +FROM `X` + +----------- RAW ------------- + +SELECT T(CASE WHEN `b` = ? THEN `a` END) +FROM `X` + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN `b` = @p0 THEN `a` END) +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c925a392 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN "b" = 3 THEN "a" END) +FROM "X" + +----------- RAW ------------- + +SELECT T(CASE WHEN "b" = ? THEN "a" END) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN "b" = :p0 THEN "a" END) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler.verified.sql new file mode 100644 index 00000000..c925a392 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN "b" = 3 THEN "a" END) +FROM "X" + +----------- RAW ------------- + +SELECT T(CASE WHEN "b" = ? THEN "a" END) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN "b" = :p0 THEN "a" END) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_PostgresCompiler.verified.sql new file mode 100644 index 00000000..c268fcf8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT T("a") FILTER ( +WHERE "b" = 3) +FROM "X" + +----------- RAW ------------- + +SELECT T("a") FILTER ( +WHERE "b" = ?) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T("a") FILTER ( +WHERE "b" = @p0) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3c16c0e3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN [b] = 3 THEN [a] END) +FROM [X] + +----------- RAW ------------- + +SELECT T(CASE WHEN [b] = ? THEN [a] END) +FROM [X] + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN [b] = @p0 THEN [a] END) +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..3c16c0e3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT T(CASE WHEN [b] = 3 THEN [a] END) +FROM [X] + +----------- RAW ------------- + +SELECT T(CASE WHEN [b] = ? THEN [a] END) +FROM [X] + +--------PARAMETRIZED -------- + +SELECT T(CASE WHEN [b] = @p0 THEN [a] END) +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqliteCompiler.verified.sql new file mode 100644 index 00000000..c268fcf8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_Filter_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT T("a") FILTER ( +WHERE "b" = 3) +FROM "X" + +----------- RAW ------------- + +SELECT T("a") FILTER ( +WHERE "b" = ?) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT T("a") FILTER ( +WHERE "b" = @p0) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_MySqlCompiler.verified.sql new file mode 100644 index 00000000..85b04105 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM `X` + +----------- RAW ------------- + +SELECT COUNT(*) +FROM `X` + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_PostgresCompiler.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..aedfe40a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM [X] + +----------- RAW ------------- + +SELECT COUNT(*) +FROM [X] + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..aedfe40a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM [X] + +----------- RAW ------------- + +SELECT COUNT(*) +FROM [X] + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqliteCompiler.verified.sql new file mode 100644 index 00000000..7b4deb7d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.Aggregate_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) +FROM "X" + +----------- RAW ------------- + +SELECT COUNT(*) +FROM "X" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..f3cd816a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", @p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler.verified.sql new file mode 100644 index 00000000..f3cd816a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", @p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..f3cd816a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", @p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_MySqlCompiler.verified.sql new file mode 100644 index 00000000..fc3b159b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT `1`, 'p' +FROM `X` + +----------- RAW ------------- + +SELECT `1`, ? +FROM `X` + +--------PARAMETRIZED -------- + +SELECT `1`, @p0 +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..7adaa630 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", :p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler.verified.sql new file mode 100644 index 00000000..7adaa630 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", :p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_PostgresCompiler.verified.sql new file mode 100644 index 00000000..f3cd816a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", @p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f4e4b33b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT [1], 'p' +FROM [X] + +----------- RAW ------------- + +SELECT [1], ? +FROM [X] + +--------PARAMETRIZED -------- + +SELECT [1], @p0 +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..f4e4b33b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT [1], 'p' +FROM [X] + +----------- RAW ------------- + +SELECT [1], ? +FROM [X] + +--------PARAMETRIZED -------- + +SELECT [1], @p0 +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqliteCompiler.verified.sql new file mode 100644 index 00000000..f3cd816a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.RawColumn_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "1", 'p' +FROM "X" + +----------- RAW ------------- + +SELECT "1", ? +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "1", @p0 +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..236da032 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler.verified.sql new file mode 100644 index 00000000..236da032 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..b4918e07 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") AS "Q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") AS "Q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") AS "Q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_MySqlCompiler.verified.sql new file mode 100644 index 00000000..1e11df60 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM `Y`) AS `q` +FROM `X` + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM `Y`) AS `q` +FROM `X` + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM `Y`) AS `q` +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8ddd7901 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler.verified.sql new file mode 100644 index 00000000..8ddd7901 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_PostgresCompiler.verified.sql new file mode 100644 index 00000000..236da032 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..46c3ab6d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..46c3ab6d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM [Y]) AS [q] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqliteCompiler.verified.sql new file mode 100644 index 00000000..236da032 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnList.SubQuery_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +----------- RAW ------------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT ( +SELECT * +FROM "Y") AS "q" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..bc9c6b4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler.verified.sql new file mode 100644 index 00000000..bc9c6b4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..760ac173 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler.verified.sql new file mode 100644 index 00000000..760ac173 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..633b4943 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT FIRST 3 DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT FIRST ? DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT FIRST @p0 DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_MySqlCompiler.verified.sql new file mode 100644 index 00000000..44c4123d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM `X` LIMIT 3 + +----------- RAW ------------- + +SELECT DISTINCT * +FROM `X` LIMIT ? + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM `X` LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..862ba965 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT DISTINCT * +FROM "X") +WHERE ROWNUM <= 3 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT DISTINCT * +FROM "X") +WHERE ROWNUM <= ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT DISTINCT * +FROM "X") +WHERE ROWNUM <= :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler.verified.sql new file mode 100644 index 00000000..b3c28e45 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_OracleCompiler.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET 0 +ROWS FETCH NEXT 3 +ROWS ONLY + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET :p0 +ROWS FETCH NEXT :p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_PostgresCompiler.verified.sql new file mode 100644 index 00000000..760ac173 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..450593f9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT TOP (3) * +FROM [X] + +----------- RAW ------------- + +SELECT DISTINCT TOP (?) * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT DISTINCT TOP (@p0) * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..42a01f39 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqlServerCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET 0 +ROWS FETCH NEXT 3 +ROWS ONLY + +----------- RAW ------------- + +SELECT DISTINCT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET @p0 +ROWS FETCH NEXT @p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqliteCompiler.verified.sql new file mode 100644 index 00000000..760ac173 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_Distinct_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..a76dd024 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT FIRST 3 * +FROM "X" + +----------- RAW ------------- + +SELECT FIRST ? * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT FIRST @p0 * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_MySqlCompiler.verified.sql new file mode 100644 index 00000000..7173fddc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` LIMIT 3 + +----------- RAW ------------- + +SELECT * +FROM `X` LIMIT ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e00ebb4d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "X") +WHERE ROWNUM <= 3 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "X") +WHERE ROWNUM <= ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "X") +WHERE ROWNUM <= :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler.verified.sql new file mode 100644 index 00000000..978c35a1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_OracleCompiler.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET 0 +ROWS FETCH NEXT 3 +ROWS ONLY + +----------- RAW ------------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET :p0 +ROWS FETCH NEXT :p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_PostgresCompiler.verified.sql new file mode 100644 index 00000000..bc9c6b4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..9e0351a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT TOP (3) * +FROM [X] + +----------- RAW ------------- + +SELECT TOP (?) * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT TOP (@p0) * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..d6c295ec --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqlServerCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET 0 +ROWS FETCH NEXT 3 +ROWS ONLY + +----------- RAW ------------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET @p0 +ROWS FETCH NEXT @p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqliteCompiler.verified.sql new file mode 100644 index 00000000..bc9c6b4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Limit_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" LIMIT 3 + +----------- RAW ------------- + +SELECT * +FROM "X" LIMIT ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" LIMIT @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..99463bf0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" OFFSET 4 + +----------- RAW ------------- + +SELECT * +FROM "X" OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" OFFSET @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler.verified.sql new file mode 100644 index 00000000..99463bf0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" OFFSET 4 + +----------- RAW ------------- + +SELECT * +FROM "X" OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" OFFSET @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..4fa7e913 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT SKIP 4 * +FROM "X" + +----------- RAW ------------- + +SELECT SKIP ? * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT SKIP @p0 * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_MySqlCompiler.verified.sql new file mode 100644 index 00000000..40a845e9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` LIMIT 18446744073709551615 OFFSET 4 + +----------- RAW ------------- + +SELECT * +FROM `X` LIMIT 18446744073709551615 OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` LIMIT 18446744073709551615 OFFSET @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f7dd1323 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT * +FROM "X") "results_wrapper") +WHERE "row_num" > 4 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT * +FROM "X") "results_wrapper") +WHERE "row_num" > ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT * +FROM "X") "results_wrapper") +WHERE "row_num" > :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler.verified.sql new file mode 100644 index 00000000..ecfa93b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET 4 ROWS + +----------- RAW ------------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET ? ROWS + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET :p0 ROWS \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_PostgresCompiler.verified.sql new file mode 100644 index 00000000..99463bf0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" OFFSET 4 + +----------- RAW ------------- + +SELECT * +FROM "X" OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" OFFSET @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..d70a4ae9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num] +FROM [X]) AS [results_wrapper] +WHERE [row_num] >= 5 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num] +FROM [X]) AS [results_wrapper] +WHERE [row_num] >= ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num] +FROM [X]) AS [results_wrapper] +WHERE [row_num] >= @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..25af6fd5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET 4 ROWS + +----------- RAW ------------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET ? ROWS + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +ORDER BY ( +SELECT 0) OFFSET @p0 ROWS \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqliteCompiler.verified.sql new file mode 100644 index 00000000..54382b7e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumns.Offset_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" LIMIT -1 OFFSET 4 + +----------- RAW ------------- + +SELECT * +FROM "X" LIMIT -1 OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" LIMIT -1 OFFSET @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..b0f3e271 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") AS "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") AS "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") AS "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler.verified.sql new file mode 100644 index 00000000..b0f3e271 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") AS "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") AS "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") AS "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..e2275450 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("A") AS "MIN" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("A") AS "MIN" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("A") AS "MIN" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..3094cc5e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler.verified.sql new file mode 100644 index 00000000..3094cc5e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_Compiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..45a84cfb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_FirebirdCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS "COUNT" +FROM ( +SELECT 1 +FROM "X" +WHERE "A" IS NOT NULL +AND "B" IS NOT NULL) AS "COUNTQUERY" + +----------- RAW ------------- + +SELECT COUNT(*) AS "COUNT" +FROM ( +SELECT 1 +FROM "X" +WHERE "A" IS NOT NULL +AND "B" IS NOT NULL) AS "COUNTQUERY" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS "COUNT" +FROM ( +SELECT 1 +FROM "X" +WHERE "A" IS NOT NULL +AND "B" IS NOT NULL) AS "COUNTQUERY" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_MySqlCompiler.verified.sql new file mode 100644 index 00000000..dd1451ad --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_MySqlCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS `count` +FROM ( +SELECT 1 +FROM `X` +WHERE `a` IS NOT NULL +AND `b` IS NOT NULL) AS `countQuery` + +----------- RAW ------------- + +SELECT COUNT(*) AS `count` +FROM ( +SELECT 1 +FROM `X` +WHERE `a` IS NOT NULL +AND `b` IS NOT NULL) AS `countQuery` + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS `count` +FROM ( +SELECT 1 +FROM `X` +WHERE `a` IS NOT NULL +AND `b` IS NOT NULL) AS `countQuery` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b57e335d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler.verified.sql new file mode 100644 index 00000000..b57e335d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_OracleCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_PostgresCompiler.verified.sql new file mode 100644 index 00000000..3094cc5e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_PostgresCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..0e0f1f78 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] + +----------- RAW ------------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..0e0f1f78 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqlServerCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] + +----------- RAW ------------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS [count] +FROM ( +SELECT 1 +FROM [X] +WHERE [a] IS NOT NULL +AND [b] IS NOT NULL) AS [countQuery] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqliteCompiler.verified.sql new file mode 100644 index 00000000..3094cc5e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_Multiple_Columns_SqliteCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +----------- RAW ------------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" + +--------PARAMETRIZED -------- + +SELECT COUNT(*) AS "count" +FROM ( +SELECT 1 +FROM "X" +WHERE "a" IS NOT NULL +AND "b" IS NOT NULL) AS "countQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_MySqlCompiler.verified.sql new file mode 100644 index 00000000..c1568e68 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN(`a`) AS `min` +FROM `X` + +----------- RAW ------------- + +SELECT MIN(`a`) AS `min` +FROM `X` + +--------PARAMETRIZED -------- + +SELECT MIN(`a`) AS `min` +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6b5bbfbd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler.verified.sql new file mode 100644 index 00000000..6b5bbfbd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_PostgresCompiler.verified.sql new file mode 100644 index 00000000..b0f3e271 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") AS "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") AS "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") AS "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a1d40559 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN([a]) AS [min] +FROM [X] + +----------- RAW ------------- + +SELECT MIN([a]) AS [min] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT MIN([a]) AS [min] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..a1d40559 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN([a]) AS [min] +FROM [X] + +----------- RAW ------------- + +SELECT MIN([a]) AS [min] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT MIN([a]) AS [min] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqliteCompiler.verified.sql new file mode 100644 index 00000000..b0f3e271 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Aggregate_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT MIN("a") AS "min" +FROM "X" + +----------- RAW ------------- + +SELECT MIN("a") AS "min" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT MIN("a") AS "min" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_MySqlCompiler.verified.sql new file mode 100644 index 00000000..6b8c2078 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM `X` + +----------- RAW ------------- + +SELECT DISTINCT * +FROM `X` + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_PostgresCompiler.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c647c038 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM [X] + +----------- RAW ------------- + +SELECT DISTINCT * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..c647c038 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM [X] + +----------- RAW ------------- + +SELECT DISTINCT * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqliteCompiler.verified.sql new file mode 100644 index 00000000..47d207cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileColumnsAfterSelect.Distinct_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT DISTINCT * +FROM "X" + +----------- RAW ------------- + +SELECT DISTINCT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT DISTINCT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..a71b6323 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +AND "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler.verified.sql new file mode 100644 index 00000000..a71b6323 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +AND "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..493eb721 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" = 88 +AND "B" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" = ? +AND "B" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" = @p0 +AND "B" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_MySqlCompiler.verified.sql new file mode 100644 index 00000000..6310b1e3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` = 88 +AND `b` = 77 + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` = ? +AND `b` = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` = @p0 +AND `b` = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8d618bd4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 +AND "b" = :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler.verified.sql new file mode 100644 index 00000000..8d618bd4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 +AND "b" = :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_PostgresCompiler.verified.sql new file mode 100644 index 00000000..a71b6323 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +AND "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..840dcb0c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = 88 +AND [b] = 77 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ? +AND [b] = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = @p0 +AND [b] = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..840dcb0c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = 88 +AND [b] = 77 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ? +AND [b] = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = @p0 +AND [b] = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqliteCompiler.verified.sql new file mode 100644 index 00000000..a71b6323 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.And_Condition_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +AND "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +AND "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +AND "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..43eb5efe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +OR "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler.verified.sql new file mode 100644 index 00000000..43eb5efe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +OR "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..37b5d424 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" = 88 +OR "B" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" = ? +OR "B" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" = @p0 +OR "B" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_MySqlCompiler.verified.sql new file mode 100644 index 00000000..182aedb4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` = 88 +OR `b` = 77 + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` = ? +OR `b` = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` = @p0 +OR `b` = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8b1aed27 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 +OR "b" = :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler.verified.sql new file mode 100644 index 00000000..8b1aed27 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = :p0 +OR "b" = :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_PostgresCompiler.verified.sql new file mode 100644 index 00000000..43eb5efe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +OR "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..83b29885 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = 88 +OR [b] = 77 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ? +OR [b] = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = @p0 +OR [b] = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..83b29885 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = 88 +OR [b] = 77 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ? +OR [b] = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = @p0 +OR [b] = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqliteCompiler.verified.sql new file mode 100644 index 00000000..43eb5efe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileConditions.Or_Condition_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = 88 +OR "b" = 77 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ? +OR "b" = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = @p0 +OR "b" = @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..f9e830b6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT @p0 AS "a", @p1 AS "b", @p2 AS "c" +UNION ALL +SELECT @p3 AS "a", @p4 AS "b", @p5 AS "c") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler.verified.sql new file mode 100644 index 00000000..f9e830b6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_Compiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT @p0 AS "a", @p1 AS "b", @p2 AS "c" +UNION ALL +SELECT @p3 AS "a", @p4 AS "b", @p5 AS "c") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..8b46a884 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_FirebirdCompiler.verified.sql @@ -0,0 +1,32 @@ +-------- ORIGINAL ----------- +WITH "Q" AS ( +SELECT 1 AS "A", 'k' AS "B", NULL AS "C" +FROM RDB$DATABASE +UNION ALL +SELECT 2 AS "A", NULL AS "B", 'j' AS "C" +FROM RDB$DATABASE) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "Q" AS ( +SELECT ? AS "A", ? AS "B", ? AS "C" +FROM RDB$DATABASE +UNION ALL +SELECT ? AS "A", ? AS "B", ? AS "C" +FROM RDB$DATABASE) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "Q" AS ( +SELECT @p0 AS "A", @p1 AS "B", @p2 AS "C" +FROM RDB$DATABASE +UNION ALL +SELECT @p3 AS "A", @p4 AS "B", @p5 AS "C" +FROM RDB$DATABASE) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..a77a5128 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_MySqlCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- +WITH `q` AS ( +SELECT 1 AS `a`, 'k' AS `b`, NULL AS `c` +UNION ALL +SELECT 2 AS `a`, NULL AS `b`, 'j' AS `c`) + +SELECT * +FROM `X` + +----------- RAW ------------- +WITH `q` AS ( +SELECT ? AS `a`, ? AS `b`, ? AS `c` +UNION ALL +SELECT ? AS `a`, ? AS `b`, ? AS `c`) + +SELECT * +FROM `X` + +--------PARAMETRIZED -------- +WITH `q` AS ( +SELECT @p0 AS `a`, @p1 AS `b`, @p2 AS `c` +UNION ALL +SELECT @p3 AS `a`, @p4 AS `b`, @p5 AS `c`) + +SELECT * +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f475fe0d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,32 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +FROM DUAL +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c" +FROM DUAL) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +FROM DUAL +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c" +FROM DUAL) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT :p0 AS "a", :p1 AS "b", :p2 AS "c" +FROM DUAL +UNION ALL +SELECT :p3 AS "a", :p4 AS "b", :p5 AS "c" +FROM DUAL) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..f475fe0d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_OracleCompiler.verified.sql @@ -0,0 +1,32 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +FROM DUAL +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c" +FROM DUAL) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +FROM DUAL +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c" +FROM DUAL) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT :p0 AS "a", :p1 AS "b", :p2 AS "c" +FROM DUAL +UNION ALL +SELECT :p3 AS "a", :p4 AS "b", :p5 AS "c" +FROM DUAL) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..f9e830b6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_PostgresCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT @p0 AS "a", @p1 AS "b", @p2 AS "c" +UNION ALL +SELECT @p3 AS "a", @p4 AS "b", @p5 AS "c") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..02945efd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,32 @@ +-------- ORIGINAL ----------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (1, 'k', NULL), +(2, NULL, 'j')) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (?, ?, ?), +(?, ?, ?)) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (@p0, @p1, @p2), +(@p3, @p4, @p5)) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..02945efd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqlServerCompiler.verified.sql @@ -0,0 +1,32 @@ +-------- ORIGINAL ----------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (1, 'k', NULL), +(2, NULL, 'j')) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (?, ?, ?), +(?, ?, ?)) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ( +SELECT [a], [b], [c] +FROM ( +VALUES (@p0, @p1, @p2), +(@p3, @p4, @p5)) +AS tbl ([a], [b], [c])) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..f9e830b6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.AdHocTableFromClause_SqliteCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT 1 AS "a", 'k' AS "b", NULL AS "c" +UNION ALL +SELECT 2 AS "a", NULL AS "b", 'j' AS "c") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT ? AS "a", ? AS "b", ? AS "c" +UNION ALL +SELECT ? AS "a", ? AS "b", ? AS "c") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT @p0 AS "a", @p1 AS "b", @p2 AS "c" +UNION ALL +SELECT @p3 AS "a", @p4 AS "b", @p5 AS "c") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..fdd74424 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "Q" AS ( +SELECT "A") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "Q" AS ( +SELECT "A") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "Q" AS ( +SELECT "A") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..6bd4b920 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH `q` AS ( +SELECT `a`) + +SELECT * +FROM `X` + +----------- RAW ------------- +WITH `q` AS ( +SELECT `a`) + +SELECT * +FROM `X` + +--------PARAMETRIZED -------- +WITH `q` AS ( +SELECT `a`) + +SELECT * +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..55ba5581 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..55ba5581 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ( +SELECT [a]) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..f4e8bb13 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.QueryFromClause_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ( +SELECT "a") + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4994f33c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" @p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler.verified.sql new file mode 100644 index 00000000..4994f33c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" @p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..ca24e233 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "Q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "Q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "Q" AS ("Y" @p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..3dff74d7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH `q` AS (`Y` 70) + +SELECT * +FROM `X` + +----------- RAW ------------- +WITH `q` AS (`Y` ?) + +SELECT * +FROM `X` + +--------PARAMETRIZED -------- +WITH `q` AS (`Y` @p0) + +SELECT * +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..fa1cf8da --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" :p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..fa1cf8da --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" :p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4994f33c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" @p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8262667a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH [q] AS ([Y] 70) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ([Y] ?) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ([Y] @p0) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..8262667a --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH [q] AS ([Y] 70) + +SELECT * +FROM [X] + +----------- RAW ------------- +WITH [q] AS ([Y] ?) + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- +WITH [q] AS ([Y] @p0) + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4994f33c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileCteQuery.RawFromClause_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- +WITH "q" AS ("Y" 70) + +SELECT * +FROM "X" + +----------- RAW ------------- +WITH "q" AS ("Y" ?) + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- +WITH "q" AS ("Y" @p0) + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_MySqlCompiler.verified.sql new file mode 100644 index 00000000..ca68ab64 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE `X` +FROM `X` +CROSS JOIN `Y` + +----------- RAW ------------- +DELETE `X` +FROM `X` +CROSS JOIN `Y` + +--------PARAMETRIZED -------- +DELETE `X` +FROM `X` +CROSS JOIN `Y` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_Compiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_FirebirdCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_MySqlCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_MySqlCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_OracleCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_PostgresCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_PostgresCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqlServerCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqliteCompiler.verified.sql new file mode 100644 index 00000000..817b87b3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_NoFrom_SqliteCompiler.verified.sql @@ -0,0 +1,7 @@ +-------- ORIGINAL ----------- + + +----------- RAW ------------- + + +--------PARAMETRIZED -------- diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_PostgresCompiler.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b20cab51 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] + +----------- RAW ------------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] + +--------PARAMETRIZED -------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..b20cab51 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] + +----------- RAW ------------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] + +--------PARAMETRIZED -------- +DELETE [X] +FROM [X] +CROSS JOIN [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqliteCompiler.verified.sql new file mode 100644 index 00000000..22eebd1d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.Join_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- +DELETE "X" +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_MySqlCompiler.verified.sql new file mode 100644 index 00000000..da9d89ce --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM `X` + +----------- RAW ------------- +DELETE +FROM `X` + +--------PARAMETRIZED -------- +DELETE +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_PostgresCompiler.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e074c194 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM [X] + +----------- RAW ------------- +DELETE +FROM [X] + +--------PARAMETRIZED -------- +DELETE +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..e074c194 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM [X] + +----------- RAW ------------- +DELETE +FROM [X] + +--------PARAMETRIZED -------- +DELETE +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqliteCompiler.verified.sql new file mode 100644 index 00000000..024103ea --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileDeleteQuery.No_Join_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" + +----------- RAW ------------- +DELETE +FROM "X" + +--------PARAMETRIZED -------- +DELETE +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..b2f14dfe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT * +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT * +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT * +FROM "Y" +WHERE "a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler.verified.sql new file mode 100644 index 00000000..38c11fb5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_Compiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..4b395dcd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_FirebirdCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "A" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "A" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "A" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_MySqlCompiler.verified.sql new file mode 100644 index 00000000..10fbc9eb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_MySqlCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE EXISTS ( +SELECT 1 +FROM `Y` +WHERE `a` = 4) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE EXISTS ( +SELECT 1 +FROM `Y` +WHERE `a` = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE EXISTS ( +SELECT 1 +FROM `Y` +WHERE `a` = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2eb4bd31 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler.verified.sql new file mode 100644 index 00000000..2eb4bd31 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_OracleCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_PostgresCompiler.verified.sql new file mode 100644 index 00000000..38c11fb5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_PostgresCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..601537a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = 4) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..601537a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqlServerCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = 4) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE EXISTS ( +SELECT 1 +FROM [Y] +WHERE [a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqliteCompiler.verified.sql new file mode 100644 index 00000000..38c11fb5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.Query_SqliteCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = 4) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE EXISTS ( +SELECT 1 +FROM "Y" +WHERE "a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..5c5703b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_MySqlCompiler.verified.sql new file mode 100644 index 00000000..4c9d01a6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT EXISTS ( +SELECT 1 +FROM `Y`) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT EXISTS ( +SELECT 1 +FROM `Y`) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT EXISTS ( +SELECT 1 +FROM `Y`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_PostgresCompiler.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5467913e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..5467913e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT EXISTS ( +SELECT 1 +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqliteCompiler.verified.sql new file mode 100644 index 00000000..ac8f69e5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileExistsCondition.SubQuery_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT EXISTS ( +SELECT 1 +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_MySqlCompiler.verified.sql new file mode 100644 index 00000000..bc8fb4eb --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` + +----------- RAW ------------- + +SELECT * +FROM `X` + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_PostgresCompiler.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b5b5c191 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] + +----------- RAW ------------- + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..b5b5c191 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] + +----------- RAW ------------- + +SELECT * +FROM [X] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqliteCompiler.verified.sql new file mode 100644 index 00000000..dc243b58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.All_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +----------- RAW ------------- + +SELECT * +FROM "X" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..692b6d40 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "A", "B", "C" +FROM "X" + +----------- RAW ------------- + +SELECT "A", "B", "C" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "A", "B", "C" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_MySqlCompiler.verified.sql new file mode 100644 index 00000000..d2401284 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT `a`, `b`, `c` +FROM `X` + +----------- RAW ------------- + +SELECT `a`, `b`, `c` +FROM `X` + +--------PARAMETRIZED -------- + +SELECT `a`, `b`, `c` +FROM `X` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_PostgresCompiler.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c571f187 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT [a], [b], [c] +FROM [X] + +----------- RAW ------------- + +SELECT [a], [b], [c] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT [a], [b], [c] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..c571f187 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT [a], [b], [c] +FROM [X] + +----------- RAW ------------- + +SELECT [a], [b], [c] +FROM [X] + +--------PARAMETRIZED -------- + +SELECT [a], [b], [c] +FROM [X] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqliteCompiler.verified.sql new file mode 100644 index 00000000..c97145af --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFlatColumns.Specific_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT "a", "b", "c" +FROM "X" + +----------- RAW ------------- + +SELECT "a", "b", "c" +FROM "X" + +--------PARAMETRIZED -------- + +SELECT "a", "b", "c" +FROM "X" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..bc9bd5e6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "A" + +----------- RAW ------------- + +SELECT "A" + +--------PARAMETRIZED -------- + +SELECT "A" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_MySqlCompiler.verified.sql new file mode 100644 index 00000000..acc9e175 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT `a` + +----------- RAW ------------- + +SELECT `a` + +--------PARAMETRIZED -------- + +SELECT `a` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_PostgresCompiler.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..44d6fd1c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT [a] + +----------- RAW ------------- + +SELECT [a] + +--------PARAMETRIZED -------- + +SELECT [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..44d6fd1c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT [a] + +----------- RAW ------------- + +SELECT [a] + +--------PARAMETRIZED -------- + +SELECT [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqliteCompiler.verified.sql new file mode 100644 index 00000000..26cedfdf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileFrom.NoFrom_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT "a" + +----------- RAW ------------- + +SELECT "a" + +--------PARAMETRIZED -------- + +SELECT "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..733b4b74 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "A" + +----------- RAW ------------- + +SELECT * GROUP BY "A" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "A" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_MySqlCompiler.verified.sql new file mode 100644 index 00000000..b912e45e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY `a` + +----------- RAW ------------- + +SELECT * GROUP BY `a` + +--------PARAMETRIZED -------- + +SELECT * GROUP BY `a` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_PostgresCompiler.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e57ee722 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY [a] + +----------- RAW ------------- + +SELECT * GROUP BY [a] + +--------PARAMETRIZED -------- + +SELECT * GROUP BY [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..e57ee722 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY [a] + +----------- RAW ------------- + +SELECT * GROUP BY [a] + +--------PARAMETRIZED -------- + +SELECT * GROUP BY [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqliteCompiler.verified.sql new file mode 100644 index 00000000..58db97a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileGroups.Trivial_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * GROUP BY "a" + +----------- RAW ------------- + +SELECT * GROUP BY "a" + +--------PARAMETRIZED -------- + +SELECT * GROUP BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..8218c06f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler.verified.sql new file mode 100644 index 00000000..8218c06f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..f93389c7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "A" = 1 + +----------- RAW ------------- + +SELECT * HAVING "A" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "A" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_MySqlCompiler.verified.sql new file mode 100644 index 00000000..772f59ac --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING `a` = 1 + +----------- RAW ------------- + +SELECT * HAVING `a` = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING `a` = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a3786a0c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler.verified.sql new file mode 100644 index 00000000..a3786a0c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_PostgresCompiler.verified.sql new file mode 100644 index 00000000..8218c06f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3912ddcf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING [a] = 1 + +----------- RAW ------------- + +SELECT * HAVING [a] = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..3912ddcf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING [a] = 1 + +----------- RAW ------------- + +SELECT * HAVING [a] = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqliteCompiler.verified.sql new file mode 100644 index 00000000..8218c06f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileHaving.Trivial_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * HAVING "a" = 1 + +----------- RAW ------------- + +SELECT * HAVING "a" = ? + +--------PARAMETRIZED -------- + +SELECT * HAVING "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..7d4996ac --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e53a57aa --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..e53a57aa --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..d9a12ad6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 1 /* NOT IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_MySqlCompiler.verified.sql new file mode 100644 index 00000000..763aa344 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_PostgresCompiler.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a60c649d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..a60c649d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqliteCompiler.verified.sql new file mode 100644 index 00000000..a4510684 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Empty_Straight_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE 1 = 0 /* IN [empty list] */ \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..e7633c91 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..e7633c91 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..c9c7b661 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..a593d304 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..07de32fa --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (:p0, :p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..07de32fa --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (:p0, :p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..e7633c91 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..aafc7d1b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..aafc7d1b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..e7633c91 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ('0', '99') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..fb17c0db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler.verified.sql new file mode 100644 index 00000000..fb17c0db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..79eac90e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_MySqlCompiler.verified.sql new file mode 100644 index 00000000..d1d06ffe --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..dcb9aaff --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (:p0, :p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler.verified.sql new file mode 100644 index 00000000..dcb9aaff --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (:p0, :p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_PostgresCompiler.verified.sql new file mode 100644 index 00000000..fb17c0db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f2f328a4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..f2f328a4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqliteCompiler.verified.sql new file mode 100644 index 00000000..fb17c0db --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInCondition.Straight_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ('aaa', 'zzz') + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN (?, ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN (@p0, @p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..b4dfb731 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..49a11ac0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` NOT IN ( +SELECT * +FROM `Y`) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` NOT IN ( +SELECT * +FROM `Y`) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` NOT IN ( +SELECT * +FROM `Y`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..0efc9e02 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..0efc9e02 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] NOT IN ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4e27102c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" NOT IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..5432b1de --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_MySqlCompiler.verified.sql new file mode 100644 index 00000000..79870aff --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` IN ( +SELECT * +FROM `Y`) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` IN ( +SELECT * +FROM `Y`) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` IN ( +SELECT * +FROM `Y`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_PostgresCompiler.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..d5896a42 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..d5896a42 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IN ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqliteCompiler.verified.sql new file mode 100644 index 00000000..31d11c23 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInQueryCondition.Straight_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IN ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..6f22ea57 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("A") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("A") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("A") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..9e6accd3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO `X` (`a`) +SELECT * +FROM `Y` + +----------- RAW ------------- +INSERT INTO `X` (`a`) +SELECT * +FROM `Y` + +--------PARAMETRIZED -------- +INSERT INTO `X` (`a`) +SELECT * +FROM `Y` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..1be59280 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] + +----------- RAW ------------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..1be59280 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] + +----------- RAW ------------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..07b9b082 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.InsertQueryClause_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +----------- RAW ------------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..3f9473e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler.verified.sql new file mode 100644 index 00000000..3f9473e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..a21d3a17 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("A") +SELECT 1 +FROM RDB$DATABASE +UNION ALL +SELECT 2 +FROM RDB$DATABASE + +----------- RAW ------------- +INSERT INTO "X" ("A") +SELECT ? +FROM RDB$DATABASE +UNION ALL +SELECT ? +FROM RDB$DATABASE + +--------PARAMETRIZED -------- +INSERT INTO "X" ("A") +SELECT @p0 +FROM RDB$DATABASE +UNION ALL +SELECT @p1 +FROM RDB$DATABASE \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_MySqlCompiler.verified.sql new file mode 100644 index 00000000..86363af2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO `X` (`a`) +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO `X` (`a`) +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO `X` (`a`) +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6f66e83c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +INSERT ALL INTO "X" ("a") +VALUES (1) INTO "X" ("a") +VALUES (2) +SELECT 1 +FROM DUAL + +----------- RAW ------------- +INSERT ALL INTO "X" ("a") +VALUES (?) INTO "X" ("a") +VALUES (?) +SELECT 1 +FROM DUAL + +--------PARAMETRIZED -------- +INSERT ALL INTO "X" ("a") +VALUES (:p0) INTO "X" ("a") +VALUES (:p1) +SELECT 1 +FROM DUAL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler.verified.sql new file mode 100644 index 00000000..6f66e83c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- +INSERT ALL INTO "X" ("a") +VALUES (1) INTO "X" ("a") +VALUES (2) +SELECT 1 +FROM DUAL + +----------- RAW ------------- +INSERT ALL INTO "X" ("a") +VALUES (?) INTO "X" ("a") +VALUES (?) +SELECT 1 +FROM DUAL + +--------PARAMETRIZED -------- +INSERT ALL INTO "X" ("a") +VALUES (:p0) INTO "X" ("a") +VALUES (:p1) +SELECT 1 +FROM DUAL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_PostgresCompiler.verified.sql new file mode 100644 index 00000000..3f9473e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..51cd4eaf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..51cd4eaf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqliteCompiler.verified.sql new file mode 100644 index 00000000..3f9473e0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.MultiValue_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1), +(2) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?), +(?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0), +(@p1) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..07263516 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler.verified.sql new file mode 100644 index 00000000..07263516 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..1a1860b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("A") +VALUES (3) + +----------- RAW ------------- +INSERT INTO "X" ("A") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("A") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_MySqlCompiler.verified.sql new file mode 100644 index 00000000..5cb6ad76 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO `X` (`a`) +VALUES (3); +SELECT last_insert_id() as Id + +----------- RAW ------------- +INSERT INTO `X` (`a`) +VALUES (?); +SELECT last_insert_id() as Id + +--------PARAMETRIZED -------- +INSERT INTO `X` (`a`) +VALUES (@p0); +SELECT last_insert_id() as Id \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a187f836 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (:p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler.verified.sql new file mode 100644 index 00000000..a187f836 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (:p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_PostgresCompiler.verified.sql new file mode 100644 index 00000000..ebcd330d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3); +SELECT lastval() AS id + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?); +SELECT lastval() AS id + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0); +SELECT lastval() AS id \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..add45dd3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (3); +SELECT scope_identity() as Id + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?); +SELECT scope_identity() as Id + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0); +SELECT scope_identity() as Id \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..add45dd3 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (3); +SELECT scope_identity() as Id + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?); +SELECT scope_identity() as Id + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0); +SELECT scope_identity() as Id \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqliteCompiler.verified.sql new file mode 100644 index 00000000..c11852b7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.ReturnId_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (3);select last_insert_rowid() as id + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?);select last_insert_rowid() as id + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0);select last_insert_rowid() as id \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4494e2b0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler.verified.sql new file mode 100644 index 00000000..4494e2b0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..1c131751 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("A") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("A") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("A") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_MySqlCompiler.verified.sql new file mode 100644 index 00000000..d69d274b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO `X` (`a`) +VALUES (1) + +----------- RAW ------------- +INSERT INTO `X` (`a`) +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO `X` (`a`) +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5c7260f7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (:p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler.verified.sql new file mode 100644 index 00000000..5c7260f7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (:p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4494e2b0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..344283ce --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (1) + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..344283ce --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO [X] ([a]) +VALUES (1) + +----------- RAW ------------- +INSERT INTO [X] ([a]) +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO [X] ([a]) +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4494e2b0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileInsertQuery.SingleValue_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +INSERT INTO "X" ("a") +VALUES (1) + +----------- RAW ------------- +INSERT INTO "X" ("a") +VALUES (?) + +--------PARAMETRIZED -------- +INSERT INTO "X" ("a") +VALUES (@p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..57594841 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("A" = "B") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("A" = "B") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("A" = "B") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_MySqlCompiler.verified.sql new file mode 100644 index 00000000..6b802a09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` + +INNER JOIN `Y` ON (`a` = `b`) + +----------- RAW ------------- + +SELECT * +FROM `X` + +INNER JOIN `Y` ON (`a` = `b`) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` + +INNER JOIN `Y` ON (`a` = `b`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_PostgresCompiler.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f2aba000 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) + +----------- RAW ------------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..f2aba000 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) + +----------- RAW ------------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] + +INNER JOIN [Y] ON ([a] = [b]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqliteCompiler.verified.sql new file mode 100644 index 00000000..a30ca20d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.With_Conditions_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +----------- RAW ------------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" + +INNER JOIN "Y" ON ("a" = "b") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_MySqlCompiler.verified.sql new file mode 100644 index 00000000..a014359b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +CROSS JOIN `Y` + +----------- RAW ------------- + +SELECT * +FROM `X` +CROSS JOIN `Y` + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +CROSS JOIN `Y` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_PostgresCompiler.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..958fc6d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +CROSS JOIN [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] +CROSS JOIN [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +CROSS JOIN [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..958fc6d1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +CROSS JOIN [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] +CROSS JOIN [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +CROSS JOIN [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqliteCompiler.verified.sql new file mode 100644 index 00000000..8e0a6662 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileJoin.Without_Conditions_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +CROSS JOIN "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +CROSS JOIN "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..577796fc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * LIMIT 1 OFFSET 7 + +----------- RAW ------------- + +SELECT * LIMIT ? OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * LIMIT @p0 OFFSET @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler.verified.sql new file mode 100644 index 00000000..577796fc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * LIMIT 1 OFFSET 7 + +----------- RAW ------------- + +SELECT * LIMIT ? OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * LIMIT @p0 OFFSET @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..d75d26ed --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ROWS 8 TO 8 + +----------- RAW ------------- + +SELECT * +ROWS ? TO ? + +--------PARAMETRIZED -------- + +SELECT * +ROWS @p0 TO @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_MySqlCompiler.verified.sql new file mode 100644 index 00000000..577796fc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * LIMIT 1 OFFSET 7 + +----------- RAW ------------- + +SELECT * LIMIT ? OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * LIMIT @p0 OFFSET @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5d946c63 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT *) "results_wrapper" +WHERE ROWNUM <= 8) +WHERE "row_num" > 7 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT *) "results_wrapper" +WHERE ROWNUM <= ?) +WHERE "row_num" > ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT "results_wrapper".*, ROWNUM "row_num" +FROM ( +SELECT *) "results_wrapper" +WHERE ROWNUM <= :p0) +WHERE "row_num" > :p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler.verified.sql new file mode 100644 index 00000000..47e89e49 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_OracleCompiler.verified.sql @@ -0,0 +1,26 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET 7 +ROWS FETCH NEXT 1 +ROWS ONLY + +----------- RAW ------------- + +SELECT * +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY ( +SELECT 0 +FROM DUAL) OFFSET :p0 +ROWS FETCH NEXT :p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_PostgresCompiler.verified.sql new file mode 100644 index 00000000..577796fc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * LIMIT 1 OFFSET 7 + +----------- RAW ------------- + +SELECT * LIMIT ? OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * LIMIT @p0 OFFSET @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..cc3f7f74 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,29 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num]) AS [results_wrapper] +WHERE [row_num] BETWEEN 8 +AND 8 + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num]) AS [results_wrapper] +WHERE [row_num] BETWEEN ? +AND ? + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT *, ROW_NUMBER() OVER ( +ORDER BY ( +SELECT 0)) AS [row_num]) AS [results_wrapper] +WHERE [row_num] BETWEEN @p0 +AND @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..5b1be951 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY ( +SELECT 0) OFFSET 7 +ROWS FETCH NEXT 1 +ROWS ONLY + +----------- RAW ------------- + +SELECT * +ORDER BY ( +SELECT 0) OFFSET ? +ROWS FETCH NEXT ? +ROWS ONLY + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY ( +SELECT 0) OFFSET @p0 +ROWS FETCH NEXT @p1 +ROWS ONLY \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqliteCompiler.verified.sql new file mode 100644 index 00000000..577796fc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileLimit.Limit_Offset_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- + +SELECT * LIMIT 1 OFFSET 7 + +----------- RAW ------------- + +SELECT * LIMIT ? OFFSET ? + +--------PARAMETRIZED -------- + +SELECT * LIMIT @p0 OFFSET @p1 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..3aa023c4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..3aa023c4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..575a3f00 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("A" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("A" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("A" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..687ab9a0 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT (`a` = 632) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT (`a` = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT (`a` = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..49fb9167 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..49fb9167 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..3aa023c4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b1cec729 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT ([a] = 632) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT ([a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT ([a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..b1cec729 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT ([a] = 632) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT ([a] = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT ([a] = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..3aa023c4 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNestedCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT ("a" = 632) + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT ("a" = ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT ("a" = @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..9cdd836d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..26c7fdd6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2a9da1d7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..2a9da1d7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..d5b5f353 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NOT NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..26560ba8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_MySqlCompiler.verified.sql new file mode 100644 index 00000000..b67576b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` IS NULL + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_PostgresCompiler.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..28f32466 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IS NULL + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..28f32466 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] IS NULL + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqliteCompiler.verified.sql new file mode 100644 index 00000000..5aaf5941 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileNullCondition.Straight_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" IS NULL + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" IS NULL \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..9ab88b29 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "A" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "A" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "A" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_MySqlCompiler.verified.sql new file mode 100644 index 00000000..a34e2790 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY `a` DESC + +----------- RAW ------------- + +SELECT * +ORDER BY `a` DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY `a` DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_PostgresCompiler.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5ff7e804 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [a] DESC + +----------- RAW ------------- + +SELECT * +ORDER BY [a] DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [a] DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..5ff7e804 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [a] DESC + +----------- RAW ------------- + +SELECT * +ORDER BY [a] DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [a] DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqliteCompiler.verified.sql new file mode 100644 index 00000000..601fdd05 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByDesc_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" DESC + +----------- RAW ------------- + +SELECT * +ORDER BY "a" DESC + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" DESC \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..2898aed5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler.verified.sql new file mode 100644 index 00000000..2898aed5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..2898aed5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_MySqlCompiler.verified.sql new file mode 100644 index 00000000..003492b8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY `X` 1 + +----------- RAW ------------- + +SELECT * +ORDER BY `X` ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY `X` @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6fb94e6f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler.verified.sql new file mode 100644 index 00000000..6fb94e6f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_PostgresCompiler.verified.sql new file mode 100644 index 00000000..2898aed5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..c161a5ab --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [X] 1 + +----------- RAW ------------- + +SELECT * +ORDER BY [X] ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [X] @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..c161a5ab --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [X] 1 + +----------- RAW ------------- + +SELECT * +ORDER BY [X] ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [X] @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqliteCompiler.verified.sql new file mode 100644 index 00000000..2898aed5 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderByRaw_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "X" 1 + +----------- RAW ------------- + +SELECT * +ORDER BY "X" ? + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..e2ed8852 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "A" + +----------- RAW ------------- + +SELECT * +ORDER BY "A" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "A" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_MySqlCompiler.verified.sql new file mode 100644 index 00000000..c7ad5351 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY `a` + +----------- RAW ------------- + +SELECT * +ORDER BY `a` + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY `a` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_PostgresCompiler.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..f9452d99 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [a] + +----------- RAW ------------- + +SELECT * +ORDER BY [a] + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..f9452d99 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY [a] + +----------- RAW ------------- + +SELECT * +ORDER BY [a] + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY [a] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqliteCompiler.verified.sql new file mode 100644 index 00000000..ee0b7d4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileOrders.OrderBy_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +ORDER BY "a" + +----------- RAW ------------- + +SELECT * +ORDER BY "a" + +--------PARAMETRIZED -------- + +SELECT * +ORDER BY "a" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..afdf106c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "A" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "A" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "A" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql new file mode 100644 index 00000000..1e2109bc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE `a` = ( +SELECT * +FROM `Y`) + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE `a` = ( +SELECT * +FROM `Y`) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE `a` = ( +SELECT * +FROM `Y`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..91c1a706 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..91c1a706 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE [a] = ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql new file mode 100644 index 00000000..a9961558 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE "a" = ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..cedf0f07 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler.verified.sql new file mode 100644 index 00000000..cedf0f07 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..0f5dc215 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS "MAX" +FROM ( +SELECT DISTINCT "A") AS "MAXQUERY" + +----------- RAW ------------- + +SELECT MAX(*) AS "MAX" +FROM ( +SELECT DISTINCT "A") AS "MAXQUERY" + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS "MAX" +FROM ( +SELECT DISTINCT "A") AS "MAXQUERY" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_MySqlCompiler.verified.sql new file mode 100644 index 00000000..3d24adcc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS `max` +FROM ( +SELECT DISTINCT `a`) AS `maxQuery` + +----------- RAW ------------- + +SELECT MAX(*) AS `max` +FROM ( +SELECT DISTINCT `a`) AS `maxQuery` + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS `max` +FROM ( +SELECT DISTINCT `a`) AS `maxQuery` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..169c9506 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler.verified.sql new file mode 100644 index 00000000..169c9506 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) "max" +FROM ( +SELECT DISTINCT "a") "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_PostgresCompiler.verified.sql new file mode 100644 index 00000000..cedf0f07 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..2fd697dd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] + +----------- RAW ------------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..2fd697dd --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] + +----------- RAW ------------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS [max] +FROM ( +SELECT DISTINCT [a]) AS [maxQuery] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqliteCompiler.verified.sql new file mode 100644 index 00000000..cedf0f07 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRaw.IsDistinct_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +----------- RAW ------------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" + +--------PARAMETRIZED -------- + +SELECT MAX(*) AS "max" +FROM ( +SELECT DISTINCT "a") AS "maxQuery" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..e30a3c09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler.verified.sql new file mode 100644 index 00000000..e30a3c09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..e30a3c09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_MySqlCompiler.verified.sql new file mode 100644 index 00000000..b5d06d58 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..5d052402 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah :p0 :p1 :p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler.verified.sql new file mode 100644 index 00000000..5d052402 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah :p0 :p1 :p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_PostgresCompiler.verified.sql new file mode 100644 index 00000000..e30a3c09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6cdfd17c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..6cdfd17c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqliteCompiler.verified.sql new file mode 100644 index 00000000..e30a3c09 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileRawCondition.AppendRaw_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE blah 1 2 3 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE blah ? ? ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE blah @p0 @p1 @p2 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..848549a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler.verified.sql new file mode 100644 index 00000000..848549a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..848549a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql new file mode 100644 index 00000000..9bc79afc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE ( +SELECT * +FROM `Y`) = 52 + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE ( +SELECT * +FROM `Y`) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE ( +SELECT * +FROM `Y`) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..de22e32d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql new file mode 100644 index 00000000..de22e32d --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql new file mode 100644 index 00000000..848549a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..b9e4044b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = 52 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..b9e4044b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = 52 + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE ( +SELECT * +FROM [Y]) = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql new file mode 100644 index 00000000..848549a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileSubQueryCondition.CompileSelectQuery_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = 52 + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = ? + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE ( +SELECT * +FROM "Y") = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4a7844e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler.verified.sql new file mode 100644 index 00000000..4a7844e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..4a7844e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..1c287fc8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER `a` 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER `a` ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER `a` @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..9ac78004 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..9ac78004 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4a7844e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3b1f01ba --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER [a] 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER [a] ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER [a] @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..3b1f01ba --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER [a] 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER [a] ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER [a] @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4a7844e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.RawFromClause_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +INNER "a" 5) + +----------- RAW ------------- + +SELECT * +FROM ( +INNER "a" ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +INNER "a" @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_MySqlCompiler.verified.sql new file mode 100644 index 00000000..ece82c96 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM `Y`) + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM `Y`) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM `Y`) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_PostgresCompiler.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..16af5dfc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..16af5dfc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM [Y]) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqliteCompiler.verified.sql new file mode 100644 index 00000000..fd1ca0cc --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTableExpression.SubQuery_No_Alias_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +----------- RAW ------------- + +SELECT * +FROM ( +SELECT * +FROM "Y") + +--------PARAMETRIZED -------- + +SELECT * +FROM ( +SELECT * +FROM "Y") \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_Compiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..314b2698 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_FirebirdCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "A" <> "B" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "A" <> "B" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "A" <> "B" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_MySqlCompiler.verified.sql new file mode 100644 index 00000000..505a33f1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_MySqlCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +WHERE NOT `a` <> `b` + +----------- RAW ------------- + +SELECT * +FROM `X` +WHERE NOT `a` <> `b` + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +WHERE NOT `a` <> `b` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_OracleCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_PostgresCompiler.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_PostgresCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..d5b9fd4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..d5b9fd4f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqlServerCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] + +----------- RAW ------------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +WHERE NOT [a] <> [b] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqliteCompiler.verified.sql new file mode 100644 index 00000000..224e7d8b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileTwoColumnsCondition.Not_SqliteCompiler.verified.sql @@ -0,0 +1,17 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +----------- RAW ------------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +WHERE NOT "a" <> "b" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_Compiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_FirebirdCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_MySqlCompiler.verified.sql new file mode 100644 index 00000000..f19c32b8 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_MySqlCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` EXCEPT ALL +SELECT * +FROM `Y` + +----------- RAW ------------- + +SELECT * +FROM `X` EXCEPT ALL +SELECT * +FROM `Y` + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` EXCEPT ALL +SELECT * +FROM `Y` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_OracleCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_PostgresCompiler.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_PostgresCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..64530b79 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..64530b79 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqlServerCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] EXCEPT ALL +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqliteCompiler.verified.sql new file mode 100644 index 00000000..3ef95350 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_All_SqliteCompiler.verified.sql @@ -0,0 +1,20 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" EXCEPT ALL +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Compiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_FirebirdCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_MySqlCompiler.verified.sql new file mode 100644 index 00000000..f6fc949f --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_MySqlCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` +UNION +SELECT * +FROM `Y` + +----------- RAW ------------- + +SELECT * +FROM `X` +UNION +SELECT * +FROM `Y` + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` +UNION +SELECT * +FROM `Y` \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_OracleCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_PostgresCompiler.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_PostgresCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..85cfc2e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler.verified.sql new file mode 100644 index 00000000..85cfc2e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_Compiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..85cfc2e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_FirebirdCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_MySqlCompiler.verified.sql new file mode 100644 index 00000000..7e81b4a9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_MySqlCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM `X` (Y 3) + +----------- RAW ------------- + +SELECT * +FROM `X` (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM `X` (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..e220345e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler.verified.sql new file mode 100644 index 00000000..e220345e --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_OracleCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y :p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_PostgresCompiler.verified.sql new file mode 100644 index 00000000..85cfc2e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_PostgresCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..39f6580b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] (Y 3) + +----------- RAW ------------- + +SELECT * +FROM [X] (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..39f6580b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqlServerCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] (Y 3) + +----------- RAW ------------- + +SELECT * +FROM [X] (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqliteCompiler.verified.sql new file mode 100644 index 00000000..85cfc2e2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_Raw_SqliteCompiler.verified.sql @@ -0,0 +1,14 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" (Y 3) + +----------- RAW ------------- + +SELECT * +FROM "X" (Y ?) + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" (Y @p0) \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..7c3e0fc9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..7c3e0fc9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqlServerCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] + +----------- RAW ------------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] + +--------PARAMETRIZED -------- + +SELECT * +FROM [X] +UNION +SELECT * +FROM [Y] \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqliteCompiler.verified.sql new file mode 100644 index 00000000..38a2550c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUnion.Combine_SqliteCompiler.verified.sql @@ -0,0 +1,23 @@ +-------- ORIGINAL ----------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +----------- RAW ------------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" + +--------PARAMETRIZED -------- + +SELECT * +FROM "X" +UNION +SELECT * +FROM "Y" \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..2fbf0229 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler.verified.sql new file mode 100644 index 00000000..2fbf0229 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_Compiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..78f01473 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_FirebirdCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "A" = "A" + 1 + +----------- RAW ------------- +UPDATE "X" SET "A" = "A" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "A" = "A" + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_MySqlCompiler.verified.sql new file mode 100644 index 00000000..358d9e0c --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_MySqlCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE `X` SET `a` = `a` + 1 + +----------- RAW ------------- +UPDATE `X` SET `a` = `a` + ? + +--------PARAMETRIZED -------- +UPDATE `X` SET `a` = `a` + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..1fd5d62b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler.verified.sql new file mode 100644 index 00000000..1fd5d62b --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_OracleCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_PostgresCompiler.verified.sql new file mode 100644 index 00000000..2fbf0229 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_PostgresCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..72d78643 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = [a] + 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = [a] + ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = [a] + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..72d78643 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqlServerCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = [a] + 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = [a] + ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = [a] + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqliteCompiler.verified.sql new file mode 100644 index 00000000..2fbf0229 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileIncrement_SqliteCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = "a" + 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = "a" + ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = "a" + @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_Compiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..4d71ee49 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_FirebirdCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "A" = 1 + +----------- RAW ------------- +UPDATE "X" SET "A" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "A" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_MySqlCompiler.verified.sql new file mode 100644 index 00000000..139a0ba7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_MySqlCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE `X` SET `a` = 1 + +----------- RAW ------------- +UPDATE `X` SET `a` = ? + +--------PARAMETRIZED -------- +UPDATE `X` SET `a` = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..bc7df8e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler.verified.sql new file mode 100644 index 00000000..bc7df8e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_OracleCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_PostgresCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..45dd6390 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..45dd6390 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqlServerCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.CompileUpdate_SqliteCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_Compiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..4d71ee49 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_FirebirdCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "A" = 1 + +----------- RAW ------------- +UPDATE "X" SET "A" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "A" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_MySqlCompiler.verified.sql new file mode 100644 index 00000000..139a0ba7 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_MySqlCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE `X` SET `a` = 1 + +----------- RAW ------------- +UPDATE `X` SET `a` = ? + +--------PARAMETRIZED -------- +UPDATE `X` SET `a` = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_OracleCompiler.verified.sql new file mode 100644 index 00000000..bc7df8e1 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_OracleCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_PostgresCompiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_PostgresCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..45dd6390 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..45dd6390 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqlServerCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE [X] SET [a] = 1 + +----------- RAW ------------- +UPDATE [X] SET [a] = ? + +--------PARAMETRIZED -------- +UPDATE [X] SET [a] = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqliteCompiler.verified.sql new file mode 100644 index 00000000..4061d352 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/CompileUpdateQuery.No_Join_SqliteCompiler.verified.sql @@ -0,0 +1,8 @@ +-------- ORIGINAL ----------- +UPDATE "X" SET "a" = 1 + +----------- RAW ------------- +UPDATE "X" SET "a" = ? + +--------PARAMETRIZED -------- +UPDATE "X" SET "a" = @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler with SelectInsideExists.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler with SelectInsideExists.verified.sql new file mode 100644 index 00000000..0e0e9da2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler with SelectInsideExists.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler.verified.sql new file mode 100644 index 00000000..0e0e9da2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_Compiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_FirebirdCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_FirebirdCompiler.verified.sql new file mode 100644 index 00000000..0e0e9da2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_FirebirdCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_MySqlCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_MySqlCompiler.verified.sql new file mode 100644 index 00000000..fb89a4b9 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_MySqlCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM `X` 1 + +----------- RAW ------------- +DELETE +FROM `X` ? + +--------PARAMETRIZED -------- +DELETE +FROM `X` @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..6cce7bb6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler.verified.sql new file mode 100644 index 00000000..6cce7bb6 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_OracleCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" :p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_PostgresCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_PostgresCompiler.verified.sql new file mode 100644 index 00000000..0e0e9da2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_PostgresCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql new file mode 100644 index 00000000..0d0ac4cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler with LegacyPagination.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM [X] 1 + +----------- RAW ------------- +DELETE +FROM [X] ? + +--------PARAMETRIZED -------- +DELETE +FROM [X] @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler.verified.sql new file mode 100644 index 00000000..0d0ac4cf --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqlServerCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM [X] 1 + +----------- RAW ------------- +DELETE +FROM [X] ? + +--------PARAMETRIZED -------- +DELETE +FROM [X] @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqliteCompiler.verified.sql b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqliteCompiler.verified.sql new file mode 100644 index 00000000..0e0e9da2 --- /dev/null +++ b/QueryBuilder.Tests/ApprovalTests/output/WriteTable.RawFromClause_SqliteCompiler.verified.sql @@ -0,0 +1,11 @@ +-------- ORIGINAL ----------- +DELETE +FROM "X" 1 + +----------- RAW ------------- +DELETE +FROM "X" ? + +--------PARAMETRIZED -------- +DELETE +FROM "X" @p0 \ No newline at end of file diff --git a/QueryBuilder.Tests/CoverageTests.cs b/QueryBuilder.Tests/CoverageTests.cs new file mode 100644 index 00000000..a757730e --- /dev/null +++ b/QueryBuilder.Tests/CoverageTests.cs @@ -0,0 +1,87 @@ +using FluentAssertions; +using SqlKata.Compilers; +using SqlKata.Tests.Infrastructure; + +namespace SqlKata.Tests +{ + public sealed class CoverageTests : TestSupport + { + [Fact] + public void CompileCte_With_RawFromClause() + { + var queryCTe = new Query("prodCTE") + .WithRaw("prodCTE", "SELECT * FROM B"); + + Compile(queryCTe)[EngineCodes.SqlServer].Should() + .Be("WITH [prodCTE] AS (SELECT * FROM B)\n" + + "SELECT * FROM [prodCTE]"); + } + [Fact] + public void From_QueryFromClause_With_Bindings() + { + var query = new Query("T") + .From(new Query("S").Where("c", 1)); + + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM " + + "(SELECT * FROM [S] WHERE [c] = 1)"); + } + [Fact] + public void Join_QueryFromClause_With_Bindings() + { + var query = new Query("L") + .Join(new Query("R").Where("c", 1), + join => join.On("a", "b")); + + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM [L] \n" + + "INNER JOIN " + + "(SELECT * FROM [R] WHERE [c] = 1) " + + "ON ([a] = [b])"); + } + [Fact] + public void InCondition() + { + var query = new Query("L").WhereIn("a", 1, 2); + + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM [L] WHERE [a] IN (1, 2)"); + } + [Fact] + public void InCondition_When_Empty_Bindings() + { + var query = new Query("L").WhereIn("a"); + + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM [L] WHERE 1 = 0 /* IN [empty list] */"); + } + [Fact] + public void InCondition_When_Not() + { + var query = new Query("L").WhereNotIn("a", "blah"); + + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM [L] WHERE [a] NOT IN ('blah')"); + } + + [Fact] + public void WhereDate_When_Unknown_DatePart() + { + var query = new Query("Orders") + .Define("@d", 1996) + .WhereDatePart("blah", "RequiredDate", "=", Expressions.Variable("@d")); + Compile(query)[EngineCodes.SqlServer].Should() + .Be("SELECT * FROM [Orders] WHERE DATEPART(BLAH, [RequiredDate]) = 1996"); + } + + [Fact] + public void Compile_Multiple() + { + new SqlServerCompiler().Compile(new[]{ + new Query("A"), new Query("B")}) + .ToString().Should().Be( + "SELECT * FROM [A];\n" + + "SELECT * FROM [B]"); + } + } +} diff --git a/QueryBuilder.Tests/DefineTest.cs b/QueryBuilder.Tests/DefineTest.cs index 0b5ff292..764b3aae 100644 --- a/QueryBuilder.Tests/DefineTest.cs +++ b/QueryBuilder.Tests/DefineTest.cs @@ -1,427 +1,433 @@ -using static SqlKata.Expressions; using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; +using static SqlKata.Expressions; + +namespace SqlKata.Tests; -namespace SqlKata.Tests +/// +/// If you want to test this queries against a database use NorthWind database +/// +public class DefineTest : TestSupport { - /// - /// If you want to test this queries against a database use NorthWind database - /// - public class DefineTest : TestSupport + [Fact] + public void Test_Define_Where() { + var query = new Query("Products") + .Define("@name", "Anto") + .Where("ProductName", Variable("@name")); - [Fact] - public void Test_Define_Where() - { - var query = new Query("Products") - .Define("@name", "Anto") - .Where("ProductName", Variable("@name")); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [Products] WHERE [ProductName] = 'Anto'", c[EngineCodes.SqlServer]); - - } - - [Fact] - public void Test_Define_SubQuery() - { - - var subquery = new Query("Products") - .AsAverage("unitprice") - .Define("@UnitsInSt", 10) - .Where("UnitsInStock", ">", Variable("@UnitsInSt")); - - var query = new Query("Products") - .Where("unitprice", ">", subquery) - .Where("UnitsOnOrder", ">", 5); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [Products] WHERE [unitprice] > (SELECT AVG([unitprice]) AS [avg] FROM [Products] WHERE [UnitsInStock] > 10) AND [UnitsOnOrder] > 5", c[EngineCodes.SqlServer]); - - } - - - [Fact] - public void Test_Define_WhereEnds() - { - - var query1 = new Query("Products") - .Select("ProductId") - .Define("@product", "Coffee") - .WhereEnds("ProductName", Variable("@product")); - - - var query2 = new Query("Products") - .Select("ProductId", "ProductName") - .Define("@product", "Coffee") - .WhereEnds("ProductName", Variable("@product"), true); - - var c1 = Compile(query1); - var c2 = Compile(query2); - - Assert.Equal("SELECT [ProductId] FROM [Products] WHERE LOWER([ProductName]) like '%coffee'", c1[EngineCodes.SqlServer]); - - Assert.Equal("SELECT [ProductId], [ProductName] FROM [Products] WHERE [ProductName] like '%Coffee'", c2[EngineCodes.SqlServer]); - - } - - - - [Fact] - public void Test_Define_WhereStarts() - { - - - var query1 = new Query("Products") - .Select("ProductId", "QuantityPerUnit") - .Define("@perUnit", "12") - .WhereStarts("QuantityPerUnit", Variable("@perUnit")); - - - var query2 = new Query("Products") - .Select("ProductId", "QuantityPerUnit") - .Define("@perUnit", "12") - .WhereStarts("QuantityPerUnit", Variable("@perUnit"), true); - - var c1 = Compile(query1); - var c2 = Compile(query2); - - Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE LOWER([QuantityPerUnit]) like '12%'", c1[EngineCodes.SqlServer]); - Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE [QuantityPerUnit] like '12%'", c2[EngineCodes.SqlServer]); - } + var c = Compile(query); + Assert.Equal("SELECT * FROM [Products] WHERE [ProductName] = 'Anto'", c[EngineCodes.SqlServer]); + } - [Fact] - public void Test_Define_WhereContains() - { + [Fact] + public void Test_Define_SubQuery() + { + var subQuery = new Query("Products") + .AsAverage("unitprice") + .Define("@UnitsInSt", 10) + .Where("UnitsInStock", ">", Variable("@UnitsInSt")); - var query1 = new Query("Products") - .Define("@perUnit", "500") - .Select("ProductId", "QuantityPerUnit") - .WhereContains("QuantityPerUnit", Variable("@perUnit")); + var query = new Query("Products") + .Where("unitprice", ">", subQuery) + .Where("UnitsOnOrder", ">", 5); + var c = Compile(query); - var query2 = new Query("Products") - .Define("@perUnit", "500") - .Select("ProductId", "QuantityPerUnit") - .WhereContains("QuantityPerUnit", Variable("@perUnit"), true); + Assert.Equal( + "SELECT * FROM [Products] WHERE [unitprice] > (SELECT AVG([unitprice]) AS [avg] FROM [Products] WHERE [UnitsInStock] > 10) AND [UnitsOnOrder] > 5", + c[EngineCodes.SqlServer]); + } - var c1 = Compile(query1); - var c2 = Compile(query2); - Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE LOWER([QuantityPerUnit]) like '%500%'", c1[EngineCodes.SqlServer]); - Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE [QuantityPerUnit] like '%500%'", c2[EngineCodes.SqlServer]); + [Fact] + public void Test_Define_WhereEnds() + { + var query1 = new Query("Products") + .Select("ProductId") + .Define("@product", "Coffee") + .WhereEnds("ProductName", Variable("@product")); - } + var query2 = new Query("Products") + .Select("ProductId", "ProductName") + .Define("@product", "Coffee") + .WhereEnds("ProductName", Variable("@product"), true); - [Fact] - public void Test_Define_WhereLike() - { - var query1 = new Query("Products") - .Select("ProductId", "ProductName", "SupplierID") - .Define("@id", "20") - .WhereLike("SupplierID", Variable("@id")); + var c1 = Compile(query1); + var c2 = Compile(query2); + Assert.Equal("SELECT [ProductId] FROM [Products] WHERE LOWER([ProductName]) like '%coffee'", + c1[EngineCodes.SqlServer]); - var query2 = new Query("Products") - .Select("ProductId", "ProductName", "SupplierID") - .Define("@id", "20") - .WhereLike("SupplierID", Variable("@id"), true); + Assert.Equal("SELECT [ProductId], [ProductName] FROM [Products] WHERE [ProductName] like '%Coffee'", + c2[EngineCodes.SqlServer]); + } - var c1 = Compile(query1); - var c2 = Compile(query2); - Assert.Equal("SELECT [ProductId], [ProductName], [SupplierID] FROM [Products] WHERE LOWER([SupplierID]) like '20'", c1[EngineCodes.SqlServer]); + [Fact] + public void Test_Define_WhereStarts() + { + var query1 = new Query("Products") + .Select("ProductId", "QuantityPerUnit") + .Define("@perUnit", "12") + .WhereStarts("QuantityPerUnit", Variable("@perUnit")); - Assert.Equal("SELECT [ProductId], [ProductName], [SupplierID] FROM [Products] WHERE [SupplierID] like '20'", c2[EngineCodes.SqlServer]); - } + var query2 = new Query("Products") + .Select("ProductId", "QuantityPerUnit") + .Define("@perUnit", "12") + .WhereStarts("QuantityPerUnit", Variable("@perUnit"), true); - [Fact] - public void Test_Define_WhereInSubquery() - { + var c1 = Compile(query1); + var c2 = Compile(query2); - var subquery = new Query("Orders") - .Define("@shipId", 3) - .Select("ShipVia").Where("ShipVia", Variable("@shipId")); + Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE LOWER([QuantityPerUnit]) like '12%'", + c1[EngineCodes.SqlServer]); + Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE [QuantityPerUnit] like '12%'", + c2[EngineCodes.SqlServer]); + } - var query1 = new Query("Shippers") - .Select("ShipperID", "CompanyName") - .WhereIn("ShipperID", subquery); + [Fact] + public void Test_Define_WhereContains() + { + var query1 = new Query("Products") + .Define("@perUnit", "500") + .Select("ProductId", "QuantityPerUnit") + .WhereContains("QuantityPerUnit", Variable("@perUnit")); - var c1 = Compile(query1); + var query2 = new Query("Products") + .Define("@perUnit", "500") + .Select("ProductId", "QuantityPerUnit") + .WhereContains("QuantityPerUnit", Variable("@perUnit"), true); - Assert.Equal("SELECT [ShipperID], [CompanyName] FROM [Shippers] WHERE [ShipperID] IN (SELECT [ShipVia] FROM [Orders] WHERE [ShipVia] = 3)", c1[EngineCodes.SqlServer]); - } + var c1 = Compile(query1); + var c2 = Compile(query2); - [Fact] - public void Test_Define_Having() - { - var c = Compile(new Query("Table") - .Define("@foo", 1) - .Having("Id", "=", Variable("@foo"))); + Assert.Equal( + "SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE LOWER([QuantityPerUnit]) like '%500%'", + c1[EngineCodes.SqlServer]); + Assert.Equal("SELECT [ProductId], [QuantityPerUnit] FROM [Products] WHERE [QuantityPerUnit] like '%500%'", + c2[EngineCodes.SqlServer]); + } - Assert.Equal("SELECT * FROM [Table] HAVING [Id] = 1", c[EngineCodes.SqlServer]); - } - /* - [Fact] - public void Test_Define_HavingRaw() - { - var query1 = new Query("Orders") - .Define("@count", 80) - .Select("Employees.LastName") - .SelectRaw("COUNT(Orders.OrderID) AS NumberOfOrders") - .Join("Employees", "Employees.EmployeeID", "Orders.EmployeeID") - .GroupBy("LastName") - .HavingRaw("COUNT(Orders.OrderID) > @count"); + [Fact] + public void Test_Define_WhereLike() + { + var query1 = new Query("Products") + .Select("ProductId", "ProductName", "SupplierID") + .Define("@id", "20") + .WhereLike("SupplierID", Variable("@id")); - var c = Compile(query1); - Assert.Equal("SELECT [Employees].[LastName], COUNT(Orders.OrderID) AS NumberOfOrders FROM [Orders] \nINNER JOIN [Employees] ON [Employees].[EmployeeID] = [Orders].[EmployeeID] GROUP BY [LastName] HAVING COUNT(Orders.OrderID) > 80", c[EngineCodes.SqlServer]); + var query2 = new Query("Products") + .Select("ProductId", "ProductName", "SupplierID") + .Define("@id", "20") + .WhereLike("SupplierID", Variable("@id"), true); - } - */ + var c1 = Compile(query1); + var c2 = Compile(query2); - [Fact] - public void Test_Define_HavingStarts() - { + Assert.Equal( + "SELECT [ProductId], [ProductName], [SupplierID] FROM [Products] WHERE LOWER([SupplierID]) like '20'", + c1[EngineCodes.SqlServer]); - var query = new Query("Customers") - .Define("@label", "U") - .SelectRaw("COUNT(CustomerID)") - .Select("Country") - .GroupBy("Country") - .HavingStarts("Country", Variable("@label")); + Assert.Equal("SELECT [ProductId], [ProductName], [SupplierID] FROM [Products] WHERE [SupplierID] like '20'", + c2[EngineCodes.SqlServer]); + } - var c = Compile(query); - Assert.Equal("SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like 'u%'", c[EngineCodes.SqlServer]); + [Fact] + public void Test_Define_WhereInSubQuery() + { + var subQuery = new Query("Orders") + .Define("@shipId", 3) + .Select("ShipVia").Where("ShipVia", Variable("@shipId")); - } + var query1 = new Query("Shippers") + .Select("ShipperID", "CompanyName") + .WhereIn("ShipperID", subQuery); - [Fact] - public void Test_Define_Having_Ends() - { - var query = new Query("Customers") - .Define("@label", "d") - .SelectRaw("COUNT(CustomerID)") - .Select("Country") - .GroupBy("Country") - .HavingEnds("Country", Variable("@label")); + var c1 = Compile(query1); - var c = Compile(query); + Assert.Equal( + "SELECT [ShipperID], [CompanyName] FROM [Shippers] WHERE [ShipperID] IN (SELECT [ShipVia] FROM [Orders] WHERE [ShipVia] = 3)", + c1[EngineCodes.SqlServer]); + } - Assert.Equal("SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like '%d'", c[EngineCodes.SqlServer]); - } + [Fact] + public void Test_Define_Having() + { + var c = Compile(new Query("Table") + .Define("@foo", 1) + .Having("Id", "=", Variable("@foo"))); + Assert.Equal("SELECT * FROM [Table] HAVING [Id] = 1", c[EngineCodes.SqlServer]); + } - [Fact] - public void Test_Define_Having_Contains() - { + /* + [Fact] + public void Test_Define_HavingRaw() + { + var query1 = new Query("Orders") + .Define("@count", 80) + .Select("Employees.LastName") + .SelectRaw("COUNT(Orders.OrderID) AS NumberOfOrders") + .Join("Employees", "Employees.EmployeeID", "Orders.EmployeeID") + .GroupBy("LastName") + .HavingRaw("COUNT(Orders.OrderID) > @count"); + var c = Compile(query1); - var query = new Query("Customers") - .Define("@label", "d") - .SelectRaw("COUNT(CustomerID)") - .Select("Country") - .GroupBy("Country") - .HavingContains("Country", Variable("@label")); + Assert.Equal("SELECT [Employees].[LastName], COUNT(Orders.OrderID) AS NumberOfOrders FROM [Orders] \nINNER JOIN [Employees] ON [Employees].[EmployeeID] = [Orders].[EmployeeID] GROUP BY [LastName] HAVING COUNT(Orders.OrderID) > 80", c[EngineCodes.SqlServer]); - var c = Compile(query); + } + */ - Assert.Equal("SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like '%d%'", c[EngineCodes.SqlServer]); + [Fact] + public void Test_Define_HavingStarts() + { + var query = new Query("Customers") + .Define("@label", "U") + .SelectRaw("COUNT(CustomerID)") + .Select("Country") + .GroupBy("Country") + .HavingStarts("Country", Variable("@label")); + + var c = Compile(query); + + Assert.Equal( + "SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like 'u%'", + c[EngineCodes.SqlServer]); + } - } + [Fact] + public void Test_Define_Having_Ends() + { + var query = new Query("Customers") + .Define("@label", "d") + .SelectRaw("COUNT(CustomerID)") + .Select("Country") + .GroupBy("Country") + .HavingEnds("Country", Variable("@label")); + + var c = Compile(query); + + Assert.Equal( + "SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like '%d'", + c[EngineCodes.SqlServer]); + } - [Fact] - public void Test_Define_NestedCondition() - { - var query = new Query("Orders") - .Define("@shipReg", null) - .Define("@one", 1) - .Where(q => - q.Where("ShipRegion", "!=", Variable("@shipReg")) - // .WhereRaw("1 = @one") - ).AsCount(); - var c = Compile(query); + [Fact] + public void Test_Define_Having_Contains() + { + var query = new Query("Customers") + .Define("@label", "d") + .SelectRaw("COUNT(CustomerID)") + .Select("Country") + .GroupBy("Country") + .HavingContains("Country", Variable("@label")); + + var c = Compile(query); + + Assert.Equal( + "SELECT COUNT(CustomerID), [Country] FROM [Customers] GROUP BY [Country] HAVING LOWER([Country]) like '%d%'", + c[EngineCodes.SqlServer]); + } - Assert.Equal("SELECT COUNT(*) AS [count] FROM [Orders] WHERE ([ShipRegion] != NULL)", c[EngineCodes.SqlServer]); - } + [Fact] + public void Test_Define_NestedCondition() + { + var query = new Query("Orders") + .Define("@shipReg", null) + .Define("@one", 1) + .Where(q => + q.Where("ShipRegion", "!=", Variable("@shipReg")) + ).AsCount(); + var c = Compile(query); - [Fact] - public void Test_Define_WhereDate() - { - var dateObj = new System.DateTime(year: 1996, month: 8, day: 1); + Assert.Equal("SELECT COUNT(*) AS [count] FROM [Orders] WHERE ([ShipRegion] != NULL)", c[EngineCodes.SqlServer]); + } - var query = new Query("Orders") - .Define("@d", dateObj) - .WhereDate("RequiredDate", Variable("@d")); + [Fact] + public void Test_Define_WhereDate() + { + var dateObj = new DateTime(1996, 8, 1); - var query2 = new Query("Orders") - .Define("@d", 1996) - .WhereDatePart("year", "RequiredDate", "=", Variable("@d")); + var query = new Query("Orders") + .Define("@d", dateObj) + .WhereDate("RequiredDate", Variable("@d")); - var query3 = new Query("Orders") - .Define("@d", "00:00:00") - .WhereTime("RequiredDate", "!=", Variable("@d")); - var c = Compile(query); - var c2 = Compile(query2); - var c3 = Compile(query3); + var query2 = new Query("Orders") + .Define("@d", 1996) + .WhereDatePart("year", "RequiredDate", "=", Variable("@d")); - Assert.Equal("SELECT * FROM [Orders] WHERE CAST([RequiredDate] AS DATE) = '1996-08-01'", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM \"Orders\" WHERE \"RequiredDate\"::date = '1996-08-01'", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM \"Orders\" WHERE strftime('%Y-%m-%d', \"RequiredDate\") = cast('1996-08-01' as text)", c[EngineCodes.Sqlite]); - Assert.Equal("SELECT * FROM \"ORDERS\" WHERE CAST(\"REQUIREDDATE\" as DATE) = '1996-08-01'", c[EngineCodes.Firebird]); + var query3 = new Query("Orders") + .Define("@d", "00:00:00") + .WhereTime("RequiredDate", "!=", Variable("@d")); + var c = Compile(query); + var c2 = Compile(query2); + var c3 = Compile(query3); + Assert.Equal("SELECT * FROM [Orders] WHERE CAST([RequiredDate] AS DATE) = '1996-08-01'", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM \"Orders\" WHERE \"RequiredDate\"::date = '1996-08-01'", c[EngineCodes.PostgreSql]); + Assert.Equal( + "SELECT * FROM \"Orders\" WHERE strftime('%Y-%m-%d', \"RequiredDate\") = cast('1996-08-01' as text)", + c[EngineCodes.Sqlite]); + Assert.Equal("SELECT * FROM \"ORDERS\" WHERE CAST(\"REQUIREDDATE\" as DATE) = '1996-08-01'", + c[EngineCodes.Firebird]); - Assert.Equal("SELECT * FROM [Orders] WHERE DATEPART(YEAR, [RequiredDate]) = 1996", c2[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM [Orders] WHERE CAST([RequiredDate] AS TIME) != '00:00:00'", c3[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT * FROM [Orders] WHERE DATEPART(YEAR, [RequiredDate]) = 1996", c2[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM [Orders] WHERE CAST([RequiredDate] AS TIME) != '00:00:00'", + c3[EngineCodes.SqlServer]); + } - [Fact] - public void Test_Define_WhereExists() - { - var query = new Query("Customers") - .WhereExists(q => q.From("Orders") + [Fact] + public void Test_Define_WhereExists() + { + var query = new Query("Customers") + .WhereExists(q => q.From("Orders") .Define("@postal", "8200") .Where("ShipPostalCode", Variable("@postal")) ); - var c = Compile(query); - Assert.Equal("SELECT * FROM [Customers] WHERE EXISTS (SELECT 1 FROM [Orders] WHERE [ShipPostalCode] = '8200')", c[EngineCodes.SqlServer]); - } - - - - [Fact] - public void Test_Define_With() - { - - var query = new Query("Products") - .Define("@unit", 10) - .Join("Categories", "Categories.CategoryID", "Products.CategoryID") - .Select("Categories.CategoryName", "Products.UnitPrice") - .Where("Products.UnitPrice", ">", Variable("@unit")); - - var queryCTe = new Query("prodCTE") - .With("prodCTE", query); - - var c = Compile(queryCTe); - - - Assert.Equal("WITH [prodCTE] AS (SELECT [Categories].[CategoryName], [Products].[UnitPrice] FROM [Products] \nINNER JOIN [Categories] ON [Categories].[CategoryID] = [Products].[CategoryID] WHERE [Products].[UnitPrice] > 10)\nSELECT * FROM [prodCTE]", c[EngineCodes.SqlServer]); - } + var c = Compile(query); + Assert.Equal("SELECT * FROM [Customers] WHERE EXISTS (SELECT 1 FROM [Orders] WHERE [ShipPostalCode] = '8200')", + c[EngineCodes.SqlServer]); + } + [Fact] + public void Test_Define_With() + { + var query = new Query("Products") + .Define("@unit", 10) + .Join("Categories", "Categories.CategoryID", "Products.CategoryID") + .Select("Categories.CategoryName", "Products.UnitPrice") + .Where("Products.UnitPrice", ">", Variable("@unit")); - /* - [Fact] - public void Test_Define_WithRaw() - { + var queryCTe = new Query("prodCTE") + .With("prodCTE", query); - //WithRaw - var query = new Query("prodCTE") - .Define("@unit", 10) - .Define("@foo", 2) - .Select("CategoryName", "UnitPrice") - .WithRaw("prodCTE", "SELECT c.CategoryName, p.UnitPrice FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID WHERE p.UnitPrice > @unit AND 2 = @foo"); + var c = Compile(queryCTe); - var c = Compile(query); - Assert.Equal("WITH [prodCTE] AS (SELECT c.CategoryName, p.UnitPrice FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID WHERE p.UnitPrice > 10 AND 2 = 2)\nSELECT [CategoryName], [UnitPrice] FROM [prodCTE]", c[EngineCodes.SqlServer]); + Assert.Equal( + "WITH [prodCTE] AS (SELECT [Categories].[CategoryName], [Products].[UnitPrice] FROM [Products] \nINNER JOIN [Categories] ON [Categories].[CategoryID] = [Products].[CategoryID] WHERE [Products].[UnitPrice] > 10)\nSELECT * FROM [prodCTE]", + c[EngineCodes.SqlServer]); + } - } - */ - // - [Fact] - public void Test_Define_Union() - { - var q1 = new Query("Suppliers") - .Define("@foo", "Beirut") - .Select("City") - .Where("City", Variable("@foo")); + /* + [Fact] + public void Test_Define_WithRaw() + { - var q2 = new Query("Customers") - .Define("@city", "Z") - .Select("City") - .Union(q1) - .WhereNotLike("City", Variable("@city")); + //WithRaw + var query = new Query("prodCTE") + .Define("@unit", 10) + .Define("@foo", 2) + .Select("CategoryName", "UnitPrice") + .WithRaw("prodCTE", "SELECT c.CategoryName, p.UnitPrice FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID WHERE p.UnitPrice > @unit AND 2 = @foo"); - var c = Compile(q2); - Assert.Equal("SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') UNION SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", c[EngineCodes.SqlServer]); - } + var c = Compile(query); + Assert.Equal("WITH [prodCTE] AS (SELECT c.CategoryName, p.UnitPrice FROM Products p INNER JOIN Categories c ON c.CategoryID = p.CategoryID WHERE p.UnitPrice > 10 AND 2 = 2)\nSELECT [CategoryName], [UnitPrice] FROM [prodCTE]", c[EngineCodes.SqlServer]); - [Fact] - public void Test_Define_Except() - { - var q1 = new Query("Suppliers") - .Define("@foo", "Beirut") - .Select("City") - .Where("City", Variable("@foo")); + } + */ - var q2 = new Query("Customers") - .Define("@city", "Z") - .Select("City") - .Except(q1) - .WhereNotLike("City", Variable("@city")); + // + [Fact] + public void Test_Define_Union() + { + var q1 = new Query("Suppliers") + .Define("@foo", "Beirut") + .Select("City") + .Where("City", Variable("@foo")); + + var q2 = new Query("Customers") + .Define("@city", "Z") + .Select("City") + .Union(q1) + .WhereNotLike("City", Variable("@city")); + + var c = Compile(q2); + Assert.Equal( + "SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') UNION SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", + c[EngineCodes.SqlServer]); + } - var c = Compile(q2); - Assert.Equal("SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') EXCEPT SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", c[EngineCodes.SqlServer]); - } - [Fact] - public void Test_Define_Intersect() - { - var q1 = new Query("Suppliers") - .Define("@foo", "Beirut") - .Select("City") - .Where("City", Variable("@foo")); + [Fact] + public void Test_Define_Except() + { + var q1 = new Query("Suppliers") + .Define("@foo", "Beirut") + .Select("City") + .Where("City", Variable("@foo")); + + var q2 = new Query("Customers") + .Define("@city", "Z") + .Select("City") + .Except(q1) + .WhereNotLike("City", Variable("@city")); + + var c = Compile(q2); + Assert.Equal( + "SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') EXCEPT SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", + c[EngineCodes.SqlServer]); + } - var q2 = new Query("Customers") - .Define("@city", "Z") - .Select("City") - .Intersect(q1) - .WhereNotLike("City", Variable("@city")); + [Fact] + public void Test_Define_Intersect() + { + var q1 = new Query("Suppliers") + .Define("@foo", "Beirut") + .Select("City") + .Where("City", Variable("@foo")); + + var q2 = new Query("Customers") + .Define("@city", "Z") + .Select("City") + .Intersect(q1) + .WhereNotLike("City", Variable("@city")); + + var c = Compile(q2); + Assert.Equal( + "SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') INTERSECT SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", + c[EngineCodes.SqlServer]); + } - var c = Compile(q2); - Assert.Equal("SELECT [City] FROM [Customers] WHERE NOT (LOWER([City]) like 'z') INTERSECT SELECT [City] FROM [Suppliers] WHERE [City] = 'Beirut'", c[EngineCodes.SqlServer]); - } + /* + [Fact] + public void Test_Define_CombineRaw() + { - /* - [Fact] - public void Test_Define_CombineRaw() - { - - var query = new Query("Customers") - .Define("@foo", 1) - .Define("@faa", 2) - .Select("City") - .CombineRaw("UNION ALL SELECT City FROM Suppliers WHERE 1 = @foo AND 2 = @faa"); - - var c = Compile(query); - Assert.Equal("SELECT [City] FROM [Customers] UNION ALL SELECT City FROM Suppliers WHERE 1 = 1 AND 2 = 2", c[EngineCodes.SqlServer]); - } - */ + var query = new Query("Customers") + .Define("@foo", 1) + .Define("@faa", 2) + .Select("City") + .CombineRaw("UNION ALL SELECT City FROM Suppliers WHERE 1 = @foo AND 2 = @faa"); + var c = Compile(query); + Assert.Equal("SELECT [City] FROM [Customers] UNION ALL SELECT City FROM Suppliers WHERE 1 = 1 AND 2 = 2", c[EngineCodes.SqlServer]); } + */ } diff --git a/QueryBuilder.Tests/DeleteTests.cs b/QueryBuilder.Tests/DeleteTests.cs index 14fd4043..bfdaac25 100644 --- a/QueryBuilder.Tests/DeleteTests.cs +++ b/QueryBuilder.Tests/DeleteTests.cs @@ -1,49 +1,52 @@ using SqlKata.Compilers; -using SqlKata.Extensions; using SqlKata.Tests.Infrastructure; -using System; -using System.Linq; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class DeleteTests : TestSupport { - public class DeleteTests : TestSupport + [Fact] + public void BasicDelete() + { + var q = new Query("Posts").AsDelete(); + + var c = Compile(q); + + Assert.Equal("DELETE FROM [Posts]", c[EngineCodes.SqlServer]); + } + + [Fact] + public void DeleteWithJoin() { - [Fact] - public void BasicDelete() - { - var q = new Query("Posts").AsDelete(); - - var c = Compile(q); - - Assert.Equal("DELETE FROM [Posts]", c[EngineCodes.SqlServer]); - } - - [Fact] - public void DeleteWithJoin() - { - var q = new Query("Posts") - .Join("Authors", "Authors.Id", "Posts.AuthorId") - .Where("Authors.Id", 5) - .AsDelete(); - - var c = Compile(q); - - Assert.Equal("DELETE [Posts] FROM [Posts] \nINNER JOIN [Authors] ON [Authors].[Id] = [Posts].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]); - Assert.Equal("DELETE `Posts` FROM `Posts` \nINNER JOIN `Authors` ON `Authors`.`Id` = `Posts`.`AuthorId` WHERE `Authors`.`Id` = 5", c[EngineCodes.MySql]); - } - - [Fact] - public void DeleteWithJoinAndAlias() - { - var q = new Query("Posts as P") - .Join("Authors", "Authors.Id", "P.AuthorId") - .Where("Authors.Id", 5) - .AsDelete(); - - var c = Compile(q); - - Assert.Equal("DELETE [P] FROM [Posts] AS [P] \nINNER JOIN [Authors] ON [Authors].[Id] = [P].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]); - } + var q = new Query("Posts") + .Join("Authors", "Authors.Id", "Posts.AuthorId") + .Where("Authors.Id", 5) + .AsDelete(); + + var c = Compile(q); + + Assert.Equal( + "DELETE [Posts] FROM [Posts] \n" + + "INNER JOIN [Authors] ON [Authors].[Id] = [Posts].[AuthorId] WHERE [Authors].[Id] = 5", + c[EngineCodes.SqlServer]); + Assert.Equal( + "DELETE `Posts` FROM `Posts` \n" + + "INNER JOIN `Authors` ON `Authors`.`Id` = `Posts`.`AuthorId` WHERE `Authors`.`Id` = 5", + c[EngineCodes.MySql]); + } + + [Fact] + public void DeleteWithJoinAndAlias() + { + var q = new Query("Posts as P") + .Join("Authors", "Authors.Id", "P.AuthorId") + .Where("Authors.Id", 5) + .AsDelete(); + + var c = Compile(q); + + Assert.Equal( + "DELETE [P] FROM [Posts] AS [P] \nINNER JOIN [Authors] ON [Authors].[Id] = [P].[AuthorId] WHERE [Authors].[Id] = 5", + c[EngineCodes.SqlServer]); } } diff --git a/QueryBuilder.Tests/ExecutionTests.cs b/QueryBuilder.Tests/ExecutionTests.cs index 5d41e7fd..bcf087c8 100644 --- a/QueryBuilder.Tests/ExecutionTests.cs +++ b/QueryBuilder.Tests/ExecutionTests.cs @@ -1,36 +1,30 @@ -using System; using SqlKata.Execution; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class ExecutionTests { - public class ExecutionTests + [Fact] + public void ShouldThrowException() + { + Assert.Throws(() => { new Query("Books").Get(); }); + } + + [Fact] + public void TimeoutShouldBeCarriedToNewCreatedFactory() { - [Fact] - public void ShouldThrowException() - { - Assert.Throws(() => - { - new Query("Books").Get(); - }); - } + var db = new QueryFactory(); + db.QueryTimeout = 4000; + var newFactory = QueryExtensions.CreateQueryFactory(db.Query()); + Assert.Equal(db.QueryTimeout, newFactory.QueryTimeout); + } - [Fact] - public void TimeoutShouldBeCarriedToNewCreatedFactory() - { - var db = new QueryFactory(); - db.QueryTimeout = 4000; - var newFactory = QueryExtensions.CreateQueryFactory(db.Query()); - Assert.Equal(db.QueryTimeout, newFactory.QueryTimeout); - } - - [Fact(Skip = "timeout over cloned xQuery is not supported yet")] - public void TimeoutShouldBeCarriedToNewCreatedFactoryAfterClone() - { - var db = new QueryFactory(); - db.QueryTimeout = 4000; - var newFactory = QueryExtensions.CreateQueryFactory(db.Query().Clone()); - Assert.Equal(db.QueryTimeout, newFactory.QueryTimeout); - } + [Fact(Skip = "timeout over cloned xQuery is not supported yet")] + public void TimeoutShouldBeCarriedToNewCreatedFactoryAfterClone() + { + var db = new QueryFactory(); + db.QueryTimeout = 4000; + var newFactory = QueryExtensions.CreateQueryFactory(db.Query().Clone()); + Assert.Equal(db.QueryTimeout, newFactory.QueryTimeout); } } diff --git a/QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs b/QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs index 9ef93ff3..fd9b2722 100644 --- a/QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs +++ b/QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs @@ -1,55 +1,49 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Firebird -{ - public class FirebirdLimitTests : TestSupport - { - private readonly FirebirdCompiler compiler; - - public FirebirdLimitTests() - { - compiler = Compilers.Get(EngineCodes.Firebird); - } - - [Fact] - public void NoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; +namespace SqlKata.Tests.Firebird; - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void LimitOnly() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; - - Assert.Null(compiler.CompileLimit(ctx)); - } +public sealed class FirebirdLimitTests +{ + private readonly FirebirdCompiler _compiler = new(); - [Fact] - public void OffsetOnly() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void NoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "TABLE" + """); + } - Assert.Null(compiler.CompileLimit(ctx)); - } + [Fact] + public void LimitOnly() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT FIRST 10 * FROM "TABLE" + """); + } - [Fact] - public void LimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void OffsetOnly() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT SKIP 20 * FROM "TABLE" + """); + } - Assert.Equal("ROWS ? TO ?", compiler.CompileLimit(ctx)); - Assert.Equal(21L, ctx.Bindings[0]); - Assert.Equal(25L, ctx.Bindings[1]); - Assert.Equal(2, ctx.Bindings.Count); - } + [Fact] + public void LimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "TABLE" ROWS 21 TO 25 + """); } } diff --git a/QueryBuilder.Tests/GeneralTests.cs b/QueryBuilder.Tests/GeneralTests.cs index 63fb3d3f..f0ae52e8 100644 --- a/QueryBuilder.Tests/GeneralTests.cs +++ b/QueryBuilder.Tests/GeneralTests.cs @@ -1,605 +1,628 @@ using SqlKata.Compilers; using SqlKata.Extensions; using SqlKata.Tests.Infrastructure; -using System; -using System.Linq; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class GeneralTests : TestSupport { - public class GeneralTests : TestSupport + [Fact] + public void ColumnsEscaping() { - [Fact] - public void ColumnsEscaping() - { - var q = new Query().From("users") - .Select("mycol[isthis]"); + var q = new Query().From("users") + .Select("mycol[isthis]"); - var c = Compile(q); + var c = Compile(q); - Assert.Equal("SELECT [mycol[isthis]]] FROM [users]", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT [mycol[isthis]]] FROM [users]", c[EngineCodes.SqlServer]); + } - [Fact] - public void InnerScopeEngineWithinCTE() - { - var series = new Query("table") - .ForPostgreSql(q => q.WhereRaw("postgres = true")) - .ForSqlServer(q => q.WhereRaw("sqlsrv = 1")) - .ForFirebird(q => q.WhereRaw("firebird = 1")); - var query = new Query("series").With("series", series); + [Fact] + public void InnerScopeEngineWithinCte() + { + var series = new Query("table") + .ForPostgreSql(q => q.WhereRaw("postgres = true")) + .ForSqlServer(q => q.WhereRaw("sqlsrv = 1")) + .ForFirebird(q => q.WhereRaw("firebird = 1")); + var query = new Query("series").With("series", series); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("WITH [series] AS (SELECT * FROM [table] WHERE sqlsrv = 1)\nSELECT * FROM [series]", c[EngineCodes.SqlServer]); + Assert.Equal("WITH [series] AS (SELECT * FROM [table] WHERE sqlsrv = 1)\nSELECT * FROM [series]", + c[EngineCodes.SqlServer]); - Assert.Equal("WITH \"series\" AS (SELECT * FROM \"table\" WHERE postgres = true)\nSELECT * FROM \"series\"", - c[EngineCodes.PostgreSql]); - Assert.Equal("WITH \"SERIES\" AS (SELECT * FROM \"TABLE\" WHERE firebird = 1)\nSELECT * FROM \"SERIES\"", - c[EngineCodes.Firebird]); - } + Assert.Equal("WITH \"series\" AS (SELECT * FROM \"table\" WHERE postgres = true)\nSELECT * FROM \"series\"", + c[EngineCodes.PostgreSql]); + Assert.Equal("WITH \"SERIES\" AS (SELECT * FROM \"TABLE\" WHERE firebird = 1)\nSELECT * FROM \"SERIES\"", + c[EngineCodes.Firebird]); + } - [Fact] - public void InnerScopeEngineWithinSubQuery() - { - var series = new Query("table") - .ForPostgreSql(q => q.WhereRaw("postgres = true")) - .ForSqlServer(q => q.WhereRaw("sqlsrv = 1")) - .ForFirebird(q => q.WhereRaw("firebird = 1")); - var query = new Query("series").From(series.As("series")); + [Fact] + public void InnerScopeEngineWithinSubQuery() + { + var series = new Query("table") + .ForPostgreSql(q => q.WhereRaw("postgres = true")) + .ForSqlServer(q => q.WhereRaw("sqlsrv = 1")) + .ForFirebird(q => q.WhereRaw("firebird = 1")); + var query = new Query("series").From(series.As("series")); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("SELECT * FROM (SELECT * FROM [table] WHERE sqlsrv = 1) AS [series]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM (SELECT * FROM [table] WHERE sqlsrv = 1) AS [series]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM (SELECT * FROM \"table\" WHERE postgres = true) AS \"series\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM (SELECT * FROM \"TABLE\" WHERE firebird = 1) AS \"SERIES\"", c[EngineCodes.Firebird]); - } + Assert.Equal("SELECT * FROM (SELECT * FROM \"table\" WHERE postgres = true) AS \"series\"", + c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT * FROM (SELECT * FROM \"TABLE\" WHERE firebird = 1) AS \"SERIES\"", + c[EngineCodes.Firebird]); + } - [Fact] - public void ItShouldCacheMethodInfoByType() - { - var compiler = new TestSqlServerCompiler(); + [Fact] + public void Custom_compiler_with_empty_identifier_overrides_should_remove_identifiers() + { + var compiler = new TestEmptyIdentifiersCompiler(); - var call1 = compiler.Call_FindCompilerMethodInfo( - typeof(BasicCondition), "CompileBasicCondition" - ); + var wrappedValue = compiler.XService.WrapValue("Table"); - var call2 = compiler.Call_FindCompilerMethodInfo( - typeof(BasicCondition), "CompileBasicCondition" - ); + Assert.Equal("Table", wrappedValue); + } - Assert.Same(call1, call2); - } + [Fact] + public void Should_Equal_AfterMultipleCompile() + { + var query = new Query() + .Select("Id", "Name") + .From("Table") + .OrderBy("Name") + .Limit(20) + .Offset(1); + + var first = Compile(query); + Assert.Equal( + "SELECT * FROM (" + + "SELECT [Id], [Name], ROW_NUMBER() " + + "OVER (ORDER BY [Name]) AS [row_num] " + + "FROM [Table]) AS [results_wrapper] " + + "WHERE [row_num] BETWEEN 2 AND 21", + first[EngineCodes.SqlServer]); + Assert.Equal("SELECT `Id`, `Name` FROM `Table` ORDER BY `Name` LIMIT 20 OFFSET 1", first[EngineCodes.MySql]); + Assert.Equal("SELECT \"Id\", \"Name\" FROM \"Table\" ORDER BY \"Name\" LIMIT 20 OFFSET 1", + first[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"TABLE\" ORDER BY \"NAME\" ROWS 2 TO 21", + first[EngineCodes.Firebird]); + + var second = Compile(query); + + Assert.Equal(first[EngineCodes.SqlServer], second[EngineCodes.SqlServer]); + Assert.Equal(first[EngineCodes.MySql], second[EngineCodes.MySql]); + Assert.Equal(first[EngineCodes.PostgreSql], second[EngineCodes.PostgreSql]); + Assert.Equal(first[EngineCodes.Firebird], second[EngineCodes.Firebird]); + } - [Fact] - public void Return_Different_MethodInfo_WhenSame_Method_With_Different_GenericTypes() - { - var compiler = new TestSqlServerCompiler(); + [Fact] + public void Raw_WrapIdentifiers() + { + var query = new Query("Users").SelectRaw("[Id], [Name], {Age}"); - var call1 = compiler.Call_FindCompilerMethodInfo( - typeof(NestedCondition), "CompileNestedCondition" - ); + var c = Compile(query); - var call2 = compiler.Call_FindCompilerMethodInfo( - typeof(NestedCondition), "CompileNestedCondition" - ); + Assert.Equal("SELECT [Id], [Name], [Age] FROM [Users]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `Id`, `Name`, `Age` FROM `Users`", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"Id\", \"Name\", \"Age\" FROM \"Users\"", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"Id\", \"Name\", \"Age\" FROM \"USERS\"", c[EngineCodes.Firebird]); + } - Assert.NotSame(call1, call2); - } + [Fact] + public void Raw_WrapIdentifiers_Escaped() + { + var query = new Query("Users").SelectRaw("'\\{1,2,3\\}'::int\\[\\]"); - [Fact] - public void Custom_compiler_with_empty_identifier_overrides_should_remove_identifiers() - { - var compiler = new TestEmptyIdentifiersCompiler(); + var c = Compile(query); - var wrappedValue = compiler.WrapValue("Table"); + Assert.Equal("SELECT '{1,2,3}'::int[] FROM \"Users\"", c[EngineCodes.PostgreSql]); + } - Assert.Equal("Table", wrappedValue); - } + [Fact] + public void WrapWithSpace() + { + var compiler = new SqlServerCompiler(); - [Fact] - public void Should_Equal_AfterMultipleCompile() - { - var query = new Query() - .Select("Id", "Name") - .From("Table") - .OrderBy("Name") - .Limit(20) - .Offset(1); - - var first = Compile(query); - Assert.Equal( - "SELECT * FROM (SELECT [Id], [Name], ROW_NUMBER() OVER (ORDER BY [Name]) AS [row_num] FROM [Table]) AS [results_wrapper] WHERE [row_num] BETWEEN 2 AND 21", - first[EngineCodes.SqlServer]); - Assert.Equal("SELECT `Id`, `Name` FROM `Table` ORDER BY `Name` LIMIT 20 OFFSET 1", first[EngineCodes.MySql]); - Assert.Equal("SELECT \"Id\", \"Name\" FROM \"Table\" ORDER BY \"Name\" LIMIT 20 OFFSET 1", first[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"TABLE\" ORDER BY \"NAME\" ROWS 2 TO 21", first[EngineCodes.Firebird]); - - var second = Compile(query); - - Assert.Equal(first[EngineCodes.SqlServer], second[EngineCodes.SqlServer]); - Assert.Equal(first[EngineCodes.MySql], second[EngineCodes.MySql]); - Assert.Equal(first[EngineCodes.PostgreSql], second[EngineCodes.PostgreSql]); - Assert.Equal(first[EngineCodes.Firebird], second[EngineCodes.Firebird]); - } - - [Fact] - public void Raw_WrapIdentifiers() - { - var query = new Query("Users").SelectRaw("[Id], [Name], {Age}"); - var c = Compile(query); + Assert.Equal("[My Table] AS [Table]", compiler.XService.WrapName("My Table as Table")); + } - Assert.Equal("SELECT [Id], [Name], [Age] FROM [Users]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `Id`, `Name`, `Age` FROM `Users`", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"Id\", \"Name\", \"Age\" FROM \"Users\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"Id\", \"Name\", \"Age\" FROM \"USERS\"", c[EngineCodes.Firebird]); - } + [Fact] + public void WrapWithDotes() + { + var compiler = new SqlServerCompiler(); - [Fact] - public void Raw_WrapIdentifiers_Escaped() - { - var query = new Query("Users").SelectRaw("'\\{1,2,3\\}'::int\\[\\]"); - var c = Compile(query); + Assert.Equal("[My Schema].[My Table] AS [Table]", compiler.XService.WrapName("My Schema.My Table as Table")); + } - Assert.Equal("SELECT '{1,2,3}'::int[] FROM \"Users\"", c[EngineCodes.PostgreSql]); - } + [Fact] + public void WrapWithMultipleSpaces() + { + var compiler = new SqlServerCompiler(); - [Fact] - public void WrapWithSpace() - { - var compiler = new SqlServerCompiler(); + Assert.Equal("[My Table One] AS [Table One]", compiler.XService.WrapName("My Table One as Table One")); + } - Assert.Equal("[My Table] AS [Table]", compiler.Wrap("My Table as Table")); - } + [Fact] + public void CompilerSpecificFrom() + { + var query = new Query() + .ForSqlServer(q => q.From("mssql")) + .ForPostgreSql(q => q.From("pgsql")) + .ForMySql(q => q.From("mysql")); + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); + + Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); + Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); + Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); + } - [Fact] - public void WrapWithDotes() - { - var compiler = new SqlServerCompiler(); + [Fact] + public void CompilerSpecificFromRaw() + { + var query = new Query() + .ForSqlServer(q => q.FromRaw("[mssql]")) + .ForPostgreSql(q => q.FromRaw("[pgsql]")) + .ForMySql(q => q.FromRaw("[mysql]")); + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); + + Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); + Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); + Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); + } + [Fact] + public void CompilerSpecificFromMixed() + { + var query = new Query() + .ForSqlServer(q => q.From("mssql")) + .ForPostgreSql(q => q.FromRaw("[pgsql]")) + .ForMySql(q => q.From("mysql")); + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); + + Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); + Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); + Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); + } - Assert.Equal("[My Schema].[My Table] AS [Table]", compiler.Wrap("My Schema.My Table as Table")); - } + [Fact] + public void OneClausePerEngine() + { + var query = new Query("generic") + .ForSqlServer(q => q.From("dnu")) + .ForSqlServer(q => q.From("mssql")); + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); + + Assert.Equal(2, query.Components.Clauses.OfType().Count()); + Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); + Assert.Equal("SELECT * FROM \"generic\"", c[EngineCodes.PostgreSql].RawSql); + Assert.Equal("SELECT * FROM `generic`", c[EngineCodes.MySql].RawSql); + } - [Fact] - public void WrapWithMultipleSpaces() - { - var compiler = new SqlServerCompiler(); + [Theory] + [InlineData(null, null)] + [InlineData(null, "mssql")] + [InlineData("original", null)] + public void AddOrReplace_Works(string? table, string engine) + { + var query = new Query(); + if (table != null) + query = query.From(table); + query.AddOrReplaceComponent(new FromClause + { + Component = "from", + Table = "updated", + Engine = engine, + Alias = "alias", + }); + + Assert.Equal("updated", query.Components.Clauses.OfType().Single().Table); + } + [Theory] + [InlineData(null, "generic")] + [InlineData(EngineCodes.SqlServer, "mssql")] + [InlineData(EngineCodes.MySql, "generic")] + public void GetOneComponent_Prefers_Engine(string engine, string column) + { + var query = new Query() + .Where("generic", "foo") + .ForSqlServer(q => q.Where("mssql", "foo")); - Assert.Equal("[My Table One] AS [Table One]", compiler.Wrap("My Table One as Table One")); - } + var where = query.GetOneComponent("where", engine) as BasicCondition; - [Fact] - public void CompilerSpecificFrom() - { - var query = new Query() - .ForSqlServer(q => q.From("mssql")) - .ForPostgreSql(q => q.From("pgsql")) - .ForMySql(q => q.From("mysql")); - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); - - Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); - Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); - Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); - } - - [Fact] - public void CompilerSpecificFromRaw() - { - var query = new Query() - .ForSqlServer(q => q.FromRaw("[mssql]")) - .ForPostgreSql(q => q.FromRaw("[pgsql]")) - .ForMySql(q => q.FromRaw("[mysql]")); - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); - - Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); - Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); - Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); - } - - [Fact] - public void CompilerSpecificFromMixed() - { - var query = new Query() - .ForSqlServer(q => q.From("mssql")) - .ForPostgreSql(q => q.FromRaw("[pgsql]")) - .ForMySql(q => q.From("mysql")); - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); - - Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); - Assert.Equal("SELECT * FROM \"pgsql\"", c[EngineCodes.PostgreSql].RawSql); - Assert.Equal("SELECT * FROM `mysql`", c[EngineCodes.MySql].RawSql); - } - - [Fact] - public void OneFromPerEngine() - { - var query = new Query("generic") - .ForSqlServer(q => q.From("dnu")) - .ForSqlServer(q => q.From("mssql")); - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); - - Assert.Equal(2, query.Clauses.OfType().Count()); - Assert.Equal("SELECT * FROM [mssql]", c[EngineCodes.SqlServer].RawSql); - Assert.Equal("SELECT * FROM \"generic\"", c[EngineCodes.PostgreSql].RawSql); - Assert.Equal("SELECT * FROM `generic`", c[EngineCodes.MySql].RawSql); - } - - [Theory] - [InlineData(null, null)] - [InlineData(null, "mssql")] - [InlineData("original", null)] - [InlineData("original", "mssql")] - public void AddOrReplace_Works(string table, string engine) - { - var query = new Query(); - if (table != null) - query.From(table); - query.AddOrReplaceComponent("from", new FromClause() { Table = "updated", Engine = engine }); - var froms = query.Clauses.OfType(); - - Assert.Single(froms); - Assert.Equal("updated", froms.Single().Table); - } - - [Theory] - [InlineData(null, "generic")] - [InlineData(EngineCodes.SqlServer, "mssql")] - [InlineData(EngineCodes.MySql, "generic")] - public void GetOneComponent_Prefers_Engine(string engine, string column) - { - var query = new Query() - .Where("generic", "foo") - .ForSqlServer(q => q.Where("mssql", "foo")); + Assert.NotNull(where); + Assert.Equal(column, where.Column); + } - var where = query.GetOneComponent("where", engine) as BasicCondition; + [Fact] + public void AddOrReplace_Throws_MoreThanOne() + { + var query = new Query() + .Where("a", "b") + .Where("c", "d"); - Assert.NotNull(where); - Assert.Equal(column, where.Column); - } + Assert.Throws(() => + query.AddOrReplaceComponent(new BasicCondition + { + Engine = null, + Component = "where", + Value = "does not matter", + Column = "does not matter", + Operator = "does not matter", + IsOr = false, + IsNot = false + })); + } - [Fact] - public void AddOrReplace_Throws_MoreThanOne() - { - var query = new Query() - .Where("a", "b") - .Where("c", "d"); + [Fact] + public void OneLimitPerEngine() + { + var query = new Query("mytable") + .ForSqlServer(q => q.Limit(5)) + .ForSqlServer(q => q.Limit(10)); - Action act = () => query.AddOrReplaceComponent("where", new BasicCondition()); - Assert.Throws(act); - } + var limits = query.GetComponents("limit", EngineCodes.SqlServer); + Assert.Single(limits); + Assert.Equal(10, limits.Single().Limit); + } - [Fact] - public void OneLimitPerEngine() - { - var query = new Query("mytable") - .ForSqlServer(q => q.Limit(5)) - .ForSqlServer(q => q.Limit(10)); + [Fact] + public void CompilerSpecificLimit() + { + var query = new Query("mytable") + .ForSqlServer(q => q.Limit(5)) + .ForPostgreSql(q => q.Limit(10)); - var limits = query.GetComponents("limit", EngineCodes.SqlServer); - Assert.Single(limits); - Assert.Equal(10, limits.Single().Limit); - } + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - [Fact] - public void CompilerSpecificLimit() - { - var query = new Query("mytable") - .ForSqlServer(q => q.Limit(5)) - .ForPostgreSql(q => q.Limit(10)); + Assert.Equal(2, query.GetComponents("limit").Count); + Assert.Equal("SELECT TOP (5) * FROM [mytable]", c[EngineCodes.SqlServer].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" LIMIT 10", c[EngineCodes.PostgreSql].ToString()); + Assert.Equal("SELECT * FROM `mytable`", c[EngineCodes.MySql].ToString()); + } - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + [Fact] + public void OneOffsetPerEngine() + { + var query = new Query("mytable") + .ForSqlServer(q => q.Offset(5)) + .ForSqlServer(q => q.Offset(10)); - Assert.Equal(2, query.GetComponents("limit").Count); - Assert.Equal("SELECT TOP (5) * FROM [mytable]", c[EngineCodes.SqlServer].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" LIMIT 10", c[EngineCodes.PostgreSql].ToString()); - Assert.Equal("SELECT * FROM `mytable`", c[EngineCodes.MySql].ToString()); - } + var limits = query.GetComponents("offset", EngineCodes.SqlServer); + Assert.Single(limits); + Assert.Equal(10, limits.Single().Offset); + } - [Fact] - public void OneOffsetPerEngine() - { - var query = new Query("mytable") - .ForSqlServer(q => q.Offset(5)) - .ForSqlServer(q => q.Offset(10)); + [Fact] + public void CompilerSpecificOffset() + { + var query = new Query("mytable") + .ForMySql(q => q.Offset(5)) + .ForPostgreSql(q => q.Offset(10)); - var limits = query.GetComponents("offset", EngineCodes.SqlServer); - Assert.Single(limits); - Assert.Equal(10, limits.Single().Offset); - } + var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - [Fact] - public void CompilerSpecificOffset() - { - var query = new Query("mytable") - .ForMySql(q => q.Offset(5)) - .ForPostgreSql(q => q.Offset(10)); + Assert.Equal(2, query.GetComponents("offset").Count); + Assert.Equal("SELECT * FROM `mytable` LIMIT 18446744073709551615 OFFSET 5", c[EngineCodes.MySql].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" OFFSET 10", c[EngineCodes.PostgreSql].ToString()); + Assert.Equal("SELECT * FROM [mytable]", c[EngineCodes.SqlServer].ToString()); + } - var engines = new[] { EngineCodes.SqlServer, EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + [Fact] + public void Limit_Takes_Generic_If_Needed() + { + var query = new Query("mytable") + .Limit(5) + .Offset(10) + .ForPostgreSql(q => q.Offset(20)); - Assert.Equal(2, query.GetComponents("offset").Count); - Assert.Equal("SELECT * FROM `mytable` LIMIT 18446744073709551615 OFFSET 5", c[EngineCodes.MySql].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" OFFSET 10", c[EngineCodes.PostgreSql].ToString()); - Assert.Equal("SELECT * FROM [mytable]", c[EngineCodes.SqlServer].ToString()); - } + var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - [Fact] - public void Limit_Takes_Generic_If_Needed() - { - var query = new Query("mytable") - .Limit(5) - .Offset(10) - .ForPostgreSql(q => q.Offset(20)); + Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 10", c[EngineCodes.MySql].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" LIMIT 5 OFFSET 20", c[EngineCodes.PostgreSql].ToString()); + } - var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + [Fact] + public void Offset_Takes_Generic_If_Needed() + { + var query = new Query("mytable") + .Limit(5) + .Offset(10) + .ForPostgreSql(q => q.Limit(20)); - Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 10", c[EngineCodes.MySql].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" LIMIT 5 OFFSET 20", c[EngineCodes.PostgreSql].ToString()); - } + var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - [Fact] - public void Offset_Takes_Generic_If_Needed() - { - var query = new Query("mytable") - .Limit(5) - .Offset(10) - .ForPostgreSql(q => q.Limit(20)); + Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 10", c[EngineCodes.MySql].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" LIMIT 20 OFFSET 10", c[EngineCodes.PostgreSql].ToString()); + } + + [Fact] + public void Can_Change_Generic_Limit_After_SpecificOffset() + { + var query = new Query("mytable") + .Limit(5) + .Offset(10) + .ForPostgreSql(q => q.Offset(20)) + .Limit(7); - var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 10", c[EngineCodes.MySql].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" LIMIT 20 OFFSET 10", c[EngineCodes.PostgreSql].ToString()); - } + Assert.Equal("SELECT * FROM `mytable` LIMIT 7 OFFSET 10", c[EngineCodes.MySql].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" LIMIT 7 OFFSET 20", c[EngineCodes.PostgreSql].ToString()); + } - [Fact] - public void Can_Change_Generic_Limit_After_SpecificOffset() - { - var query = new Query("mytable") - .Limit(5) - .Offset(10) - .ForPostgreSql(q => q.Offset(20)) - .Limit(7); + [Fact] + public void Can_Change_Generic_Offset_After_SpecificLimit() + { + var query = new Query("mytable") + .Limit(5) + .Offset(10) + .ForPostgreSql(q => q.Limit(20)) + .Offset(7); - var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; + var c = Compilers.Compile(engines, query); - Assert.Equal("SELECT * FROM `mytable` LIMIT 7 OFFSET 10", c[EngineCodes.MySql].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" LIMIT 7 OFFSET 20", c[EngineCodes.PostgreSql].ToString()); - } + Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 7", c[EngineCodes.MySql].ToString()); + Assert.Equal("SELECT * FROM \"mytable\" LIMIT 20 OFFSET 7", c[EngineCodes.PostgreSql].ToString()); + } + + [Fact] + public void Where_Nested() + { + var query = new Query("table") + .Where(q => q.Where("a", 1).OrWhere("a", 2)); - [Fact] - public void Can_Change_Generic_Offset_After_SpecificLimit() + var engines = new[] { - var query = new Query("mytable") - .Limit(5) - .Offset(10) - .ForPostgreSql(q => q.Limit(20)) - .Offset(7); + EngineCodes.SqlServer + }; - var engines = new[] { EngineCodes.MySql, EngineCodes.PostgreSql }; - var c = Compilers.Compile(engines, query); + var c = Compilers.Compile(engines, query); - Assert.Equal("SELECT * FROM `mytable` LIMIT 5 OFFSET 7", c[EngineCodes.MySql].ToString()); - Assert.Equal("SELECT * FROM \"mytable\" LIMIT 20 OFFSET 7", c[EngineCodes.PostgreSql].ToString()); - } + Assert.Equal("SELECT * FROM [table] WHERE ([a] = 1 OR [a] = 2)", c[EngineCodes.SqlServer].ToString()); + } - [Fact] - public void Where_Nested() - { - var query = new Query("table") - .Where(q => q.Where("a", 1).OrWhere("a", 2)); + [Fact] + public void AdHoc_Throws_WhenNoColumnsProvided() + { + Assert.Throws(() => + new Query("rows").With("rows", + new string[0], + new[] + { + new object[] { }, + new object[] { } + })); + } - var engines = new[] { - EngineCodes.SqlServer, - }; - - var c = Compilers.Compile(engines, query); - - Assert.Equal("SELECT * FROM [table] WHERE ([a] = 1 OR [a] = 2)", c[EngineCodes.SqlServer].ToString()); - } - - [Fact] - public void AdHoc_Throws_WhenNoColumnsProvided() => - Assert.Throws(() => - new Query("rows").With("rows", - new string[0], - new object[][] { - new object[] {}, - new object[] {}, - })); - - [Fact] - public void AdHoc_Throws_WhenNoValueRowsProvided() => - Assert.Throws(() => - new Query("rows").With("rows", - new[] { "a", "b", "c" }, - new object[][] { - })); - - [Fact] - public void AdHoc_Throws_WhenColumnsOutnumberFieldValues() => - Assert.Throws(() => - new Query("rows").With("rows", - new[] { "a", "b", "c", "d" }, - new object[][] { - new object[] { 1, 2, 3 }, - new object[] { 4, 5, 6 }, - })); - - [Fact] - public void AdHoc_Throws_WhenFieldValuesOutNumberColumns() => - Assert.Throws(() => - new Query("rows").With("rows", - new[] { "a", "b" }, - new object[][] { - new object[] { 1, 2, 3 }, - new object[] { 4, 5, 6 }, - })); - - [Fact] - public void AdHoc_SingletonRow() - { - var query = new Query("rows").With("rows", - new[] { "a" }, - new object[][] { - new object[] { 1 }, - }); - - var c = Compilers.Compile(query); - - Assert.Equal("WITH [rows] AS (SELECT [a] FROM (VALUES (1)) AS tbl ([a]))\nSELECT * FROM [rows]", c[EngineCodes.SqlServer].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\")\nSELECT * FROM \"rows\"", c[EngineCodes.PostgreSql].ToString()); - Assert.Equal("WITH `rows` AS (SELECT 1 AS `a`)\nSELECT * FROM `rows`", c[EngineCodes.MySql].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\")\nSELECT * FROM \"rows\"", c[EngineCodes.Sqlite].ToString()); - Assert.Equal("WITH \"ROWS\" AS (SELECT 1 AS \"A\" FROM RDB$DATABASE)\nSELECT * FROM \"ROWS\"", c[EngineCodes.Firebird].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\" FROM DUAL)\nSELECT * FROM \"rows\"", c[EngineCodes.Oracle].ToString()); - } - - [Fact] - public void AdHoc_TwoRows() - { - var query = new Query("rows").With("rows", + [Fact] + public void AdHoc_Throws_WhenNoValueRowsProvided() + { + Assert.Throws(() => + new Query("rows").With("rows", new[] { "a", "b", "c" }, - new object[][] { + new object[][] + { + })); + } + + [Fact] + public void AdHoc_Throws_WhenColumnsOutnumberFieldValues() + { + Assert.Throws(() => + new Query("rows").With("rows", + new[] { "a", "b", "c", "d" }, + new[] + { + new object[] { 1, 2, 3 }, + new object[] { 4, 5, 6 } + })); + } + + [Fact] + public void AdHoc_Throws_WhenFieldValuesOutNumberColumns() + { + Assert.Throws(() => + new Query("rows").With("rows", + new[] { "a", "b" }, + new[] + { new object[] { 1, 2, 3 }, - new object[] { 4, 5, 6 }, - }); + new object[] { 4, 5, 6 } + })); + } - var c = Compilers.Compile(query); + [Fact] + public void AdHoc_SingletonRow() + { + var query = new Query("rows").With("rows", + new[] { "a" }, + new[] + { + new object[] { 1 } + }); - Assert.Equal("WITH [rows] AS (SELECT [a], [b], [c] FROM (VALUES (1, 2, 3), (4, 5, 6)) AS tbl ([a], [b], [c]))\nSELECT * FROM [rows]", c[EngineCodes.SqlServer].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\")\nSELECT * FROM \"rows\"", c[EngineCodes.PostgreSql].ToString()); - Assert.Equal("WITH `rows` AS (SELECT 1 AS `a`, 2 AS `b`, 3 AS `c` UNION ALL SELECT 4 AS `a`, 5 AS `b`, 6 AS `c`)\nSELECT * FROM `rows`", c[EngineCodes.MySql].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\")\nSELECT * FROM \"rows\"", c[EngineCodes.Sqlite].ToString()); - Assert.Equal("WITH \"ROWS\" AS (SELECT 1 AS \"A\", 2 AS \"B\", 3 AS \"C\" FROM RDB$DATABASE UNION ALL SELECT 4 AS \"A\", 5 AS \"B\", 6 AS \"C\" FROM RDB$DATABASE)\nSELECT * FROM \"ROWS\"", c[EngineCodes.Firebird].ToString()); - Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" FROM DUAL UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\" FROM DUAL)\nSELECT * FROM \"rows\"", c[EngineCodes.Oracle].ToString()); - } + var c = Compilers.Compile(query); + + Assert.Equal("WITH [rows] AS (SELECT [a] FROM (VALUES (1)) AS tbl ([a]))\nSELECT * FROM [rows]", + c[EngineCodes.SqlServer].ToString()); + Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\")\nSELECT * FROM \"rows\"", + c[EngineCodes.PostgreSql].ToString()); + Assert.Equal("WITH `rows` AS (SELECT 1 AS `a`)\nSELECT * FROM `rows`", c[EngineCodes.MySql].ToString()); + Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\")\nSELECT * FROM \"rows\"", c[EngineCodes.Sqlite].ToString()); + Assert.Equal("WITH \"ROWS\" AS (SELECT 1 AS \"A\" FROM RDB$DATABASE)\nSELECT * FROM \"ROWS\"", + c[EngineCodes.Firebird].ToString()); + Assert.Equal("WITH \"rows\" AS (SELECT 1 AS \"a\" FROM DUAL)\nSELECT * FROM \"rows\"", + c[EngineCodes.Oracle].ToString()); + } - [Fact] - public void AdHoc_ProperBindingsPlacement() - { - var query = new Query("rows") - .With("othercte", q => q.From("othertable").Where("othertable.status", "A")) - .Where("rows.foo", "bar") - .With("rows", + [Fact] + public void AdHoc_TwoRows() + { + var query = new Query("rows").With("rows", + new[] { "a", "b", "c" }, + new[] + { + new object[] { 1, 2, 3 }, + new object[] { 4, 5, 6 } + }); + + var c = Compilers.Compile(query); + + Assert.Equal( + "WITH [rows] AS (SELECT [a], [b], [c] FROM (VALUES (1, 2, 3), (4, 5, 6)) AS tbl ([a], [b], [c]))\nSELECT * FROM [rows]", + c[EngineCodes.SqlServer].ToString()); + Assert.Equal( + "WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\")\nSELECT * FROM \"rows\"", + c[EngineCodes.PostgreSql].ToString()); + Assert.Equal( + "WITH `rows` AS (SELECT 1 AS `a`, 2 AS `b`, 3 AS `c` UNION ALL SELECT 4 AS `a`, 5 AS `b`, 6 AS `c`)\nSELECT * FROM `rows`", + c[EngineCodes.MySql].ToString()); + Assert.Equal( + "WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\")\nSELECT * FROM \"rows\"", + c[EngineCodes.Sqlite].ToString()); + Assert.Equal( + "WITH \"ROWS\" AS (SELECT 1 AS \"A\", 2 AS \"B\", 3 AS \"C\" FROM RDB$DATABASE UNION ALL SELECT 4 AS \"A\", 5 AS \"B\", 6 AS \"C\" FROM RDB$DATABASE)\nSELECT * FROM \"ROWS\"", + c[EngineCodes.Firebird].ToString()); + Assert.Equal( + "WITH \"rows\" AS (SELECT 1 AS \"a\", 2 AS \"b\", 3 AS \"c\" FROM DUAL UNION ALL SELECT 4 AS \"a\", 5 AS \"b\", 6 AS \"c\" FROM DUAL)\nSELECT * FROM \"rows\"", + c[EngineCodes.Oracle].ToString()); + } + + [Fact] + public void AdHoc_ProperBindingsPlacement() + { + var query = new Query("rows") + .With("othercte", q => q.From("othertable").Where("othertable.status", "A")) + .Where("rows.foo", "bar") + .With("rows", new[] { "a", "b", "c" }, - new object[][] { + new[] + { new object[] { 1, 2, 3 }, - new object[] { 4, 5, 6 }, + new object[] { 4, 5, 6 } }) - .Where("rows.baz", "buzz"); + .Where("rows.baz", "buzz"); - var c = Compilers.Compile(query); + var c = Compilers.Compile(query); - Assert.Equal(string.Join("\n", new[] { - "WITH [othercte] AS (SELECT * FROM [othertable] WHERE [othertable].[status] = 'A'),", + Assert.Equal( + string.Join("\n", "WITH [othercte] AS (SELECT * FROM [othertable] WHERE [othertable].[status] = 'A'),", "[rows] AS (SELECT [a], [b], [c] FROM (VALUES (1, 2, 3), (4, 5, 6)) AS tbl ([a], [b], [c]))", - "SELECT * FROM [rows] WHERE [rows].[foo] = 'bar' AND [rows].[baz] = 'buzz'", - }), c[EngineCodes.SqlServer].ToString()); - } + "SELECT * FROM [rows] WHERE [rows].[foo] = 'bar' AND [rows].[baz] = 'buzz'"), + c[EngineCodes.SqlServer].ToString()); + } - [Fact] - public void UnsafeLiteral_Insert() + [Fact] + public void UnsafeLiteral_Insert() + { + var query = new Query("Table").AsInsert(new { - var query = new Query("Table").AsInsert(new - { - Count = new UnsafeLiteral("Count + 1") - }); + Count = new UnsafeLiteral("Count + 1") + }); - var engines = new[] { - EngineCodes.SqlServer, - }; + var engines = new[] + { + EngineCodes.SqlServer + }; - var c = Compilers.Compile(engines, query); + var c = Compilers.Compile(engines, query); - Assert.Equal("INSERT INTO [Table] ([Count]) VALUES (Count + 1)", c[EngineCodes.SqlServer].ToString()); - } + Assert.Equal("INSERT INTO [Table] ([Count]) VALUES (Count + 1)", c[EngineCodes.SqlServer].ToString()); + } - [Fact] - public void UnsafeLiteral_Update() + [Fact] + public void UnsafeLiteral_Update() + { + var query = new Query("Table").AsUpdate(new { - var query = new Query("Table").AsUpdate(new - { - Count = new UnsafeLiteral("Count + 1") - }); + Count = new UnsafeLiteral("Count + 1") + }); + + var engines = new[] + { + EngineCodes.SqlServer + }; - var engines = new[] { - EngineCodes.SqlServer, - }; + var c = Compilers.Compile(engines, query); - var c = Compilers.Compile(engines, query); + Assert.Equal("UPDATE [Table] SET [Count] = Count + 1", c[EngineCodes.SqlServer].ToString()); + } - Assert.Equal("UPDATE [Table] SET [Count] = Count + 1", c[EngineCodes.SqlServer].ToString()); - } + [Fact] + public void Passing_Boolean_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + { + var query = new Query("Table").Where("Col", true); - [Fact] - public void Passing_Boolean_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + var engines = new[] { - var query = new Query("Table").Where("Col", true); + EngineCodes.SqlServer + }; - var engines = new[] { - EngineCodes.SqlServer, - }; + var c = Compilers.Compile(engines, query); - var c = Compilers.Compile(engines, query); + Assert.Equal("SELECT * FROM [Table] WHERE [Col] = cast(1 as bit)", c[EngineCodes.SqlServer].ToString()); + } - Assert.Equal("SELECT * FROM [Table] WHERE [Col] = cast(1 as bit)", c[EngineCodes.SqlServer].ToString()); - } + [Fact] + public void Passing_Boolean_False_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + { + var query = new Query("Table").Where("Col", false); - [Fact] - public void Passing_Boolean_False_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + var engines = new[] { - var query = new Query("Table").Where("Col", false); + EngineCodes.SqlServer + }; - var engines = new[] { - EngineCodes.SqlServer, - }; + var c = Compilers.Compile(engines, query); - var c = Compilers.Compile(engines, query); + Assert.Equal("SELECT * FROM [Table] WHERE [Col] = cast(0 as bit)", c[EngineCodes.SqlServer].ToString()); + } - Assert.Equal("SELECT * FROM [Table] WHERE [Col] = cast(0 as bit)", c[EngineCodes.SqlServer].ToString()); - } + [Fact] + public void Passing_Negative_Boolean_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + { + var query = new Query("Table").Where("Col", "!=", true); - [Fact] - public void Passing_Negative_Boolean_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + var engines = new[] { - var query = new Query("Table").Where("Col", "!=", true); + EngineCodes.SqlServer + }; - var engines = new[] { - EngineCodes.SqlServer, - }; + var c = Compilers.Compile(engines, query); - var c = Compilers.Compile(engines, query); + Assert.Equal("SELECT * FROM [Table] WHERE [Col] != cast(1 as bit)", c[EngineCodes.SqlServer].ToString()); + } - Assert.Equal("SELECT * FROM [Table] WHERE [Col] != cast(1 as bit)", c[EngineCodes.SqlServer].ToString()); - } + [Fact] + public void Passing_Negative_Boolean_False_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + { + var query = new Query("Table").Where("Col", "!=", false); - [Fact] - public void Passing_Negative_Boolean_False_To_Where_Should_Call_WhereTrue_Or_WhereFalse() + var engines = new[] { - var query = new Query("Table").Where("Col", "!=", false); - - var engines = new[] { - EngineCodes.SqlServer, - }; + EngineCodes.SqlServer + }; - var c = Compilers.Compile(engines, query); + var c = Compilers.Compile(engines, query); - Assert.Equal("SELECT * FROM [Table] WHERE [Col] != cast(0 as bit)", c[EngineCodes.SqlServer].ToString()); - } + Assert.Equal("SELECT * FROM [Table] WHERE [Col] != cast(0 as bit)", c[EngineCodes.SqlServer].ToString()); } } diff --git a/QueryBuilder.Tests/HelperTests.cs b/QueryBuilder.Tests/HelperTests.cs index 11a9fd4e..eee77370 100644 --- a/QueryBuilder.Tests/HelperTests.cs +++ b/QueryBuilder.Tests/HelperTests.cs @@ -1,237 +1,100 @@ -using System.Collections; -using System.Linq; -using Xunit; +using FluentAssertions; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class HelperTests { - public class HelperTests + [Theory] + [InlineData("")] + [InlineData(null)] + [InlineData(" ")] + [InlineData(" ")] + [InlineData(" ")] + public void ItShouldKeepItAsIs(string input) { - [Theory] - [InlineData("")] - [InlineData(null)] - [InlineData(" ")] - [InlineData(" ")] - [InlineData(" ")] - public void ItShouldKeepItAsIs(string input) - { - var output = Helper.ReplaceAll(input, "any", x => x + ""); - - Assert.Equal(input, output); - } - - [Theory] - [InlineData("hello", "hello")] - [InlineData("?hello", "@hello")] - [InlineData("??hello", "@@hello")] - [InlineData("?? hello", "@@ hello")] - [InlineData("? ? hello", "@ @ hello")] - [InlineData(" ? ? hello", " @ @ hello")] - public void ReplaceOnTheBegining(string input, string expected) - { - var output = Helper.ReplaceAll(input, "?", x => "@"); - Assert.Equal(expected, output); - } - - [Theory] - [InlineData("hello?", "hello@")] - [InlineData("hello? ", "hello@ ")] - [InlineData("hello??? ", "hello@@@ ")] - [InlineData("hello ? ?? ? ", "hello @ @@ @ ")] - public void ReplaceOnTheEnd(string input, string expected) - { - var output = Helper.ReplaceAll(input, "?", x => "@"); - Assert.Equal(expected, output); - } - - [Theory] - [InlineData("hello?", "hello0")] - [InlineData("hello? ", "hello0 ")] - [InlineData("hello??? ", "hello012 ")] - [InlineData("hel?lo ? ?? ? ", "hel0lo 1 23 4 ")] - [InlineData("????", "0123")] - public void ReplaceWithPositions(string input, string expected) - { - var output = Helper.ReplaceAll(input, "?", x => x + ""); - Assert.Equal(expected, output); - } - - [Fact] - public void AllIndexesOf_ReturnIndexes_IfValueIsContainedInAString() - { - // Given - var input = "hello"; - - // When - var result = Helper.AllIndexesOf(input, "l"); - - // Then - Assert.Equal(new[] { 2, 3 }, result); - } - - [Theory] - [InlineData("")] - [InlineData(null)] - public void AllIndexesOf_ReturnEmptyCollection_IfValueIsEmptyOrNull(string value) - { - // Given - var input = "hello"; - - // When - var result = Helper.AllIndexesOf(input, value); - - // Then - Assert.Empty(result); - } - - [Fact] - public void AllIndexesOf_ReturnEmptyCollection_IfValueIsNotContainedInAString() - { - // Given - var input = "hello"; - - // When - var result = Helper.AllIndexesOf(input, "F"); - - // Then - Assert.Empty(result); - } - - [Fact] - public void Flatten_ReturnFlatttenDeepCollectionRecursively_IfArrayIsNested() - { - // Given - var objects = new object[] - { - 1, - 0.1, - 'A', - new object[] - { - 'A', - "B", - new object[] - { - "C", - 'D' - } - } - }; - - // When - var flatten = Helper.FlattenDeep(objects); - - // Then - Assert.Equal(new object[] { 1, 0.1, 'A', 'A', "B", "C", 'D' }, flatten); - } - - [Fact] - public void Flatten_FlatOneLevel() - { - // Given - var objects = new object[] - { - 1, - new object[] - { - 2, - 3, - new [] {4,5,6} - } - }; - - // When - var flatten = Helper.Flatten(objects); + var output = BindingExtensions.ReplaceAll(input, "any", x => x + ""); - // Then - Assert.Equal(new[] { 4, 5, 6 }, flatten.ElementAt(3)); - } - [Fact] - public void Flatten_ShouldRemoveEmptyCollections() - { - // Given - var objects = new object[] - { - 1, - new object[] {}, - new object[] - { - 2, - 3, - } - }; - - // When - var flatten = Helper.Flatten(objects); - - // Then - Assert.Equal(new object[] { 1, 2, 3 }, flatten); - } - - [Fact] - public void IsArray_ReturnFalse_IfValueIsNull() - { - // Given - IEnumerable test = null; - - // When - var isArray = Helper.IsArray(test); - - // Then - Assert.False(isArray); - } + Assert.Equal(input, output); + } - [Fact] - public void IsArray_ReturnFalse_IfTypeOfValueIsString() - { - // Given - var value = "string"; + [Theory] + [InlineData("hello", "hello")] + [InlineData("?hello", "@hello")] + [InlineData("??hello", "@@hello")] + [InlineData("?? hello", "@@ hello")] + [InlineData("? ? hello", "@ @ hello")] + [InlineData(" ? ? hello", " @ @ hello")] + public void ReplaceOnTheBeginning(string input, string expected) + { + var output = BindingExtensions.ReplaceAll(input, "?", _ => "@"); + Assert.Equal(expected, output); + } - // When - var isArray = Helper.IsArray(value); + [Theory] + [InlineData("hello?", "hello@")] + [InlineData("hello? ", "hello@ ")] + [InlineData("hello??? ", "hello@@@ ")] + [InlineData("hello ? ?? ? ", "hello @ @@ @ ")] + public void ReplaceOnTheEnd(string input, string expected) + { + var output = BindingExtensions.ReplaceAll(input, "?", _ => "@"); + Assert.Equal(expected, output); + } - // Then - Assert.False(isArray); - } + [Theory] + [InlineData("hello?", "hello0")] + [InlineData("hello? ", "hello0 ")] + [InlineData("hello??? ", "hello012 ")] + [InlineData("hel?lo ? ?? ? ", "hel0lo 1 23 4 ")] + [InlineData("????", "0123")] + public void ReplaceWithPositions(string input, string expected) + { + var output = BindingExtensions.ReplaceAll(input, "?", x => x + ""); + Assert.Equal(expected, output); + } - [Fact] - public void IsArray_ReturnTrue_IfValueIsExactlyIEnumerable() - { - // Given - var value = new object[] { 1, 'B', "C" }; + [Fact] + public void Flatten_FlatOneLevel() + { + // 3 levels + var objects = new object[] { 1, new object[] { 2, 3, new[] { 4, 5, 6 } } }; - // When - var isArray = Helper.IsArray(value); + // 2 levels + objects.FlattenOneLevel().Should().BeEquivalentTo( + new object[]{1, 2, 3, new[] { 4, 5, 6 }}); - // Then - Assert.True(isArray); - } + // 3 levels + objects.FlattenOneLevel().FlattenOneLevel().Should().BeEquivalentTo( + new []{1, 2, 3, 4, 5, 6 }); + } - [Theory] - [InlineData("Users.Id", "Users.Id")] - [InlineData("Users.{Id", "Users.{Id")] - [InlineData("Users.{Id}", "Users.Id")] - [InlineData("Users.{Id,Name}", "Users.Id, Users.Name")] - [InlineData("Users.{Id,Name, Last_Name }", "Users.Id, Users.Name, Users.Last_Name")] - public void ExpandExpression(string input, string expected) - { - Assert.Equal(expected, string.Join(", ", Helper.ExpandExpression(input))); - } + [Theory] + [InlineData("Users.Id", "Users.Id")] + [InlineData("Users.{Id", "Users.{Id")] + [InlineData("Users.{Id}", "Users.Id")] + [InlineData("Users.{Id,Name}", "Users.Id, Users.Name")] + [InlineData("Users.{Id,Name, Last_Name }", "Users.Id, Users.Name, Users.Last_Name")] + public void ExpandExpression(string input, string expected) + { + Assert.Equal(expected, string.Join(", ", Helper.ExpandExpression(input))); + } - [Fact] - public void ExpandParameters() - { - var expanded = Helper.ExpandParameters("where id = ? or id in (?) or id in (?)", "?", new object[] { 1, new[] { 1, 2 }, new object[] { } }); + [Fact] + public void ExpandParameters() + { + var expanded = BindingExtensions.ExpandParameters("where id = ? or id in (?) or id in (?)", "?", + new object[] { 1, new[] { 1, 2 }, new object[] { } }); - Assert.Equal("where id = ? or id in (?,?) or id in ()", expanded); - } + Assert.Equal("where id = ? or id in (?,?) or id in ()", expanded); + } - [Theory] - [InlineData(@"\{ text {", @"\", "{", "[", "{ text [")] - [InlineData(@"{ text {", @"\", "{", "[", "[ text [")] - public void WrapIdentifiers(string input, string escapeCharacter, string identifier, string newIdentifier, string expected) - { - var result = input.ReplaceIdentifierUnlessEscaped(escapeCharacter, identifier, newIdentifier); - Assert.Equal(expected, result); - } + [Theory] + [InlineData(@"\{ text {", @"\", "{", "[", "{ text [")] + [InlineData(@"{ text {", @"\", "{", "[", "[ text [")] + public void WrapIdentifiers(string input, string escapeCharacter, string identifier, string newIdentifier, + string expected) + { + var result = input.ReplaceIdentifierUnlessEscaped(escapeCharacter, identifier, newIdentifier); + Assert.Equal(expected, result); } } diff --git a/QueryBuilder.Tests/Infrastructure/TestCompiler.cs b/QueryBuilder.Tests/Infrastructure/TestCompiler.cs index aded9fd1..c3e4781e 100644 --- a/QueryBuilder.Tests/Infrastructure/TestCompiler.cs +++ b/QueryBuilder.Tests/Infrastructure/TestCompiler.cs @@ -1,58 +1,23 @@ -using System; -using System.Reflection; using SqlKata.Compilers; -namespace SqlKata.Tests.Infrastructure -{ - /// - /// A test class to expose private methods - /// - class TestCompiler : Compiler - { - public override string EngineCode { get; } = "test"; - - public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string methodName) - { - return FindCompilerMethodInfo(clauseType, methodName); - } - } - - class TestSqlServerCompiler : SqlServerCompiler - { - public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string methodName) - { - return FindCompilerMethodInfo(clauseType, methodName); - } - } - - class TestMySqlCompiler : MySqlCompiler - { - public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string methodName) - { - return FindCompilerMethodInfo(clauseType, methodName); - } - } +namespace SqlKata.Tests.Infrastructure; - class TestPostgresCompiler : PostgresCompiler +/// +/// A test class to expose private methods +/// +internal class TestCompiler : Compiler +{ + protected TestCompiler() { - public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string methodName) - { - return FindCompilerMethodInfo(clauseType, methodName); - } + EngineCode = "test"; } - class TestFirebirdCompiler : FirebirdCompiler - { - public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string methodName) - { - return FindCompilerMethodInfo(clauseType, methodName); - } - } +} - class TestEmptyIdentifiersCompiler : TestCompiler +internal class TestEmptyIdentifiersCompiler : TestCompiler +{ + public TestEmptyIdentifiersCompiler() { - protected override string OpeningIdentifier { get; set; } = ""; - protected override string ClosingIdentifier { get; set; } = ""; + XService = new X("", "", "AS "); } } - diff --git a/QueryBuilder.Tests/Infrastructure/TestCompilersContainer.cs b/QueryBuilder.Tests/Infrastructure/TestCompilersContainer.cs index 2312a192..ec06c3bb 100644 --- a/QueryBuilder.Tests/Infrastructure/TestCompilersContainer.cs +++ b/QueryBuilder.Tests/Infrastructure/TestCompilersContainer.cs @@ -1,109 +1,103 @@ -using System; -using System.Collections.Generic; -using System.Linq; using SqlKata.Compilers; -namespace SqlKata.Tests.Infrastructure +namespace SqlKata.Tests.Infrastructure; + +public class TestCompilersContainer { - public class TestCompilersContainer + private readonly IDictionary _compilers = new Dictionary { - private static class Messages + [EngineCodes.MySql] = new MySqlCompiler(), + [EngineCodes.Oracle] = new OracleCompiler(), + [EngineCodes.PostgreSql] = new PostgresCompiler(), + [EngineCodes.Sqlite] = new SqliteCompiler(), + [EngineCodes.SqlServer] = new SqlServerCompiler { - public const string ERR_INVALID_ENGINECODE = "Engine code '{0}' is not valid"; - public const string ERR_INVALID_ENGINECODES = "Invalid engine codes supplied '{0}'"; - } + UseLegacyPagination = true + }, + [EngineCodes.Firebird] = new FirebirdCompiler(), + }; - protected readonly IDictionary Compilers = new Dictionary - { - [EngineCodes.Firebird] = new FirebirdCompiler(), - [EngineCodes.MySql] = new MySqlCompiler(), - [EngineCodes.Oracle] = new OracleCompiler(), - [EngineCodes.PostgreSql] = new PostgresCompiler(), - [EngineCodes.Sqlite] = new SqliteCompiler(), - [EngineCodes.SqlServer] = new SqlServerCompiler() - { - UseLegacyPagination = true - } - }; + public ICollection KnownEngineCodes + { + get { return _compilers.Keys; } + } - public IEnumerable KnownEngineCodes - { - get { return Compilers.Select(s => s.Key); } - } + /// + /// Returns a instance for the given engine code + /// + /// + /// + public Compiler Get(string engineCode) + { + if (!_compilers.ContainsKey(engineCode)) + throw new InvalidOperationException(string.Format(Messages.ErrInvalidEngineCode, engineCode)); - /// - /// Returns a instance for the given engine code - /// - /// - /// - public Compiler Get(string engineCode) - { - if (!Compilers.ContainsKey(engineCode)) - { - throw new InvalidOperationException(string.Format(Messages.ERR_INVALID_ENGINECODE, engineCode)); - } + return _compilers[engineCode]; + } - return Compilers[engineCode]; - } + /// + /// Convenience method + /// + /// Does not validate generic type against engine code before cast + /// + /// + /// + public TCompiler Get(string engineCode) where TCompiler : Compiler + { + return (TCompiler)Get(engineCode); + } - /// - /// Convenience method - /// - /// Does not validate generic type against engine code before cast - /// - /// - /// - public TCompiler Get(string engineCode) where TCompiler : Compiler - { - return (TCompiler)Get(engineCode); - } + /// + /// Compiles the against the given engine code + /// + /// + /// + /// + public SqlResult CompileFor(string engineCode, Query query) + { + var compiler = Get(engineCode); + return compiler.Compile(query); + } - /// - /// Compiles the against the given engine code - /// - /// - /// - /// - public SqlResult CompileFor(string engineCode, Query query) - { - var compiler = Get(engineCode); - return compiler.Compile(query); - } + /// + /// Compiles the against the given engine codes + /// + /// + /// + /// + public TestSqlResultContainer Compile(IEnumerable engineCodes, Query query) + { + var codes = engineCodes.ToList(); - /// - /// Compiles the against the given engine codes - /// - /// - /// - /// - public TestSqlResultContainer Compile(IEnumerable engineCodes, Query query) - { - var codes = engineCodes.ToList(); + var results = _compilers + .Where(w => codes.Contains(w.Key)) + .ToDictionary(k => k.Key, v => v.Value.Compile(query.Clone())); - var results = Compilers - .Where(w => codes.Contains(w.Key)) - .ToDictionary(k => k.Key, v => v.Value.Compile(query.Clone())); + if (results.Count != codes.Count) + { + var missingCodes = codes.Where(w => _compilers.All(a => a.Key != w)); + var templateArg = string.Join(", ", missingCodes); + throw new InvalidOperationException(string.Format(Messages.ErrInvalidEngineCodes, templateArg)); + } - if (results.Count != codes.Count) - { - var missingCodes = codes.Where(w => Compilers.All(a => a.Key != w)); - var templateArg = string.Join(", ", missingCodes); - throw new InvalidOperationException(string.Format(Messages.ERR_INVALID_ENGINECODES, templateArg)); - } + return new TestSqlResultContainer(results); + } - return new TestSqlResultContainer(results); - } + /// + /// Compiles the against all s + /// + /// + /// + public TestSqlResultContainer Compile(Query query) + { + var resultKeyValues = _compilers + .ToDictionary(k => k.Key, v => v.Value.Compile(query.Clone())); + return new TestSqlResultContainer(resultKeyValues); + } - /// - /// Compiles the against all s - /// - /// - /// - public TestSqlResultContainer Compile(Query query) - { - var resultKeyValues = Compilers - .ToDictionary(k => k.Key, v => v.Value.Compile(query.Clone())); - return new TestSqlResultContainer(resultKeyValues); - } + private static class Messages + { + public const string ErrInvalidEngineCode = "Engine code '{0}' is not valid"; + public const string ErrInvalidEngineCodes = "Invalid engine codes supplied '{0}'"; } } diff --git a/QueryBuilder.Tests/Infrastructure/TestSqlResultContainer.cs b/QueryBuilder.Tests/Infrastructure/TestSqlResultContainer.cs index 16a5eeff..fc505f93 100644 --- a/QueryBuilder.Tests/Infrastructure/TestSqlResultContainer.cs +++ b/QueryBuilder.Tests/Infrastructure/TestSqlResultContainer.cs @@ -1,13 +1,10 @@ -using System.Collections.Generic; using System.Collections.ObjectModel; -namespace SqlKata.Tests.Infrastructure +namespace SqlKata.Tests.Infrastructure; + +public class TestSqlResultContainer : ReadOnlyDictionary { - public class TestSqlResultContainer : ReadOnlyDictionary + public TestSqlResultContainer(IDictionary dictionary) : base(dictionary) { - public TestSqlResultContainer(IDictionary dictionary) : base(dictionary) - { - - } } } diff --git a/QueryBuilder.Tests/Infrastructure/TestSupport.cs b/QueryBuilder.Tests/Infrastructure/TestSupport.cs index 78d912cc..4a8ba8a4 100644 --- a/QueryBuilder.Tests/Infrastructure/TestSupport.cs +++ b/QueryBuilder.Tests/Infrastructure/TestSupport.cs @@ -1,20 +1,19 @@ -using System.Collections.Generic; -using System.Linq; +namespace SqlKata.Tests.Infrastructure; -namespace SqlKata.Tests.Infrastructure +public abstract class TestSupport { - public abstract class TestSupport - { - protected readonly TestCompilersContainer Compilers = new TestCompilersContainer(); + protected readonly TestCompilersContainer Compilers = new(); - /// - /// For legacy test support - /// - /// - /// - protected IReadOnlyDictionary Compile(Query query) - { - return Compilers.Compile(query).ToDictionary(s => s.Key, v => v.Value.ToString()); - } + /// + /// For legacy test support + /// + /// + /// + protected IReadOnlyDictionary Compile(Query query) + { + return Compilers.Compile(query) + .ToDictionary( + s => s.Key, + v => v.Value.ToString()!); } } diff --git a/QueryBuilder.Tests/InfrastructureTests.cs b/QueryBuilder.Tests/InfrastructureTests.cs index 5bb7f2df..4d063b61 100644 --- a/QueryBuilder.Tests/InfrastructureTests.cs +++ b/QueryBuilder.Tests/InfrastructureTests.cs @@ -1,54 +1,50 @@ -using System; -using System.Linq; using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class InfrastructureTests : TestSupport { - public class InfrastructureTests : TestSupport + [Fact] + public void CanGetCompiler() + { + var compiler = Compilers.Get(EngineCodes.SqlServer); + + Assert.NotNull(compiler); + Assert.IsType(compiler); + } + + [Fact] + public void CanCompile() + { + var results = Compilers.Compile(new Query("Table")); + + Assert.NotNull(results); + Assert.Equal(Compilers.KnownEngineCodes.Count(), results.Count); + } + + [Fact] + public void CanCompileSelectively() + { + var desiredEngines = new[] { EngineCodes.SqlServer, EngineCodes.MySql }; + var results = Compilers.Compile(desiredEngines, new Query("Table")); + + Assert.Equal(desiredEngines.Length, results.Count); + Assert.Contains(results, a => a.Key == EngineCodes.SqlServer); + Assert.Contains(results, a => a.Key == EngineCodes.MySql); + } + + + [Fact] + public void ShouldThrowIfInvalidEngineCode() + { + Assert.Throws(() => Compilers.CompileFor("XYZ", new Query())); + } + + [Fact] + public void ShouldThrowIfAnyEngineCodesAreInvalid() { - [Fact] - public void CanGetCompiler() - { - var compiler = Compilers.Get(EngineCodes.SqlServer); - - Assert.NotNull(compiler); - Assert.IsType(compiler); - } - - [Fact] - public void CanCompile() - { - var results = Compilers.Compile(new Query("Table")); - - Assert.NotNull(results); - Assert.Equal(Compilers.KnownEngineCodes.Count(), results.Count); - } - - [Fact] - public void CanCompileSelectively() - { - var desiredEngines = new[] { EngineCodes.SqlServer, EngineCodes.MySql }; - var results = Compilers.Compile(desiredEngines, new Query("Table")); - - Assert.Equal(desiredEngines.Length, results.Count); - Assert.Contains(results, a => a.Key == EngineCodes.SqlServer); - Assert.Contains(results, a => a.Key == EngineCodes.MySql); - } - - - [Fact] - public void ShouldThrowIfInvalidEngineCode() - { - Assert.Throws(() => Compilers.CompileFor("XYZ", new Query())); - } - - [Fact] - public void ShouldThrowIfAnyEngineCodesAreInvalid() - { - var codes = new[] { EngineCodes.SqlServer, "123", EngineCodes.MySql, "abc" }; - Assert.Throws(() => Compilers.Compile(codes, new Query())); - } + var codes = new[] { EngineCodes.SqlServer, "123", EngineCodes.MySql, "abc" }; + Assert.Throws(() => Compilers.Compile(codes, new Query())); } } diff --git a/QueryBuilder.Tests/InsertTests.cs b/QueryBuilder.Tests/InsertTests.cs index 926e18b2..806be441 100644 --- a/QueryBuilder.Tests/InsertTests.cs +++ b/QueryBuilder.Tests/InsertTests.cs @@ -1,308 +1,322 @@ -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Dynamic; -using System.Linq; +using JetBrains.Annotations; using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class InsertTests : TestSupport { - public class InsertTests : TestSupport + [Fact] + public void InsertObject() { - private class Account - { - public Account(string name, string currency = null, string created_at = null, string color = null) - { - this.name = name ?? throw new ArgumentNullException(nameof(name)); - this.Currency = currency; - this.color = color; - } + var query = new Query("Table") + .AsInsert( + new + { + Name = "The User", + Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) + }); - public string name { get; set; } + var c = Compile(query); - [Column("currency_id")] - public string Currency { get; set; } + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); - [Ignore] - public string color { get; set; } - } + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } - [Fact] - public void InsertObject() - { - var query = new Query("Table") - .AsInsert( - new - { - Name = "The User", - Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc), - }); - - var c = Compile(query); - - Assert.Equal( - "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); - - Assert.Equal( - "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", - c[EngineCodes.Firebird]); - } + [Fact] + public void InsertFromSubQueryWithCte() + { + var query = new Query("expensive_cars") + .With("old_cards", new Query("all_cars").Where("year", "<", 2000)) + .AsInsert( + new[] { "name", "model", "year" }, + new Query("old_cars").Where("price", ">", 100).ForPage(2, 10)); - [Fact] - public void InsertFromSubQueryWithCte() - { - var query = new Query("expensive_cars") - .With("old_cards", new Query("all_cars").Where("year", "<", 2000)) - .AsInsert( - new[] { "name", "model", "year" }, - new Query("old_cars").Where("price", ">", 100).ForPage(2, 10)); + var c = Compile(query); - var c = Compile(query); + Assert.Equal( + "WITH [old_cards] AS (SELECT * FROM [all_cars] WHERE [year] < 2000)\nINSERT INTO [expensive_cars] ([name], [model], [year]) SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [old_cars] WHERE [price] > 100) AS [results_wrapper] WHERE [row_num] BETWEEN 11 AND 20", + c[EngineCodes.SqlServer]); - Assert.Equal( - "WITH [old_cards] AS (SELECT * FROM [all_cars] WHERE [year] < 2000)\nINSERT INTO [expensive_cars] ([name], [model], [year]) SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [old_cars] WHERE [price] > 100) AS [results_wrapper] WHERE [row_num] BETWEEN 11 AND 20", - c[EngineCodes.SqlServer]); + Assert.Equal( + "WITH `old_cards` AS (SELECT * FROM `all_cars` WHERE `year` < 2000)\nINSERT INTO `expensive_cars` (`name`, `model`, `year`) SELECT * FROM `old_cars` WHERE `price` > 100 LIMIT 10 OFFSET 10", + c[EngineCodes.MySql]); - Assert.Equal( - "WITH `old_cards` AS (SELECT * FROM `all_cars` WHERE `year` < 2000)\nINSERT INTO `expensive_cars` (`name`, `model`, `year`) SELECT * FROM `old_cars` WHERE `price` > 100 LIMIT 10 OFFSET 10", - c[EngineCodes.MySql]); + Assert.Equal( + "WITH \"old_cards\" AS (SELECT * FROM \"all_cars\" WHERE \"year\" < 2000)\nINSERT INTO \"expensive_cars\" (\"name\", \"model\", \"year\") SELECT * FROM \"old_cars\" WHERE \"price\" > 100 LIMIT 10 OFFSET 10", + c[EngineCodes.PostgreSql]); + } - Assert.Equal( - "WITH \"old_cards\" AS (SELECT * FROM \"all_cars\" WHERE \"year\" < 2000)\nINSERT INTO \"expensive_cars\" (\"name\", \"model\", \"year\") SELECT * FROM \"old_cars\" WHERE \"price\" > 100 LIMIT 10 OFFSET 10", - c[EngineCodes.PostgreSql]); - } + [Fact] + public void InsertMultiRecords() + { + var query = new Query("expensive_cars") + .AsInsert( + new[] { "name", "brand", "year" }, + new[] + { + new object?[] { "Chiron", "Bugatti", null }, + new object?[] { "Huayra", "Pagani", 2012 }, + new object?[] { "Reventon roadster", "Lamborghini", 2009 } + }); - [Fact] - public void InsertMultiRecords() - { - var query = new Query("expensive_cars") - .AsInsert( - new[] { "name", "brand", "year" }, - new[] - { - new object[] { "Chiron", "Bugatti", null }, - new object[] { "Huayra", "Pagani", 2012 }, - new object[] { "Reventon roadster", "Lamborghini", 2009 } - }); - - var c = Compile(query); - - Assert.Equal( - "INSERT INTO [expensive_cars] ([name], [brand], [year]) VALUES ('Chiron', 'Bugatti', NULL), ('Huayra', 'Pagani', 2012), ('Reventon roadster', 'Lamborghini', 2009)", - c[EngineCodes.SqlServer]); - - Assert.Equal( - "INSERT INTO \"EXPENSIVE_CARS\" (\"NAME\", \"BRAND\", \"YEAR\") SELECT 'Chiron', 'Bugatti', NULL FROM RDB$DATABASE UNION ALL SELECT 'Huayra', 'Pagani', 2012 FROM RDB$DATABASE UNION ALL SELECT 'Reventon roadster', 'Lamborghini', 2009 FROM RDB$DATABASE", - c[EngineCodes.Firebird]); - } + var c = Compile(query); - [Fact] - public void InsertWithNullValues() - { - var query = new Query("Books") - .AsInsert( - new[] { "Id", "Author", "ISBN", "Date" }, - new object[] { 1, "Author 1", "123456", null }); + Assert.Equal( + "INSERT INTO [expensive_cars] ([name], [brand], [year]) VALUES ('Chiron', 'Bugatti', NULL), ('Huayra', 'Pagani', 2012), ('Reventon roadster', 'Lamborghini', 2009)", + c[EngineCodes.SqlServer]); - var c = Compile(query); + Assert.Equal( + "INSERT INTO \"EXPENSIVE_CARS\" (\"NAME\", \"BRAND\", \"YEAR\") SELECT 'Chiron', 'Bugatti', NULL FROM RDB$DATABASE UNION ALL SELECT 'Huayra', 'Pagani', 2012 FROM RDB$DATABASE UNION ALL SELECT 'Reventon roadster', 'Lamborghini', 2009 FROM RDB$DATABASE", + c[EngineCodes.Firebird]); + } - Assert.Equal("INSERT INTO [Books] ([Id], [Author], [ISBN], [Date]) VALUES (1, 'Author 1', '123456', NULL)", - c[EngineCodes.SqlServer]); + [Fact] + public void InsertWithNullValues() + { + var query = new Query("Books") + .AsInsert( + new[] { "Id", "Author", "ISBN", "Date" }, + new object?[] { 1, "Author 1", "123456", null }); + var c = Compile(query); - Assert.Equal( - "INSERT INTO \"BOOKS\" (\"ID\", \"AUTHOR\", \"ISBN\", \"DATE\") VALUES (1, 'Author 1', '123456', NULL)", - c[EngineCodes.Firebird]); - } + Assert.Equal("INSERT INTO [Books] ([Id], [Author], [ISBN], [Date]) VALUES (1, 'Author 1', '123456', NULL)", + c[EngineCodes.SqlServer]); - [Fact] - public void InsertWithEmptyString() - { - var query = new Query("Books") - .AsInsert( - new[] { "Id", "Author", "ISBN", "Description" }, - new object[] { 1, "Author 1", "123456", "" }); - var c = Compile(query); + Assert.Equal( + "INSERT INTO \"BOOKS\" (\"ID\", \"AUTHOR\", \"ISBN\", \"DATE\") VALUES (1, 'Author 1', '123456', NULL)", + c[EngineCodes.Firebird]); + } - Assert.Equal( - "INSERT INTO [Books] ([Id], [Author], [ISBN], [Description]) VALUES (1, 'Author 1', '123456', '')", - c[EngineCodes.SqlServer]); + [Fact] + public void InsertWithEmptyString() + { + var query = new Query("Books") + .AsInsert( + new[] { "Id", "Author", "ISBN", "Description" }, + new object[] { 1, "Author 1", "123456", "" }); + var c = Compile(query); - Assert.Equal( - "INSERT INTO \"BOOKS\" (\"ID\", \"AUTHOR\", \"ISBN\", \"DESCRIPTION\") VALUES (1, 'Author 1', '123456', '')", - c[EngineCodes.Firebird]); - } + Assert.Equal( + "INSERT INTO [Books] ([Id], [Author], [ISBN], [Description]) VALUES (1, 'Author 1', '123456', '')", + c[EngineCodes.SqlServer]); - [Fact] - public void InsertWithByteArray() - { - var fauxImagebytes = new byte[] { 0x1, 0x3, 0x3, 0x7 }; - var query = new Query("Books") - .AsInsert( - new[] { "Id", "CoverImageBytes" }, - new object[] - { - 1, - fauxImagebytes - }); - - var c = Compilers.Compile(query); - Assert.All(c.Values, a => Assert.Equal(2, a.NamedBindings.Count)); - - var exemplar = c[EngineCodes.SqlServer]; - - Assert.Equal("INSERT INTO [Books] ([Id], [CoverImageBytes]) VALUES (?, ?)", exemplar.RawSql); - Assert.Equal("INSERT INTO [Books] ([Id], [CoverImageBytes]) VALUES (@p0, @p1)", exemplar.Sql); - } - [Fact] - public void InsertWithIgnoreAndColumnProperties() - { - var account = new Account(name: $"popular", color: $"blue", currency: "US"); - var query = new Query("Account").AsInsert(account); + Assert.Equal( + "INSERT INTO \"BOOKS\" (\"ID\", \"AUTHOR\", \"ISBN\", \"DESCRIPTION\") VALUES (1, 'Author 1', '123456', '')", + c[EngineCodes.Firebird]); + } + + [Fact] + public void InsertWithByteArray() + { + var fauxImagebytes = new byte[] { 0x1, 0x3, 0x3, 0x7 }; + var query = new Query("Books") + .AsInsert( + new[] { "Id", "CoverImageBytes" }, + new object[] + { + 1, + fauxImagebytes + }); - var c = Compile(query); + var c = Compilers.Compile(query); + Assert.All(c.Values, a => Assert.Equal(2, a.NamedBindings.Count)); - Assert.Equal( - "INSERT INTO [Account] ([name], [currency_id]) VALUES ('popular', 'US')", - c[EngineCodes.SqlServer]); + var exemplar = c[EngineCodes.SqlServer]; - Assert.Equal( - "INSERT INTO \"ACCOUNT\" (\"NAME\", \"CURRENCY_ID\") VALUES ('popular', 'US')", - c[EngineCodes.Firebird]); - } + Assert.Equal("INSERT INTO [Books] ([Id], [CoverImageBytes]) VALUES (?, ?)", exemplar.RawSql); + Assert.Equal("INSERT INTO [Books] ([Id], [CoverImageBytes]) VALUES (@p0, @p1)", exemplar.Sql); + } - [Fact] - public void InsertFromRaw() - { - var query = new Query() - .FromRaw("Table.With.Dots") - .AsInsert( - new - { - Name = "The User", - Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc), - }); - - var c = Compile(query); - - Assert.Equal( - "INSERT INTO Table.With.Dots ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); - } + [Fact] + public void InsertWithIgnoreAndColumnProperties() + { + var account = new Account("popular", color: "blue", currency: "US"); + var query = new Query("Account").AsInsert(account); - [Fact] - public void InsertFromQueryShouldFail() - { - var query = new Query() - .From(new Query("InnerTable")) - .AsInsert( - new - { - Name = "The User", - Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc), - }); - - Assert.Throws(() => - { - Compile(query); - }); - } + var c = Compile(query); - [Fact] - public void InsertKeyValuePairs() - { - var dictionaryUser = new Dictionary + Assert.Equal( + "INSERT INTO [Account] ([Name], [currency_id]) VALUES ('popular', 'US')", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "INSERT INTO \"ACCOUNT\" (\"NAME\", \"CURRENCY_ID\") VALUES ('popular', 'US')", + c[EngineCodes.Firebird]); + } + + [Fact] + public void InsertFromRaw() + { + var query = new Query() + .FromRaw("Table.With.Dots") + .AsInsert( + new { - { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - } - .ToArray(); + Name = "The User", + Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) + }); - var query = new Query("Table") - .AsInsert(dictionaryUser); + var c = Compile(query); - var c = Compile(query); + Assert.Equal( + "INSERT INTO Table.With.Dots ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); + } - Assert.Equal( - "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); + [Fact] + public void InsertFromQueryShouldFail() + { + var query = new Query() + .From(new Query("InnerTable")) + .AsInsert( + new + { + Name = "The User", + Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) + }); - Assert.Equal( - "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", - c[EngineCodes.Firebird]); - } + Assert.Throws(() => { Compile(query); }); + } - [Fact] - public void InsertDictionary() - { - var dictionaryUser = new Dictionary { + [Fact] + public void InsertKeyValuePairs() + { + var dictionaryUser = new Dictionary + { { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - }; + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } + } + .ToArray(); - var query = new Query("Table") - .AsInsert(dictionaryUser); + var query = new Query("Table") + .AsInsert(dictionaryUser); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); - Assert.Equal( - "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", - c[EngineCodes.Firebird]); - } + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } - [Fact] - public void InsertReadOnlyDictionary() + [Fact] + public void InsertDictionary() + { + var dictionaryUser = new Dictionary { - var dictionaryUser = new ReadOnlyDictionary( - new Dictionary - { - { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - }); + { "Name", "The User" }, + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } + }; - var query = new Query("Table") - .AsInsert(dictionaryUser); + var query = new Query("Table") + .AsInsert(dictionaryUser); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); - Assert.Equal( - "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", - c[EngineCodes.Firebird]); - } + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } - [Fact] - public void InsertExpandoObject() + [Fact] + public void InsertReadOnlyDictionary() + { + var dictionaryUser = new ReadOnlyDictionary( + new Dictionary + { + { "Name", "The User" }, + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } + }); + + var query = new Query("Table") + .AsInsert(dictionaryUser); + + var c = Compile(query); + + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } + + [Fact] + public void InsertExpandoObject() + { + dynamic expandoUser = new ExpandoObject(); + expandoUser.Name = "The User"; + expandoUser.Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); + + var query = new Query("Table") + .AsInsert(expandoUser); + + var c = Compile(query); + + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } + [Fact] + public void InsertAnonymousObject() + { + var expandoUser = new { - dynamic expandoUser = new ExpandoObject(); - expandoUser.Name = "The User"; - expandoUser.Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); + Name = "The User", + Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) + }; - var query = new Query("Table") - .AsInsert(expandoUser); + var query = new Query("Table") + .AsInsert(expandoUser); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", - c[EngineCodes.SqlServer]); + Assert.Equal( + "INSERT INTO [Table] ([Name], [Age]) VALUES ('The User', '2018-01-01')", + c[EngineCodes.SqlServer]); - Assert.Equal( - "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", - c[EngineCodes.Firebird]); + Assert.Equal( + "INSERT INTO \"TABLE\" (\"NAME\", \"AGE\") VALUES ('The User', '2018-01-01')", + c[EngineCodes.Firebird]); + } + [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] + private class Account + { + public Account(string name, string? currency = null, string? color = null) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Currency = currency; + Color = color; } + + public string Name { get; set; } + + [Column("currency_id")] public string? Currency { get; set; } + + [Ignore] public string? Color { get; set; } } } diff --git a/QueryBuilder.Tests/MySql/MySqlLimitTests.cs b/QueryBuilder.Tests/MySql/MySqlLimitTests.cs index 074c5ad8..50bf7bea 100644 --- a/QueryBuilder.Tests/MySql/MySqlLimitTests.cs +++ b/QueryBuilder.Tests/MySql/MySqlLimitTests.cs @@ -1,58 +1,43 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.MySql -{ - public class MySqlLimitTests : TestSupport - { - private readonly MySqlCompiler compiler; - - public MySqlLimitTests() - { - compiler = Compilers.Get(EngineCodes.MySql); - } - - [Fact] - public void WithNoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; +namespace SqlKata.Tests.MySql; - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void WithNoOffset() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; - - Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx)); - Assert.Equal(10, ctx.Bindings[0]); - } +public sealed class MySqlLimitTests +{ + private readonly MySqlCompiler _compiler = new(); - [Fact] - public void WithNoLimit() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM `Table`"); + } - Assert.Equal("LIMIT 18446744073709551615 OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } + [Fact] + public void WithNoOffset() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM `Table` LIMIT 10 + """); + } - [Fact] - public void WithLimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimit() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM `Table` LIMIT 18446744073709551615 OFFSET 20"); + } - Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(5, ctx.Bindings[0]); - Assert.Equal(20L, ctx.Bindings[1]); - Assert.Equal(2, ctx.Bindings.Count); - } + [Fact] + public void WithLimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM `Table` LIMIT 5 OFFSET 20"); } } diff --git a/QueryBuilder.Tests/MySqlExecutionTest.cs b/QueryBuilder.Tests/MySqlExecutionTest.cs index 07df93c8..20765269 100644 --- a/QueryBuilder.Tests/MySqlExecutionTest.cs +++ b/QueryBuilder.Tests/MySqlExecutionTest.cs @@ -1,269 +1,264 @@ +using MySql.Data.MySqlClient; using SqlKata.Compilers; -using Xunit; using SqlKata.Execution; -using MySql.Data.MySqlClient; -using System; -using System.Linq; using static SqlKata.Expressions; -using System.Collections.Generic; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +[Collection("Sequential")] +public class MySqlExecutionTest { - public class MySqlExecutionTest + [Fact] + public void EmptySelect() { - [Fact] - public void EmptySelect() + var db = Db().Create("Cars", new[] { + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - var db = DB().Create("Cars", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + var rows = db.Query("Cars").Get(); - var rows = db.Query("Cars").Get(); + Assert.Empty(rows); - Assert.Empty(rows); - - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void SelectWithLimit() + [Fact] + public void SelectWithLimit() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); - var rows = db.Query("Cars").Get().ToList(); + var rows = db.Query("Cars").Get().ToList(); - Assert.Single(rows); + Assert.Single(rows); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void Count() + [Fact] + public void Count() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); - var count = db.Query("Cars").Count(); - Assert.Equal(1, count); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); + var count = db.Query("Cars").Count(); + Assert.Equal(1, count); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Toyota', 2021)"); - count = db.Query("Cars").Count(); - Assert.Equal(2, count); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Toyota', 2021)"); + count = db.Query("Cars").Count(); + Assert.Equal(2, count); - int affected = db.Query("Cars").Delete(); - Assert.Equal(2, affected); + var affected = db.Query("Cars").Delete(); + Assert.Equal(2, affected); - count = db.Query("Cars").Count(); - Assert.Equal(0, count); + count = db.Query("Cars").Count(); + Assert.Equal(0, count); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void CloneThenCount() + [Fact] + public void CloneThenCount() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); - - for (int i = 0; i < 10; i++) + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); + + for (var i = 0; i < 10; i++) + db.Query("Cars").Insert(new { - db.Query("Cars").Insert(new - { - Brand = "Brand " + i, - Year = "2020", - }); - } + Brand = "Brand " + i, + Year = "2020" + }); - var query = db.Query("Cars").Where("Id", "<", 5); - var count = query.Count(); - var cloneCount = query.Clone().Count(); + var query = db.Query("Cars").Where("Id", "<", 5); + var count = query.Count(); + var cloneCount = query.Clone().Count(); - Assert.Equal(4, count); - Assert.Equal(4, cloneCount); + Assert.Equal(4, count); + Assert.Equal(4, cloneCount); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void QueryWithVariable() + [Fact] + public void QueryWithVariable() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); - - for (int i = 0; i < 10; i++) + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); + + for (var i = 0; i < 10; i++) + db.Query("Cars").Insert(new { - db.Query("Cars").Insert(new - { - Brand = "Brand " + i, - Year = "2020", - }); - } + Brand = "Brand " + i, + Year = "2020" + }); - var count = db.Query("Cars") - .Define("Threshold", 5) - .Where("Id", "<", SqlKata.Expressions.Variable("Threshold")) - .Count(); + var count = db.Query("Cars") + .Define("Threshold", 5) + .Where("Id", "<", Variable("Threshold")) + .Count(); - Assert.Equal(4, count); + Assert.Equal(4, count); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void InlineTable() + [Fact] + public void InlineTable() + { + var db = Db().Create("Transaction", new[] { - var db = DB().Create("Transaction", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Amount int NOT NULL", - "Date DATE NOT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Amount int NOT NULL", + "Date DATE NOT NULL" + }); - db.Query("Transaction").Insert(new - { - Date = "2022-01-01", - Amount = 10 - }); + db.Query("Transaction").Insert(new + { + Date = "2022-01-01", + Amount = 10 + }); - var rows = db.Query("Transaction") - .With("Rates", new[] { "Date", "Rate" }, new object[][] { - new object[] {"2022-01-01", 0.5}, - }) - .Join("Rates", "Rates.Date", "Transaction.Date") - .SelectRaw("Transaction.Amount * Rates.Rate as AmountConverted") - .Get(); + var rows = db.Query("Transaction") + .With("Rates", new[] { "Date", "Rate" }, new[] + { + new object[] { "2022-01-01", 0.5 } + }) + .Join("Rates", "Rates.Date", "Transaction.Date") + .SelectRaw("Transaction.Amount * Rates.Rate as AmountConverted") + .Get(); - Assert.Single(rows); - Assert.Equal(5, rows.First().AmountConverted); + Assert.Equal(5, rows.First().AmountConverted); - db.Drop("Transaction"); - } + db.Drop("Transaction"); + } - [Fact] - public void ExistsShouldReturnFalseForEmptyTable() + [Fact] + public void ExistsShouldReturnFalseForEmptyTable() + { + var db = Db().Create("Transaction", new[] { - var db = DB().Create("Transaction", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Amount int NOT NULL", - "Date DATE NOT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Amount int NOT NULL", + "Date DATE NOT NULL" + }); - var exists = db.Query("Transaction").Exists(); - Assert.Equal(false, exists); + Assert.False(db.Query("Transaction").Exists()); - db.Drop("Transaction"); - } + db.Drop("Transaction"); + } - [Fact] - public void ExistsShouldReturnTrueForNonEmptyTable() + [Fact] + public void ExistsShouldReturnTrueForNonEmptyTable() + { + var db = Db().Create("Transaction", new[] { - var db = DB().Create("Transaction", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Amount int NOT NULL", - "Date DATE NOT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Amount int NOT NULL", + "Date DATE NOT NULL" + }); - db.Query("Transaction").Insert(new - { - Date = "2022-01-01", - Amount = 10 - }); + db.Query("Transaction").Insert(new + { + Date = "2022-01-01", + Amount = 10 + }); - var exists = db.Query("Transaction").Exists(); - Assert.Equal(true, exists); + Assert.True(db.Query("Transaction").Exists()); - db.Drop("Transaction"); - } + db.Drop("Transaction"); + } - [Fact] - public void BasicSelectFilter() + [Fact] + public void BasicSelectFilter() + { + var db = Db().Create("Transaction", new[] { - var db = DB().Create("Transaction", new[] { - "Id INT PRIMARY KEY AUTO_INCREMENT", - "Date DATE NOT NULL", - "Amount int NOT NULL", - }); + "Id INT PRIMARY KEY AUTO_INCREMENT", + "Date DATE NOT NULL", + "Amount int NOT NULL" + }); - var data = new Dictionary { - // 2020 - {"2020-01-01", 10}, - {"2020-05-01", 20}, - - // 2021 - {"2021-01-01", 40}, - {"2021-02-01", 10}, - {"2021-04-01", -10}, - - // 2022 - {"2022-01-01", 80}, - {"2022-02-01", -30}, - {"2022-05-01", 50}, - }; - - foreach (var row in data) + var data = new Dictionary + { + // 2020 + { "2020-01-01", 10 }, + { "2020-05-01", 20 }, + + // 2021 + { "2021-01-01", 40 }, + { "2021-02-01", 10 }, + { "2021-04-01", -10 }, + + // 2022 + { "2022-01-01", 80 }, + { "2022-02-01", -30 }, + { "2022-05-01", 50 } + }; + + foreach (var row in data) + db.Query("Transaction").Insert(new { - db.Query("Transaction").Insert(new - { - Date = row.Key, - Amount = row.Value - }); - } - - var query = db.Query("Transaction") + Date = row.Key, + Amount = row.Value + }); + + var query = db.Query("Transaction") .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020)) .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021)) .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022)) - ; + ; - var results = query.Get().ToList(); - Assert.Single(results); - Assert.Equal(30, results[0].Total_2020); - Assert.Equal(40, results[0].Total_2021); - Assert.Equal(100, results[0].Total_2022); + var results = query.Get().ToList(); + Assert.Single(results); + Assert.Equal(30, results[0].Total_2020); + Assert.Equal(40, results[0].Total_2021); + Assert.Equal(100, results[0].Total_2022); - db.Drop("Transaction"); - } - - QueryFactory DB() - { - var host = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST"); - var user = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_USER"); - var dbName = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_DB"); - var cs = $"server={host};user={user};database={dbName}"; - - var connection = new MySqlConnection(cs); - - var db = new QueryFactory(connection, new MySqlCompiler()); + db.Drop("Transaction"); + } - return db; - } + private QueryFactory Db() + { + // var host = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST"); + // var user = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_USER"); + // var dbName = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_DB"); + // var cs = $"server={host};user={user};database={dbName}"; + var cs = "server=localhost;user=root;port=3306;password=mysql;database=kata"; + var connection = new MySqlConnection(cs); + var db = new QueryFactory(connection, new MySqlCompiler()); + return db; } -} \ No newline at end of file +} diff --git a/QueryBuilder.Tests/OperatorWhitelistTests.cs b/QueryBuilder.Tests/OperatorWhitelistTests.cs index 55c3aafc..30a21dd5 100644 --- a/QueryBuilder.Tests/OperatorWhitelistTests.cs +++ b/QueryBuilder.Tests/OperatorWhitelistTests.cs @@ -1,139 +1,130 @@ -using System; using SqlKata.Compilers; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class OperatorWhitelistTests { - public class OperatorWhitelistTests + [Theory] + [InlineData("!!")] + [InlineData("~!")] + [InlineData("*=")] + public void DenyInvalidOperatorsInWhere(string op) { + var compiler = new SqlServerCompiler(); - public OperatorWhitelistTests() + Assert.Throws(() => { + compiler.Compile(new Query("Table").Where("Id", op, 1)); + compiler.Compile(new Query("Table").OrWhere("Id", op, 1)); + compiler.Compile(new Query("Table").WhereNot("Id", op, 1)); + compiler.Compile(new Query("Table").OrWhereNot("Id", op, 1)); + + compiler.Compile(new Query("Table").WhereColumns("Col1", op, "Col2")); + compiler.Compile(new Query("Table").OrWhereColumns("Col1", op, "Col2")); + }); + } - } + [Theory] + [InlineData("!!")] + [InlineData("~!")] + [InlineData("*=")] + public void DenyInvalidOperatorsInHaving(string op) + { + var compiler = new SqlServerCompiler(); - [Theory] - [InlineData("!!")] - [InlineData("~!")] - [InlineData("*=")] - public void DenyInvalidOperatorsInWhere(string op) - { - var compiler = new SqlServerCompiler(); - - Assert.Throws(() => - { - compiler.Compile(new Query("Table").Where("Id", op, 1)); - compiler.Compile(new Query("Table").OrWhere("Id", op, 1)); - compiler.Compile(new Query("Table").WhereNot("Id", op, 1)); - compiler.Compile(new Query("Table").OrWhereNot("Id", op, 1)); - - compiler.Compile(new Query("Table").WhereColumns("Col1", op, "Col2")); - compiler.Compile(new Query("Table").OrWhereColumns("Col1", op, "Col2")); - }); - } - - [Theory] - [InlineData("!!")] - [InlineData("~!")] - [InlineData("*=")] - public void DenyInvalidOperatorsInHaving(string op) - { - var compiler = new SqlServerCompiler(); - - Assert.Throws(() => - { - compiler.Compile(new Query("Table").Having("Id", op, 1)); - compiler.Compile(new Query("Table").OrHaving("Id", op, 1)); - compiler.Compile(new Query("Table").HavingNot("Id", op, 1)); - compiler.Compile(new Query("Table").OrHavingNot("Id", op, 1)); - - compiler.Compile(new Query("Table").HavingColumns("Col1", op, "Col2")); - compiler.Compile(new Query("Table").OrHavingColumns("Col1", op, "Col2")); - }); - } - - - [Theory] - [InlineData("=")] - [InlineData("!=")] - [InlineData("ilike")] - public void AllowValidOperatorsInWhere(string op) - { - new Query("Table").Where("Id", op, 1); - new Query("Table").OrWhere("Id", op, 1); - new Query("Table").WhereNot("Id", op, 1); - new Query("Table").OrWhereNot("Id", op, 1); - - new Query("Table").WhereColumns("Col1", op, "Col2"); - new Query("Table").OrWhereColumns("Col1", op, "Col2"); - } - - [Theory] - [InlineData("=")] - [InlineData("!=")] - [InlineData("ilike")] - public void AllowValidOperatorsInHaving(string op) + Assert.Throws(() => { - new Query("Table").Having("Id", op, 1); - new Query("Table").OrHaving("Id", op, 1); - new Query("Table").HavingNot("Id", op, 1); - new Query("Table").OrHavingNot("Id", op, 1); - - new Query("Table").HavingColumns("Col1", op, "Col2"); - new Query("Table").OrHavingColumns("Col1", op, "Col2"); - } - - [Theory] - [InlineData("^")] - [InlineData("<<")] - [InlineData(">>")] - [InlineData("~")] - [InlineData("~*")] - [InlineData("!~")] - [InlineData("!~*")] - public void ShouldNotThrowAfterWhiteListing(string op) - { - var compiler = new SqlServerCompiler().Whitelist(op); + compiler.Compile(new Query("Table").Having("Id", op, 1)); + compiler.Compile(new Query("Table").OrHaving("Id", op, 1)); + compiler.Compile(new Query("Table").HavingNot("Id", op, 1)); + compiler.Compile(new Query("Table").OrHavingNot("Id", op, 1)); + + compiler.Compile(new Query("Table").HavingColumns("Col1", op, "Col2")); + compiler.Compile(new Query("Table").OrHavingColumns("Col1", op, "Col2")); + }); + } + + + [Theory] + [InlineData("=")] + [InlineData("!=")] + [InlineData("ilike")] + public void AllowValidOperatorsInWhere(string op) + { + new Query("Table").Where("Id", op, 1); + new Query("Table").OrWhere("Id", op, 1); + new Query("Table").WhereNot("Id", op, 1); + new Query("Table").OrWhereNot("Id", op, 1); + + new Query("Table").WhereColumns("Col1", op, "Col2"); + new Query("Table").OrWhereColumns("Col1", op, "Col2"); + } + + [Theory] + [InlineData("=")] + [InlineData("!=")] + [InlineData("ilike")] + public void AllowValidOperatorsInHaving(string op) + { + new Query("Table").Having("Id", op, 1); + new Query("Table").OrHaving("Id", op, 1); + new Query("Table").HavingNot("Id", op, 1); + new Query("Table").OrHavingNot("Id", op, 1); - var query = new Query("Table"); + new Query("Table").HavingColumns("Col1", op, "Col2"); + new Query("Table").OrHavingColumns("Col1", op, "Col2"); + } - compiler.Compile(query.Clone().Where("Id", op, 1)); - compiler.Compile(query.Clone().OrWhere("Id", op, 1)); - compiler.Compile(query.Clone().WhereNot("Id", op, 1)); - compiler.Compile(query.Clone().OrWhereNot("Id", op, 1)); + [Theory] + [InlineData("^")] + [InlineData("<<")] + [InlineData(">>")] + [InlineData("~")] + [InlineData("~*")] + [InlineData("!~")] + [InlineData("!~*")] + public void ShouldNotThrowAfterWhiteListing(string op) + { + var compiler = new SqlServerCompiler().Whitelist(op); - compiler.Compile(query.Clone().WhereColumns("Col1", op, "Col2")); - compiler.Compile(query.Clone().OrWhereColumns("Col1", op, "Col2")); + var query = new Query("Table"); - compiler.Compile(query.Clone().Having("Id", op, 1)); - compiler.Compile(query.Clone().OrHaving("Id", op, 1)); - compiler.Compile(query.Clone().HavingNot("Id", op, 1)); - compiler.Compile(query.Clone().OrHavingNot("Id", op, 1)); + compiler.Compile(query.Clone().Where("Id", op, 1)); + compiler.Compile(query.Clone().OrWhere("Id", op, 1)); + compiler.Compile(query.Clone().WhereNot("Id", op, 1)); + compiler.Compile(query.Clone().OrWhereNot("Id", op, 1)); - compiler.Compile(query.Clone().HavingColumns("Col1", op, "Col2")); - compiler.Compile(query.Clone().OrHavingColumns("Col1", op, "Col2")); - } + compiler.Compile(query.Clone().WhereColumns("Col1", op, "Col2")); + compiler.Compile(query.Clone().OrWhereColumns("Col1", op, "Col2")); - [Fact] - public void ShouldAllowWhiteListedOperatorsInNestedWhere() - { - var compiler = new SqlServerCompiler().Whitelist("!!"); + compiler.Compile(query.Clone().Having("Id", op, 1)); + compiler.Compile(query.Clone().OrHaving("Id", op, 1)); + compiler.Compile(query.Clone().HavingNot("Id", op, 1)); + compiler.Compile(query.Clone().OrHavingNot("Id", op, 1)); - var query = new Query("Table") - .Where(q => q.Where("A", "!!", "value")); + compiler.Compile(query.Clone().HavingColumns("Col1", op, "Col2")); + compiler.Compile(query.Clone().OrHavingColumns("Col1", op, "Col2")); + } - compiler.Compile(query); - } + [Fact] + public void ShouldAllowWhiteListedOperatorsInNestedWhere() + { + var compiler = new SqlServerCompiler().Whitelist("!!"); - [Fact] - public void ShouldNotConsiderWhereRawCondition() - { - var compiler = new SqlServerCompiler(); + var query = new Query("Table") + .Where(q => q.Where("A", "!!", "value")); - var query = new Query("Table") - .WhereRaw("Col !! value"); + compiler.Compile(query); + } + + [Fact] + public void ShouldNotConsiderWhereRawCondition() + { + var compiler = new SqlServerCompiler(); - } + var query = new Query("Table") + .WhereRaw("Col !! value"); + compiler.Compile(query); } } diff --git a/QueryBuilder.Tests/Oracle/OracleDateConditionTests.cs b/QueryBuilder.Tests/Oracle/OracleDateConditionTests.cs index 6407f5ca..c0419b11 100644 --- a/QueryBuilder.Tests/Oracle/OracleDateConditionTests.cs +++ b/QueryBuilder.Tests/Oracle/OracleDateConditionTests.cs @@ -1,223 +1,232 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Oracle +namespace SqlKata.Tests.Oracle; + +public class OracleDateConditionTests : TestSupport { - public class OracleDateConditionTests : TestSupport + private const string TableName = "Table"; + + private readonly OracleCompiler _compiler; + + public OracleDateConditionTests() + { + _compiler = Compilers.Get(EngineCodes.Oracle); + } + + [Fact] + public void SimpleWhereDateTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDate("STAMP", "=", "2018-04-01"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD')", + ctx.RawSql); + Assert.Equal("2018-04-01", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartDateTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("date", "STAMP", "=", "2018-04-01"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD')", + ctx.RawSql); + Assert.Equal("2018-04-01", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereTimeWithSecondsTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereTime("STAMP", "=", "19:01:10"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS')", + ctx.RawSql); + Assert.Equal("19:01:10", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartTimeWithSecondsTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("time", "STAMP", "=", "19:01:10"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS')", + ctx.RawSql); + Assert.Equal("19:01:10", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereTimeWithoutSecondsTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereTime("STAMP", "=", "19:01"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI'), 'HH24:MI:SS')", + ctx.RawSql); + Assert.Equal("19:01", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartTimeWithoutSecondsTest() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("time", "STAMP", "=", "19:01"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal( + $"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI'), 'HH24:MI:SS')", + ctx.RawSql); + Assert.Equal("19:01", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartYear() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("year", "STAMP", "=", "2018"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(YEAR FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("2018", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartMonth() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("month", "STAMP", "=", "9"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(MONTH FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("9", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartDay() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("day", "STAMP", "=", "15"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(DAY FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("15", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartHour() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("hour", "STAMP", "=", "15"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(HOUR FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("15", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartMinute() + { + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("minute", "STAMP", "=", "25"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(MINUTE FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("25", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); + } + + [Fact] + public void SimpleWhereDatePartSecond() { - private const string TableName = "Table"; - private const string SqlPlaceholder = "GENERATED_SQL"; - - private OracleCompiler compiler; - - public OracleDateConditionTests() - { - compiler = Compilers.Get(EngineCodes.Oracle); - } - - [Fact] - public void SimpleWhereDateTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDate("STAMP", "=", "2018-04-01"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD')", ctx.RawSql); - Assert.Equal("2018-04-01", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartDateTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("date", "STAMP", "=", "2018-04-01"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'YY-MM-DD') = TO_CHAR(TO_DATE(?, 'YY-MM-DD'), 'YY-MM-DD')", ctx.RawSql); - Assert.Equal("2018-04-01", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereTimeWithSecondsTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereTime("STAMP", "=", "19:01:10"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS')", ctx.RawSql); - Assert.Equal("19:01:10", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartTimeWithSecondsTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("time", "STAMP", "=", "19:01:10"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI:SS'), 'HH24:MI:SS')", ctx.RawSql); - Assert.Equal("19:01:10", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereTimeWithoutSecondsTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereTime("STAMP", "=", "19:01"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI'), 'HH24:MI:SS')", ctx.RawSql); - Assert.Equal("19:01", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartTimeWithoutSecondsTest() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("time", "STAMP", "=", "19:01"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE TO_CHAR(\"STAMP\", 'HH24:MI:SS') = TO_CHAR(TO_DATE(?, 'HH24:MI'), 'HH24:MI:SS')", ctx.RawSql); - Assert.Equal("19:01", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartYear() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("year", "STAMP", "=", "2018"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(YEAR FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("2018", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartMonth() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("month", "STAMP", "=", "9"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(MONTH FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("9", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartDay() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("day", "STAMP", "=", "15"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(DAY FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("15", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartHour() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("hour", "STAMP", "=", "15"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(HOUR FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("15", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartMinute() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("minute", "STAMP", "=", "25"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(MINUTE FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("25", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } - - [Fact] - public void SimpleWhereDatePartSecond() - { - // Arrange: - var query = new Query(TableName) - .Select() - .WhereDatePart("second", "STAMP", "=", "59"); - - // Act: - var ctx = compiler.Compile(query); - - // Assert: - Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(SECOND FROM \"STAMP\") = ?", ctx.RawSql); - Assert.Equal("59", ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } + // Arrange: + var query = new Query(TableName) + .Select() + .WhereDatePart("second", "STAMP", "=", "59"); + + // Act: + var ctx = _compiler.Compile(query); + + // Assert: + Assert.Equal($"SELECT * FROM \"{TableName}\" WHERE EXTRACT(SECOND FROM \"STAMP\") = ?", ctx.RawSql); + Assert.Equal("59", ctx.Bindings[0]); + Assert.Single(ctx.Bindings); } } diff --git a/QueryBuilder.Tests/Oracle/OracleInsertManyTests.cs b/QueryBuilder.Tests/Oracle/OracleInsertManyTests.cs index f25cf2ba..96b44d3e 100644 --- a/QueryBuilder.Tests/Oracle/OracleInsertManyTests.cs +++ b/QueryBuilder.Tests/Oracle/OracleInsertManyTests.cs @@ -1,61 +1,63 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Oracle +namespace SqlKata.Tests.Oracle; + +public class OracleInsertManyTests : TestSupport { - public class OracleInsertManyTests : TestSupport + private const string TableName = "Table"; + private readonly OracleCompiler _compiler; + + public OracleInsertManyTests() { - private const string TableName = "Table"; - private readonly OracleCompiler compiler; + _compiler = Compilers.Get(EngineCodes.Oracle); + } - public OracleInsertManyTests() - { - compiler = Compilers.Get(EngineCodes.Oracle); - } + [Fact] + public void InsertManyForOracle_ShouldRepeatColumnsAndAddSelectFromDual() + { + // Arrange: + var cols = new[] { "Name", "Price" }; - [Fact] - public void InsertManyForOracle_ShouldRepeatColumnsAndAddSelectFromDual() + var data = new[] { - // Arrange: - var cols = new[] { "Name", "Price" }; + new object[] { "A", 1000 }, + new object[] { "B", 2000 }, + new object[] { "C", 3000 } + }; - var data = new[] { - new object[] { "A", 1000 }, - new object[] { "B", 2000 }, - new object[] { "C", 3000 }, - }; + var query = new Query(TableName) + .AsInsert(cols, data); - var query = new Query(TableName) - .AsInsert(cols, data); + // Act: + var ctx = _compiler.Compile(query); - // Act: - var ctx = compiler.Compile(query); + // Assert: + Assert.Equal( + $@"INSERT ALL INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) SELECT 1 FROM DUAL", + ctx.RawSql); + } - // Assert: - Assert.Equal($@"INSERT ALL INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?) SELECT 1 FROM DUAL", ctx.RawSql); - } + [Fact] + public void InsertForOracle_SingleInsertShouldNotAddALLKeywordAndNotHaveSelectFromDual() + { + // Arrange: + var cols = new[] { "Name", "Price" }; - [Fact] - public void InsertForOracle_SingleInsertShouldNotAddALLKeywordAndNotHaveSelectFromDual() + var data = new[] { - // Arrange: - var cols = new[] { "Name", "Price" }; - - var data = new[] { - new object[] { "A", 1000 } - }; + new object[] { "A", 1000 } + }; - var query = new Query(TableName) - .AsInsert(cols, data); + var query = new Query(TableName) + .AsInsert(cols, data); - // Act: - var ctx = compiler.Compile(query); + // Act: + var ctx = _compiler.Compile(query); - // Assert: - Assert.Equal($@"INSERT INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?)", ctx.RawSql); - } + // Assert: + Assert.Equal($@"INSERT INTO ""{TableName}"" (""Name"", ""Price"") VALUES (?, ?)", ctx.RawSql); } } diff --git a/QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs b/QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs index 2b18769f..5760deb7 100644 --- a/QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs +++ b/QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs @@ -1,82 +1,54 @@ +using FluentAssertions; using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Oracle -{ - public class OracleLegacyLimitTests : TestSupport - { - private const string TableName = "Table"; - private const string SqlPlaceholder = "GENERATED_SQL"; - private readonly OracleCompiler compiler; - - public OracleLegacyLimitTests() - { - compiler = Compilers.Get(EngineCodes.Oracle); - compiler.UseLegacyPagination = true; - } - - [Fact] - public void WithNoLimitNorOffset() - { - // Arrange: - var query = new Query(TableName); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; - - // Act: - compiler.ApplyLegacyLimit(ctx); - - // Assert: - Assert.Equal(SqlPlaceholder, ctx.RawSql); - } - - [Fact] - public void WithNoOffset() - { - // Arrange: - var query = new Query(TableName).Limit(10); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; - - // Act: - compiler.ApplyLegacyLimit(ctx); - - // Assert: - Assert.Matches($"SELECT \\* FROM \\({SqlPlaceholder}\\) WHERE ROWNUM <= ?", ctx.RawSql); - Assert.Equal(10, ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } +namespace SqlKata.Tests.Oracle; - [Fact] - public void WithNoLimit() - { - // Arrange: - var query = new Query(TableName).Offset(20); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; - - // Act: - compiler.ApplyLegacyLimit(ctx); +public class OracleLegacyLimitTests : TestSupport +{ + private static readonly OracleCompiler OracleCompiler = new() { UseLegacyPagination = true }; - // Assert: - Assert.Equal("SELECT * FROM (SELECT \"results_wrapper\".*, ROWNUM \"row_num\" FROM (GENERATED_SQL) \"results_wrapper\") WHERE \"row_num\" > ?", ctx.RawSql); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } + [Fact] + public void WithNoLimitNorOffset() + { + var query = new Query("Table"); + OracleCompiler + .Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "Table" + """); + } - [Fact] - public void WithLimitAndOffset() - { - // Arrange: - var query = new Query(TableName).Limit(5).Offset(20); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; + [Fact] + public void WithNoOffset() + { + var query = new Query("Table").Limit(10); + OracleCompiler + .Compile(query).ToString().Should() + .Be(""" + SELECT * FROM (SELECT * FROM "Table") WHERE ROWNUM <= 10 + """); + } - // Act: - compiler.ApplyLegacyLimit(ctx); + [Fact] + public void WithNoLimit() + { + var query = new Query("Table").Offset(20); + OracleCompiler + .Compile(query).ToString().Should() + .Be(""" + SELECT * FROM (SELECT "results_wrapper".*, ROWNUM "row_num" FROM (SELECT * FROM "Table") "results_wrapper") WHERE "row_num" > 20 + """); + } - // Assert: - Assert.Equal("SELECT * FROM (SELECT \"results_wrapper\".*, ROWNUM \"row_num\" FROM (GENERATED_SQL) \"results_wrapper\" WHERE ROWNUM <= ?) WHERE \"row_num\" > ?", ctx.RawSql); - Assert.Equal(25L, ctx.Bindings[0]); - Assert.Equal(20L, ctx.Bindings[1]); - Assert.Equal(2, ctx.Bindings.Count); - } + [Fact] + public void WithLimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + OracleCompiler + .Compile(query).ToString().Should() + .Be(""" + SELECT * FROM (SELECT "results_wrapper".*, ROWNUM "row_num" FROM (SELECT * FROM "Table") "results_wrapper" WHERE ROWNUM <= 25) WHERE "row_num" > 20 + """); } } diff --git a/QueryBuilder.Tests/Oracle/OracleLimitTests.cs b/QueryBuilder.Tests/Oracle/OracleLimitTests.cs index 404fd5b1..8baca20d 100644 --- a/QueryBuilder.Tests/Oracle/OracleLimitTests.cs +++ b/QueryBuilder.Tests/Oracle/OracleLimitTests.cs @@ -1,75 +1,45 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Oracle -{ - public class OracleLimitTests : TestSupport - { - private const string TableName = "Table"; - private const string SqlPlaceholder = "GENERATED_SQL"; - - private OracleCompiler compiler; - - public OracleLimitTests() - { - compiler = Compilers.Get(EngineCodes.Oracle); - } - - [Fact] - public void NoLimitNorOffset() - { - // Arrange: - var query = new Query(TableName); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; - - // Act & Assert: - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void LimitOnly() - { - // Arrange: - var query = new Query(TableName).Limit(10); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; - - // Act & Assert: - Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx)); - Assert.Equal(2, ctx.Bindings.Count); - Assert.Equal(0L, ctx.Bindings[0]); - Assert.Equal(10, ctx.Bindings[1]); - } - - [Fact] - public void OffsetOnly() - { - // Arrange: - var query = new Query(TableName).Offset(20); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; +namespace SqlKata.Tests.Oracle; - // Act & Assert: - Assert.EndsWith("OFFSET ? ROWS", compiler.CompileLimit(ctx)); - - Assert.Single(ctx.Bindings); - Assert.Equal(20L, ctx.Bindings[0]); - } +public sealed class OracleLimitTests +{ + private readonly OracleCompiler _compiler = new (); - [Fact] - public void LimitAndOffset() - { - // Arrange: - var query = new Query(TableName).Limit(5).Offset(20); - var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder }; + [Fact] + public void NoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "Table" + """); + } - // Act & Assert: - Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx)); + [Fact] + public void LimitOnly() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" ORDER BY (SELECT 0 FROM DUAL) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"""); + } - Assert.Equal(2, ctx.Bindings.Count); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Equal(5, ctx.Bindings[1]); + [Fact] + public void OffsetOnly() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "Table" ORDER BY (SELECT 0 FROM DUAL) OFFSET 20 ROWS + """); + } - compiler.CompileLimit(ctx); - } + [Fact] + public void LimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" ORDER BY (SELECT 0 FROM DUAL) OFFSET 20 ROWS FETCH NEXT 5 ROWS ONLY"""); } } diff --git a/QueryBuilder.Tests/ParameterTypeTests.cs b/QueryBuilder.Tests/ParameterTypeTests.cs index 095a6e53..594779dd 100644 --- a/QueryBuilder.Tests/ParameterTypeTests.cs +++ b/QueryBuilder.Tests/ParameterTypeTests.cs @@ -1,52 +1,54 @@ -using System; -using System.Collections.Generic; +using System.Collections; using System.Globalization; using SqlKata.Compilers; -using Xunit; -using System.Collections; using SqlKata.Tests.Infrastructure; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class ParameterTypeTests : TestSupport { - public class ParameterTypeTests : TestSupport + public enum EnumExample + { + First, + Second, + Third + } + + [Theory] + [ClassData(typeof(ParameterTypeGenerator))] + public void CorrectParameterTypeOutput(string rendered, object input) + { + var query = new Query("Table").Where("Col", input); + + var c = Compile(query); + + Assert.Equal($"SELECT * FROM [Table] WHERE [Col] = {rendered}", c[EngineCodes.SqlServer]); + } + + public class ParameterTypeGenerator : IEnumerable { - public enum EnumExample + private readonly List _data = new() { - First, - Second, - Third, - } + new object[] { "1", 1 }, + new object[] { Convert.ToSingle("10.5", CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), 10.5 }, + new object[] { "-2", -2 }, + new object[] { Convert.ToSingle("-2.8", CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture), -2.8 }, + new object[] { "cast(1 as bit)", true }, + new object[] { "cast(0 as bit)", false }, + new object[] { "'2018-10-28 19:22:00'", new DateTime(2018, 10, 28, 19, 22, 0) }, + new object[] { "0 /* First */", EnumExample.First }, + new object[] { "1 /* Second */", EnumExample.Second }, + new object[] { "'a string'", "a string" } + }; - public class ParameterTypeGenerator : IEnumerable + public IEnumerator GetEnumerator() { - private readonly List _data = new List - { - new object[] {"1", 1}, - new object[] {Convert.ToSingle("10.5", CultureInfo.InvariantCulture).ToString(), 10.5}, - new object[] {"-2", -2}, - new object[] {Convert.ToSingle("-2.8", CultureInfo.InvariantCulture).ToString(), -2.8}, - new object[] {"cast(1 as bit)", true}, - new object[] {"cast(0 as bit)", false}, - new object[] {"'2018-10-28 19:22:00'", new DateTime(2018, 10, 28, 19, 22, 0)}, - new object[] {"0 /* First */", EnumExample.First}, - new object[] {"1 /* Second */", EnumExample.Second}, - new object[] {"'a string'", "a string"}, - }; - - public IEnumerator GetEnumerator() => _data.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + return _data.GetEnumerator(); } - [Theory] - [ClassData(typeof(ParameterTypeGenerator))] - public void CorrectParameterTypeOutput(string rendered, object input) + IEnumerator IEnumerable.GetEnumerator() { - var query = new Query("Table").Where("Col", input); - - var c = Compile(query); - - Assert.Equal($"SELECT * FROM [Table] WHERE [Col] = {rendered}", c[EngineCodes.SqlServer]); + return GetEnumerator(); } } } diff --git a/QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs b/QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs index 3c8d054a..f3c3ab49 100644 --- a/QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs +++ b/QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs @@ -1,58 +1,43 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.PostgreSql -{ - public class PostgreSqlLimitTests : TestSupport - { - private readonly PostgresCompiler compiler; - - public PostgreSqlLimitTests() - { - compiler = Compilers.Get(EngineCodes.PostgreSql); - } - - [Fact] - public void WithNoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; +namespace SqlKata.Tests.PostgreSql; - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void WithNoOffset() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; - - Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx)); - Assert.Equal(10, ctx.Bindings[0]); - } +public sealed class PostgreSqlLimitTests +{ + private readonly PostgresCompiler _compiler = new(); - [Fact] - public void WithNoLimit() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "Table" + """); + } - Assert.Equal("OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } + [Fact] + public void WithNoOffset() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" LIMIT 10"""); + } - [Fact] - public void WithLimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimit() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" OFFSET 20"""); + } - Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(5, ctx.Bindings[0]); - Assert.Equal(20L, ctx.Bindings[1]); - Assert.Equal(2, ctx.Bindings.Count); - } + [Fact] + public void WithLimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" LIMIT 5 OFFSET 20"""); } } diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.csproj b/QueryBuilder.Tests/QueryBuilder.Tests.csproj old mode 100755 new mode 100644 index 92829215..5b7f3efd --- a/QueryBuilder.Tests/QueryBuilder.Tests.csproj +++ b/QueryBuilder.Tests/QueryBuilder.Tests.csproj @@ -1,19 +1,110 @@ - - net6.0 - Library - false - SqlKata.Tests - - - - - - - - - - - - + + net7.0 + Library + false + SqlKata.Tests + enable + enable + true + 11 + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + + CompileFlatColumns.cs + + \ No newline at end of file diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.csproj.DotSettings b/QueryBuilder.Tests/QueryBuilder.Tests.csproj.DotSettings new file mode 100644 index 00000000..16c7a3d1 --- /dev/null +++ b/QueryBuilder.Tests/QueryBuilder.Tests.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp110 \ No newline at end of file diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.v3.ncrunchproject b/QueryBuilder.Tests/QueryBuilder.Tests.v3.ncrunchproject new file mode 100644 index 00000000..8602fef7 --- /dev/null +++ b/QueryBuilder.Tests/QueryBuilder.Tests.v3.ncrunchproject @@ -0,0 +1,103 @@ + + + + + SqlKata.Tests.IntermediateStageInsertTests.InsertFromSubQueryWithCte + + + SqlKata.Tests.IntermediateStageSelectTests.MultipleUnionWithBindingsAndPagination + + + SqlKata.Tests.IntermediateStageSelectTests.UnionWithDifferentEngine + + + SqlKata.Tests.IntermediateStageInsertTests + + + SqlKata.Tests.Firebird.FirebirdLimitTests + + + SqlKata.Tests.MySql.MySqlLimitTests + + + SqlKata.Tests.Oracle.OracleLimitTests + + + SqlKata.Tests.Oracle.OracleLegacyLimitTests + + + SqlKata.Tests.Oracle.OracleInsertManyTests + + + SqlKata.Tests.Oracle.OracleDateConditionTests + + + SqlKata.Tests.PostgreSql.PostgreSqlLimitTests + + + SqlKata.Tests.Sqlite.SqliteLimitTests + + + SqlKata.Tests.SqlServer.SqlServerTests + + + SqlKata.Tests.SqlServer.SqlServerLimitTests + + + SqlKata.Tests.SqlServer.SqlServerLegacyLimitTests + + + SqlKata.Tests.SqlServer.NestedSelectTests + + + SqlKata.Tests.MySqlExecutionTest + + + SqlKata.Tests.AggregateTests + + + SqlKata.Tests.CoverageTests + + + SqlKata.Tests.DefineTest + + + SqlKata.Tests.DeleteTests + + + SqlKata.Tests.ExecutionTests + + + SqlKata.Tests.GeneralTests + + + SqlKata.Tests.HelperTests + + + SqlKata.Tests.InfrastructureTests + + + SqlKata.Tests.InsertTests + + + SqlKata.Tests.OperatorWhitelistTests + + + SqlKata.Tests.ParameterTypeTests + + + SqlKata.Tests.SelectTests + + + SqlKata.Tests.SqliteExecutionTest + + + SqlKata.Tests.UpdateTests + + + SqlKata.Tests.WhereTests + + + True + + \ No newline at end of file diff --git a/QueryBuilder.Tests/QueryFactoryExtension.cs b/QueryBuilder.Tests/QueryFactoryExtension.cs index 9f87bfce..7261e53f 100644 --- a/QueryBuilder.Tests/QueryFactoryExtension.cs +++ b/QueryBuilder.Tests/QueryFactoryExtension.cs @@ -1,8 +1,8 @@ - -using System.Collections.Generic; using SqlKata.Execution; -static class QueryFactoryExtensions +namespace SqlKata.Tests; + +internal static class QueryFactoryExtensions { public static QueryFactory Create(this QueryFactory db, string table, IEnumerable cols) { @@ -16,4 +16,4 @@ public static QueryFactory Drop(this QueryFactory db, string table) db.Statement($"DROP TABLE IF EXISTS `{table}`;"); return db; } -} \ No newline at end of file +} diff --git a/QueryBuilder.Tests/SQLiteExecutionTest.cs b/QueryBuilder.Tests/SQLiteExecutionTest.cs index 8c4d43f5..5e698016 100644 --- a/QueryBuilder.Tests/SQLiteExecutionTest.cs +++ b/QueryBuilder.Tests/SQLiteExecutionTest.cs @@ -1,275 +1,267 @@ +using Microsoft.Data.Sqlite; using SqlKata.Compilers; -using Xunit; using SqlKata.Execution; -using MySql.Data.MySqlClient; -using System; -using System.Linq; using static SqlKata.Expressions; -using System.Collections.Generic; -using Microsoft.Data.Sqlite; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class SqliteExecutionTest { - public class SqliteExecutionTest + [Fact] + public void EmptySelect() { - [Fact] - public void EmptySelect() + var db = Db().Create("Cars", new[] { + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + var tables = db.Select(@"SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%'"); + Assert.NotEmpty(tables); - var tables = db.Select(@"SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%'"); + var rows = db.Query("Cars").Get(); - var rows = db.Query("Cars").Get(); + Assert.Empty(rows); - Assert.Empty(rows); - - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void SelectWithLimit() + [Fact] + public void SelectWithLimit() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); - var rows = db.Query("Cars").Get().ToList(); + var rows = db.Query("Cars").Get().ToList(); - Assert.Single(rows); + Assert.Single(rows); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void InsertGetId() + [Fact] + public void InsertGetId() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - }); - - var id = db.Query("Cars").InsertGetId(new - { - Brand = "Toyota", - Year = 1900 - }); + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL" + }); - Assert.Equal(1, id); + var id = db.Query("Cars").InsertGetId(new + { + Brand = "Toyota", + Year = 1900 + }); - id = db.Query("Cars").InsertGetId(new - { - Brand = "Toyota 2", - Year = 1901 - }); + Assert.Equal(1, id); - Assert.Equal(2, id); + id = db.Query("Cars").InsertGetId(new + { + Brand = "Toyota 2", + Year = 1901 + }); - id = db.Query("Cars").InsertGetId(new - { - Brand = "Toyota 2", - Year = 1901 - }); + Assert.Equal(2, id); - Assert.Equal(3, id); + id = db.Query("Cars").InsertGetId(new + { + Brand = "Toyota 2", + Year = 1901 + }); + Assert.Equal(3, id); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void Count() + [Fact] + public void Count() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); - var count = db.Query("Cars").Count(); - Assert.Equal(1, count); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)"); + var count = db.Query("Cars").Count(); + Assert.Equal(1, count); - db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Toyota', 2021)"); - count = db.Query("Cars").Count(); - Assert.Equal(2, count); + db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Toyota', 2021)"); + count = db.Query("Cars").Count(); + Assert.Equal(2, count); - int affected = db.Query("Cars").Delete(); - Assert.Equal(2, affected); + var affected = db.Query("Cars").Delete(); + Assert.Equal(2, affected); - count = db.Query("Cars").Count(); - Assert.Equal(0, count); + count = db.Query("Cars").Count(); + Assert.Equal(0, count); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void CloneThenCount() + [Fact] + public void CloneThenCount() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); - - for (int i = 0; i < 10; i++) + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); + + for (var i = 0; i < 10; i++) + db.Query("Cars").Insert(new { - db.Query("Cars").Insert(new - { - Brand = "Brand " + i, - Year = "2020", - }); - } + Brand = "Brand " + i, + Year = "2020" + }); - var query = db.Query("Cars").Where("Id", "<", 5); - var count = query.Count(); - var cloneCount = query.Clone().Count(); + var query = db.Query("Cars").Where("Id", "<", 5); + var count = query.Count(); + var cloneCount = query.Clone().Count(); - Assert.Equal(4, count); - Assert.Equal(4, cloneCount); + Assert.Equal(4, count); + Assert.Equal(4, cloneCount); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void QueryWithVariable() + [Fact] + public void QueryWithVariable() + { + var db = Db().Create("Cars", new[] { - var db = DB().Create("Cars", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Brand TEXT NOT NULL", - "Year INT NOT NULL", - "Color TEXT NULL", - }); - - for (int i = 0; i < 10; i++) + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Brand TEXT NOT NULL", + "Year INT NOT NULL", + "Color TEXT NULL" + }); + + for (var i = 0; i < 10; i++) + db.Query("Cars").Insert(new { - db.Query("Cars").Insert(new - { - Brand = "Brand " + i, - Year = "2020", - }); - } + Brand = "Brand " + i, + Year = "2020" + }); - var count = db.Query("Cars") - .Define("Threshold", 5) - .Where("Id", "<", SqlKata.Expressions.Variable("Threshold")) - .Count(); + var count = db.Query("Cars") + .Define("Threshold", 5) + .Where("Id", "<", Variable("Threshold")) + .Count(); - Assert.Equal(4, count); + Assert.Equal(4, count); - db.Drop("Cars"); - } + db.Drop("Cars"); + } - [Fact] - public void InlineTable() + [Fact] + public void InlineTable() + { + var db = Db().Create("Transaction", new[] { - var db = DB().Create("Transaction", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Amount int NOT NULL", - "Date DATE NOT NULL", - }); + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Amount int NOT NULL", + "Date DATE NOT NULL" + }); - db.Query("Transaction").Insert(new - { - Date = "2022-01-01", - Amount = 10 - }); + db.Query("Transaction").Insert(new + { + Date = "2022-01-01", + Amount = 10 + }); - var rows = db.Query("Transaction") - .With("Rates", new[] { "Date", "Rate" }, new object[][] { - new object[] {"2022-01-01", 0.5}, - }) - .Join("Rates", "Rates.Date", "Transaction.Date") - .SelectRaw("([Transaction].[Amount] * [Rates].[Rate]) as AmountConverted") - .Get(); + var rows = db.Query("Transaction") + .With("Rates", new[] { "Date", "Rate" }, new[] + { + new object[] { "2022-01-01", 0.5 } + }) + .Join("Rates", "Rates.Date", "Transaction.Date") + .SelectRaw("([Transaction].[Amount] * [Rates].[Rate]) as AmountConverted") + .Get(); - Assert.Single(rows); - Assert.Equal(5, rows.First().AmountConverted); + Assert.Equal(5, rows.First().AmountConverted); - db.Drop("Transaction"); - } + db.Drop("Transaction"); + } + [Fact] + public void BasicSelectFilter() + { + var db = Db().Create("Transaction", new[] + { + "Id INTEGER PRIMARY KEY AUTOINCREMENT", + "Date DATE NOT NULL", + "Amount int NOT NULL" + }); - [Fact] - public void BasicSelectFilter() + var data = new Dictionary { - var db = DB().Create("Transaction", new[] { - "Id INTEGER PRIMARY KEY AUTOINCREMENT", - "Date DATE NOT NULL", - "Amount int NOT NULL", + // 2020 + { "2020-01-01", 10 }, + { "2020-05-01", 20 }, + + // 2021 + { "2021-01-01", 40 }, + { "2021-02-01", 10 }, + { "2021-04-01", -10 }, + + // 2022 + { "2022-01-01", 80 }, + { "2022-02-01", -30 }, + { "2022-05-01", 50 } + }; + + foreach (var row in data) + db.Query("Transaction").Insert(new + { + Date = row.Key, + Amount = row.Value }); - var data = new Dictionary { - // 2020 - {"2020-01-01", 10}, - {"2020-05-01", 20}, - - // 2021 - {"2021-01-01", 40}, - {"2021-02-01", 10}, - {"2021-04-01", -10}, - - // 2022 - {"2022-01-01", 80}, - {"2022-02-01", -30}, - {"2022-05-01", 50}, - }; - - foreach (var row in data) - { - db.Query("Transaction").Insert(new - { - Date = row.Key, - Amount = row.Value - }); - } - - var query = db.Query("Transaction") + var query = db.Query("Transaction") .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020)) .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021)) .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022)) - ; + ; - var results = query.Get().ToList(); - Assert.Single(results); - Assert.Equal(30, results[0].Total_2020); - Assert.Equal(40, results[0].Total_2021); - Assert.Equal(100, results[0].Total_2022); + var results = query.Get().ToList(); + Assert.Single(results); + Assert.Equal(30, results[0].Total_2020); + Assert.Equal(40, results[0].Total_2021); + Assert.Equal(100, results[0].Total_2022); - db.Drop("Transaction"); - } - - QueryFactory DB() - { - var cs = $"Data Source=file::memory:;Cache=Shared"; - - var connection = new SqliteConnection(cs); - - var db = new QueryFactory(connection, new SqliteCompiler()); + db.Drop("Transaction"); + } - return db; - } + private QueryFactory Db() + { + var cs = "Data Source=file::memory:;Cache=Shared"; + var connection = new SqliteConnection(cs); + var db = new QueryFactory(connection, new SqliteCompiler()); + return db; } -} \ No newline at end of file +} diff --git a/QueryBuilder.Tests/SelectTests.cs b/QueryBuilder.Tests/SelectTests.cs index 3f3c28ba..191dd1a1 100644 --- a/QueryBuilder.Tests/SelectTests.cs +++ b/QueryBuilder.Tests/SelectTests.cs @@ -1,935 +1,1016 @@ using SqlKata.Compilers; using SqlKata.Extensions; using SqlKata.Tests.Infrastructure; -using System; -using System.Collections.Generic; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class SelectTests : TestSupport { - public class SelectTests : TestSupport + [Fact] + public void BasicSelect() { - [Fact] - public void BasicSelect() - { - var q = new Query().From("users").Select("id", "name"); - var c = Compile(q); - - Assert.Equal("SELECT [id], [name] FROM [users]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `id`, `name` FROM `users`", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.Oracle]); - } - - [Fact] - public void BasicSelectEnumerable() - { - var q = new Query().From("users").Select(new List() { "id", "name" }); - var c = Compile(q); - - Assert.Equal("SELECT [id], [name] FROM [users]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `id`, `name` FROM `users`", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.Oracle]); - } - - [Fact] - public void BasicSelectWhereBindingIsEmptyOrNull() - { - var q = new Query() - .From("users") - .Select("id", "name") - .Where("author", "") - .OrWhere("author", null); - - var c = Compile(q); - - Assert.Equal("SELECT [id], [name] FROM [users] WHERE [author] = '' OR [author] IS NULL", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `id`, `name` FROM `users` WHERE `author` = '' OR `author` IS NULL", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" WHERE \"author\" = '' OR \"author\" IS NULL", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\" WHERE \"AUTHOR\" = '' OR \"AUTHOR\" IS NULL", c[EngineCodes.Firebird]); - } - - [Fact] - public void BasicSelectWithAlias() - { - var q = new Query().From("users as u").Select("id", "name"); - var c = Compile(q); - - Assert.Equal("SELECT [id], [name] FROM [users] AS [u]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `id`, `name` FROM `users` AS `u`", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" AS \"u\"", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\" AS \"U\"", c[EngineCodes.Firebird]); - } - - [Fact] - public void ExpandedSelect() - { - var q = new Query().From("users").Select("users.{id,name, age}"); - var c = Compile(q); - - Assert.Equal("SELECT [users].[id], [users].[name], [users].[age] FROM [users]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `users`.`id`, `users`.`name`, `users`.`age` FROM `users`", c[EngineCodes.MySql]); - } - - [Fact] - public void ExpandedSelectWithSchema() - { - var q = new Query().From("users").Select("dbo.users.{id,name, age}"); - var c = Compile(q); - - Assert.Equal("SELECT [dbo].[users].[id], [dbo].[users].[name], [dbo].[users].[age] FROM [users]", c[EngineCodes.SqlServer]); - } - - [Fact] - public void NestedEmptyWhereAtFirstCondition() - { - var query = new Query("table") - .Where(q => new Query()) - .Where("id", 1); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [table] WHERE [id] = 1", c[EngineCodes.SqlServer]); - - - Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ID\" = 1", c[EngineCodes.Firebird]); - } - - [Fact] - public void WhereTrue() - { - var query = new Query("Table").WhereTrue("IsActive"); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [Table] WHERE [IsActive] = cast(1 as bit)", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `Table` WHERE `IsActive` = true", c[EngineCodes.MySql]); - Assert.Equal("SELECT * FROM \"Table\" WHERE \"IsActive\" = true", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ISACTIVE\" = 1", c[EngineCodes.Firebird]); - } - - [Fact] - public void WhereFalse() - { - var query = new Query("Table").WhereFalse("IsActive"); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [Table] WHERE [IsActive] = cast(0 as bit)", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `Table` WHERE `IsActive` = false", c[EngineCodes.MySql]); - Assert.Equal("SELECT * FROM \"Table\" WHERE \"IsActive\" = false", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ISACTIVE\" = 0", c[EngineCodes.Firebird]); - } - - [Fact] - public void OrWhereFalse() - { - var query = new Query("Table").Where("MyCol", "abc").OrWhereFalse("IsActive"); - - var c = Compile(query); - - Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] = cast(0 as bit)", c[EngineCodes.SqlServer]); - - Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" = false", c[EngineCodes.PostgreSql]); - - } - - [Fact] - public void OrWhereTrue() - { - var query = new Query("Table").Where("MyCol", "abc").OrWhereTrue("IsActive"); + var q = new Query().From("users").Select("id", "name"); + var c = Compile(q); + + Assert.Equal("SELECT [id], [name] FROM [users]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `id`, `name` FROM `users`", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.Oracle]); + } - var c = Compile(query); + [Fact] + public void BasicSelectEnumerable() + { + var q = new Query().From("users").Select(new List { "id", "name" }); + var c = Compile(q); + + Assert.Equal("SELECT [id], [name] FROM [users]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `id`, `name` FROM `users`", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\"", c[EngineCodes.Oracle]); + } - Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] = cast(1 as bit)", c[EngineCodes.SqlServer]); + [Fact] + public void BasicSelectWhereBindingIsEmptyOrNull() + { + var q = new Query() + .From("users") + .Select("id", "name") + .Where("author", "") + .OrWhere("author", null); + + var c = Compile(q); + + Assert.Equal("SELECT [id], [name] FROM [users] WHERE [author] = '' OR [author] IS NULL", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `id`, `name` FROM `users` WHERE `author` = '' OR `author` IS NULL", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" WHERE \"author\" = '' OR \"author\" IS NULL", + c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\" WHERE \"AUTHOR\" = '' OR \"AUTHOR\" IS NULL", + c[EngineCodes.Firebird]); + } - Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" = true", c[EngineCodes.PostgreSql]); + [Fact] + public void BasicSelectWithAlias() + { + var q = new Query().From("users as u").Select("id", "name"); + var c = Compile(q); - } + Assert.Equal("SELECT [id], [name] FROM [users] AS [u]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `id`, `name` FROM `users` AS `u`", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" AS \"u\"", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT \"ID\", \"NAME\" FROM \"USERS\" AS \"U\"", c[EngineCodes.Firebird]); + } - [Fact] - public void OrWhereNull() - { - var query = new Query("Table").Where("MyCol", "abc").OrWhereNull("IsActive"); + [Fact] + public void ExpandedSelect() + { + var q = new Query().From("users").Select("users.{id,name, age}"); + var c = Compile(q); - var c = Compile(query); + Assert.Equal("SELECT [users].[id], [users].[name], [users].[age] FROM [users]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `users`.`id`, `users`.`name`, `users`.`age` FROM `users`", c[EngineCodes.MySql]); + } - Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] IS NULL", c[EngineCodes.SqlServer]); + [Fact] + public void ExpandedSelectWithSchema() + { + var q = new Query().From("users").Select("dbo.users.{id,name, age}"); + var c = Compile(q); - Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" IS NULL", c[EngineCodes.PostgreSql]); - } + Assert.Equal("SELECT [dbo].[users].[id], [dbo].[users].[name], [dbo].[users].[age] FROM [users]", + c[EngineCodes.SqlServer]); + } - [Fact] - public void WhereSub() - { - var subQuery = new Query("Table2").WhereColumns("Table2.Column", "=", "Table.MyCol").AsCount(); + [Fact] + public void NestedEmptyWhereAtFirstCondition() + { + var query = new Query("table") + .Where(_ => new Query()) + .Where("id", 1); - var query = new Query("Table").WhereSub(subQuery, 1); + var c = Compile(query); - var c = Compile(query); + Assert.Equal("SELECT * FROM [table] WHERE [id] = 1", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM [Table] WHERE (SELECT COUNT(*) AS [count] FROM [Table2] WHERE [Table2].[Column] = [Table].[MyCol]) = 1", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM \"Table\" WHERE (SELECT COUNT(*) AS \"count\" FROM \"Table2\" WHERE \"Table2\".\"Column\" = \"Table\".\"MyCol\") = 1", c[EngineCodes.PostgreSql]); - } + Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ID\" = 1", c[EngineCodes.Firebird]); + } - [Fact] - public void OrWhereSub() - { - var subQuery = new Query("Table2").WhereColumns("Table2.Column", "=", "Table.MyCol").AsCount(); + [Fact] + public void WhereTrue() + { + var query = new Query("Table").WhereTrue("IsActive"); - var query = new Query("Table").WhereNull("MyCol").OrWhereSub(subQuery, "<", 1); + var c = Compile(query); - var c = Compile(query); + Assert.Equal("SELECT * FROM [Table] WHERE [IsActive] = cast(1 as bit)", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `Table` WHERE `IsActive` = true", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM \"Table\" WHERE \"IsActive\" = true", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ISACTIVE\" = 1", c[EngineCodes.Firebird]); + } - Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] IS NULL OR (SELECT COUNT(*) AS [count] FROM [Table2] WHERE [Table2].[Column] = [Table].[MyCol]) < 1", c[EngineCodes.SqlServer]); + [Fact] + public void WhereFalse() + { + var query = new Query("Table").WhereFalse("IsActive"); - Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" IS NULL OR (SELECT COUNT(*) AS \"count\" FROM \"Table2\" WHERE \"Table2\".\"Column\" = \"Table\".\"MyCol\") < 1", c[EngineCodes.PostgreSql]); - } + var c = Compile(query); - [Fact] - public void PassingArrayAsParameter() - { - var query = new Query("Table").WhereRaw("[Id] in (?)", new object[] { new object[] { 1, 2, 3 } }); + Assert.Equal("SELECT * FROM [Table] WHERE [IsActive] = cast(0 as bit)", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `Table` WHERE `IsActive` = false", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM \"Table\" WHERE \"IsActive\" = false", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT * FROM \"TABLE\" WHERE \"ISACTIVE\" = 0", c[EngineCodes.Firebird]); + } - var c = Compile(query); + [Fact] + public void OrWhereFalse() + { + var query = new Query("Table").Where("MyCol", "abc").OrWhereFalse("IsActive"); - Assert.Equal("SELECT * FROM [Table] WHERE [Id] in (1,2,3)", c[EngineCodes.SqlServer]); - } + var c = Compile(query); - [Fact] - public void UsingJsonArray() - { - var query = new Query("Table").WhereRaw("[Json]->'address'->>'country' in (?)", new[] { 1, 2, 3, 4 }); + Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] = cast(0 as bit)", + c[EngineCodes.SqlServer]); - var c = Compile(query); + Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" = false", + c[EngineCodes.PostgreSql]); + } - Assert.Equal("SELECT * FROM \"Table\" WHERE \"Json\"->'address'->>'country' in (1,2,3,4)", c[EngineCodes.PostgreSql]); - } + [Fact] + public void OrWhereTrue() + { + var query = new Query("Table").Where("MyCol", "abc").OrWhereTrue("IsActive"); - [Fact] - public void Union() - { - var laptops = new Query("Laptops"); - var mobiles = new Query("Phones").Union(laptops); + var c = Compile(query); - var c = Compile(mobiles); + Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] = cast(1 as bit)", + c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM \"Phones\" UNION SELECT * FROM \"Laptops\"", c[EngineCodes.Sqlite]); - Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\"", c[EngineCodes.Firebird]); - } + Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" = true", + c[EngineCodes.PostgreSql]); + } + [Fact] + public void OrWhereNull() + { + var query = new Query("Table").Where("MyCol", "abc").OrWhereNull("IsActive"); - [Fact] - public void UnionWithBindings() - { - var laptops = new Query("Laptops").Where("Type", "A"); - var mobiles = new Query("Phones").Union(laptops); + var c = Compile(query); - var c = Compile(mobiles); + Assert.Equal("SELECT * FROM [Table] WHERE [MyCol] = 'abc' OR [IsActive] IS NULL", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] WHERE [Type] = 'A'", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM \"Phones\" UNION SELECT * FROM \"Laptops\" WHERE \"Type\" = 'A'", c[EngineCodes.Sqlite]); - Assert.Equal("SELECT * FROM `Phones` UNION SELECT * FROM `Laptops` WHERE `Type` = 'A'", c[EngineCodes.MySql]); - Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\" WHERE \"TYPE\" = 'A'", c[EngineCodes.Firebird]); - } + Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = 'abc' OR \"IsActive\" IS NULL", + c[EngineCodes.PostgreSql]); + } - [Fact] - public void RawUnionWithBindings() - { - var mobiles = new Query("Phones").UnionRaw("UNION SELECT * FROM [Laptops] WHERE [Type] = ?", "A"); + [Fact] + public void WhereSub() + { + var subQuery = new Query("Table2").WhereColumns("Table2.Column", "=", "Table.MyCol").AsCount(); - var c = Compile(mobiles); + var query = new Query("Table").WhereSub(subQuery, 1); - Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] WHERE [Type] = 'A'", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `Phones` UNION SELECT * FROM `Laptops` WHERE `Type` = 'A'", c[EngineCodes.MySql]); - } + var c = Compile(query); - [Fact] - public void MultipleUnion() - { - var laptops = new Query("Laptops"); - var tablets = new Query("Tablets"); + Assert.Equal( + "SELECT * FROM [Table] WHERE (SELECT COUNT(*) AS [count] FROM [Table2] WHERE [Table2].[Column] = [Table].[MyCol]) = 1", + c[EngineCodes.SqlServer]); - var mobiles = new Query("Phones").Union(laptops).Union(tablets); + Assert.Equal( + "SELECT * FROM \"Table\" WHERE (SELECT COUNT(*) AS \"count\" FROM \"Table2\" WHERE \"Table2\".\"Column\" = \"Table\".\"MyCol\") = 1", + c[EngineCodes.PostgreSql]); + } - var c = Compile(mobiles); + [Fact] + public void OrWhereSub() + { + var subQuery = new Query("Table2").WhereColumns("Table2.Column", "=", "Table.MyCol").AsCount(); - Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] UNION SELECT * FROM [Tablets]", - c[EngineCodes.SqlServer]); + var query = new Query("Table").WhereNull("MyCol").OrWhereSub(subQuery, "<", 1); + var c = Compile(query); - Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\" UNION SELECT * FROM \"TABLETS\"", - c[EngineCodes.Firebird]); - } + Assert.Equal( + "SELECT * FROM [Table] WHERE [MyCol] IS NULL OR (SELECT COUNT(*) AS [count] FROM [Table2] WHERE [Table2].[Column] = [Table].[MyCol]) < 1", + c[EngineCodes.SqlServer]); - [Fact] - public void MultipleUnionWithBindings() - { - var laptops = new Query("Laptops").Where("Price", ">", 1000); - var tablets = new Query("Tablets").Where("Price", ">", 2000); + Assert.Equal( + "SELECT * FROM \"Table\" WHERE \"MyCol\" IS NULL OR (SELECT COUNT(*) AS \"count\" FROM \"Table2\" WHERE \"Table2\".\"Column\" = \"Table\".\"MyCol\") < 1", + c[EngineCodes.PostgreSql]); + } - var mobiles = new Query("Phones").Where("Price", "<", 3000).Union(laptops).Union(tablets); + [Fact] + public void PassingArrayAsParameter() + { + var query = new Query("Table").WhereRaw("[Id] in (?)", new object[] { new object[] { 1, 2, 3 } }); - var c = Compile(mobiles); + var c = Compile(query); - Assert.Equal( - "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] WHERE [Price] > 1000 UNION SELECT * FROM [Tablets] WHERE [Price] > 2000", - c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM [Table] WHERE [Id] in (1,2,3)", c[EngineCodes.SqlServer]); + } + [Fact] + public void UsingJsonArray() + { + var query = new Query("Table").WhereRaw("[Json]->'address'->>'country' in (?)", new[] { 1, 2, 3, 4 }); - Assert.Equal( - "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" > 1000 UNION SELECT * FROM \"TABLETS\" WHERE \"PRICE\" > 2000", - c[EngineCodes.Firebird]); - } + var c = Compile(query); - [Fact] - public void MultipleUnionWithBindingsAndPagination() - { - var laptops = new Query("Laptops").Where("Price", ">", 1000); - var tablets = new Query("Tablets").Where("Price", ">", 2000).ForPage(2); + Assert.Equal("SELECT * FROM \"Table\" WHERE \"Json\"->'address'->>'country' in (1,2,3,4)", + c[EngineCodes.PostgreSql]); + } - var mobiles = new Query("Phones").Where("Price", "<", 3000).Union(laptops).UnionAll(tablets); + [Fact] + public void Union() + { + var laptops = new Query("Laptops"); + var mobiles = new Query("Phones").Union(laptops); + var c = Compile(mobiles); - var c = Compile(mobiles); + Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM \"Phones\" UNION SELECT * FROM \"Laptops\"", c[EngineCodes.Sqlite]); + Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\"", c[EngineCodes.Firebird]); + } - Assert.Equal( - "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] WHERE [Price] > 1000 UNION ALL SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [Tablets] WHERE [Price] > 2000) AS [results_wrapper] WHERE [row_num] BETWEEN 16 AND 30", - c[EngineCodes.SqlServer]); + [Fact] + public void UnionWithBindings() + { + var laptops = new Query("Laptops").Where("Type", "A"); + var mobiles = new Query("Phones").Union(laptops); + + var c = Compile(mobiles); + + Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] WHERE [Type] = 'A'", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM \"Phones\" UNION SELECT * FROM \"Laptops\" WHERE \"Type\" = 'A'", + c[EngineCodes.Sqlite]); + Assert.Equal("SELECT * FROM `Phones` UNION SELECT * FROM `Laptops` WHERE `Type` = 'A'", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\" WHERE \"TYPE\" = 'A'", + c[EngineCodes.Firebird]); + } - Assert.Equal( - "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" > 1000 UNION ALL SELECT * FROM \"TABLETS\" WHERE \"PRICE\" > 2000 ROWS 16 TO 30", - c[EngineCodes.Firebird]); - } + [Fact] + public void RawUnionWithBindings() + { + var mobiles = new Query("Phones").UnionRaw("UNION SELECT * FROM [Laptops] WHERE [Type] = ?", "A"); - [Fact] - public void UnionWithCallbacks() - { - var mobiles = new Query("Phones") - .Where("Price", "<", 3000) - .Union(q => q.From("Laptops")) - .UnionAll(q => q.From("Tablets")); + var c = Compile(mobiles); - var c = Compile(mobiles); + Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] WHERE [Type] = 'A'", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `Phones` UNION SELECT * FROM `Laptops` WHERE `Type` = 'A'", c[EngineCodes.MySql]); + } - Assert.Equal( - "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] UNION ALL SELECT * FROM [Tablets]", - c[EngineCodes.SqlServer]); + [Fact] + public void MultipleUnion() + { + var laptops = new Query("Laptops"); + var tablets = new Query("Tablets"); + var mobiles = new Query("Phones").Union(laptops).Union(tablets); - Assert.Equal( - "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" UNION ALL SELECT * FROM \"TABLETS\"", - c[EngineCodes.Firebird]); - } + var c = Compile(mobiles); - [Fact] - public void UnionWithDifferentEngine() - { - var mobiles = new Query("Phones") - .Where("Price", "<", 300) - .ForSqlServer(scope => scope.Except(q => q.From("Phones").WhereNot("Os", "iOS"))) - .ForPostgreSql(scope => scope.Union(q => q.From("Laptops").Where("Price", "<", 800))) - .ForMySql(scope => scope.IntersectAll(q => q.From("Watches").Where("Os", "Android"))) - .ForFirebird(scope => scope.Union(q => q.From("Laptops").Where("Price", "<", 800))) - .UnionAll(q => q.From("Tablets").Where("Price", "<", 100)); - - var c = Compile(mobiles); - - Assert.Equal( - "SELECT * FROM [Phones] WHERE [Price] < 300 EXCEPT SELECT * FROM [Phones] WHERE NOT ([Os] = 'iOS') UNION ALL SELECT * FROM [Tablets] WHERE [Price] < 100", - c[EngineCodes.SqlServer]); - - Assert.Equal( - "SELECT * FROM `Phones` WHERE `Price` < 300 INTERSECT ALL SELECT * FROM `Watches` WHERE `Os` = 'Android' UNION ALL SELECT * FROM `Tablets` WHERE `Price` < 100", - c[EngineCodes.MySql]); - - Assert.Equal( - "SELECT * FROM \"Phones\" WHERE \"Price\" < 300 UNION SELECT * FROM \"Laptops\" WHERE \"Price\" < 800 UNION ALL SELECT * FROM \"Tablets\" WHERE \"Price\" < 100", - c[EngineCodes.PostgreSql]); - - Assert.Equal( - "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 300 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" < 800 UNION ALL SELECT * FROM \"TABLETS\" WHERE \"PRICE\" < 100", - c[EngineCodes.Firebird]); - } - - [Fact] - public void CombineRaw() - { - var query = new Query("Mobiles").CombineRaw("UNION ALL SELECT * FROM Devices"); + Assert.Equal("SELECT * FROM [Phones] UNION SELECT * FROM [Laptops] UNION SELECT * FROM [Tablets]", + c[EngineCodes.SqlServer]); - var c = Compile(query); - Assert.Equal("SELECT * FROM [Mobiles] UNION ALL SELECT * FROM Devices", c[EngineCodes.SqlServer]); - } + Assert.Equal("SELECT * FROM \"PHONES\" UNION SELECT * FROM \"LAPTOPS\" UNION SELECT * FROM \"TABLETS\"", + c[EngineCodes.Firebird]); + } - [Fact] - public void CombineRawWithPlaceholders() - { - var query = new Query("Mobiles").CombineRaw("UNION ALL SELECT * FROM {Devices}"); + [Fact] + public void MultipleUnionWithBindings() + { + var laptops = new Query("Laptops").Where("Price", ">", 1000); + var tablets = new Query("Tablets").Where("Price", ">", 2000); - var c = Compile(query); + var mobiles = new Query("Phones").Where("Price", "<", 3000).Union(laptops).Union(tablets); - Assert.Equal("SELECT * FROM [Mobiles] UNION ALL SELECT * FROM [Devices]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `Mobiles` UNION ALL SELECT * FROM `Devices`", c[EngineCodes.MySql]); + var c = Compile(mobiles); - Assert.Equal("SELECT * FROM \"MOBILES\" UNION ALL SELECT * FROM \"Devices\"", c[EngineCodes.Firebird]); - } + Assert.Equal( + "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] WHERE [Price] > 1000 UNION SELECT * FROM [Tablets] WHERE [Price] > 2000", + c[EngineCodes.SqlServer]); - [Fact] - public void NestedEmptyWhere() - { - // Empty nested where should be ignored - var query = new Query("A").Where(q => new Query().Where(q2 => new Query().Where(q3 => new Query()))); - var c = Compile(query); + Assert.Equal( + "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" > 1000 UNION SELECT * FROM \"TABLETS\" WHERE \"PRICE\" > 2000", + c[EngineCodes.Firebird]); + } - Assert.Equal("SELECT * FROM [A]", c[EngineCodes.SqlServer]); - } + [Fact] + public void MultipleUnionWithBindingsAndPagination() + { + var laptops = new Query("Laptops").Where("Price", ">", 1000); + var tablets = new Query("Tablets").Where("Price", ">", 2000).ForPage(2); - [Fact] - public void NestedQuery() - { - var query = new Query("A").Where(q => new Query("B")); + var mobiles = new Query("Phones").Where("Price", "<", 3000).Union(laptops).UnionAll(tablets); - var c = Compile(query); - Assert.Equal("SELECT * FROM [A]", c[EngineCodes.SqlServer]); - } + var c = Compile(mobiles); - [Fact] - public void NestedQueryAfterNestedJoin() - { - // in this test, i am testing the compiler dynamic caching functionality - var query = new Query("users") - .Join("countries", j => j.On("countries.id", "users.country_id")) - .Where(q => new Query()); + Assert.Equal( + "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] WHERE [Price] > 1000 UNION ALL SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [Tablets] WHERE [Price] > 2000) AS [results_wrapper] WHERE [row_num] BETWEEN 16 AND 30", + c[EngineCodes.SqlServer]); - var c = Compile(query); - Assert.Equal("SELECT * FROM [users] \nINNER JOIN [countries] ON ([countries].[id] = [users].[country_id])", - c[EngineCodes.SqlServer]); - } + Assert.Equal( + "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" > 1000 UNION ALL SELECT * FROM \"TABLETS\" WHERE \"PRICE\" > 2000 ROWS 16 TO 30", + c[EngineCodes.Firebird]); + } - [Fact] - public void MultipleCte() - { - var q1 = new Query("A"); - var q2 = new Query("B"); - var q3 = new Query("C"); + [Fact] + public void UnionWithCallbacks() + { + var mobiles = new Query("Phones") + .Where("Price", "<", 3000) + .Union(q => q.From("Laptops")) + .UnionAll(q => q.From("Tablets")); - var query = new Query("A") - .With("A", q1) - .With("B", q2) - .With("C", q3); + var c = Compile(mobiles); - var c = Compile(query); + Assert.Equal( + "SELECT * FROM [Phones] WHERE [Price] < 3000 UNION SELECT * FROM [Laptops] UNION ALL SELECT * FROM [Tablets]", + c[EngineCodes.SqlServer]); - Assert.Equal( - "WITH [A] AS (SELECT * FROM [A]),\n[B] AS (SELECT * FROM [B]),\n[C] AS (SELECT * FROM [C])\nSELECT * FROM [A]", - c[EngineCodes.SqlServer]); - } - [Fact] - public void CteAndBindings() - { - var query = new Query("Races") - .For("mysql", s => - s.With("range", q => - q.From("seqtbl") - .Select("Id").Where("Id", "<", 33)) - .WhereIn("RaceAuthor", q => q.From("Users") - .Select("Name").Where("Status", "Available") - ) - ) - .For("sqlsrv", s => - s.With("range", - q => q.From("Sequence").Select("Number").Where("Number", "<", 78) - ) - .Limit(25).Offset(20) - ) - .For("postgres", - s => s.With("range", q => q.FromRaw("generate_series(1, 33) as d").Select("d")) - .Where("Name", "3778") - ) - .For("firebird", - s => s.With("range", q => q.FromRaw("generate_series(1, 33) as d").Select("d")) - .Where("Name", "3778") - ) - .Where("Id", ">", 55) - .WhereBetween("Value", 18, 24); - - var c = Compile(query); - - Assert.Equal( - "WITH [range] AS (SELECT [Number] FROM [Sequence] WHERE [Number] < 78)\nSELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [Races] WHERE [Id] > 55 AND [Value] BETWEEN 18 AND 24) AS [results_wrapper] WHERE [row_num] BETWEEN 21 AND 45", - c[EngineCodes.SqlServer]); - - Assert.Equal( - "WITH `range` AS (SELECT `Id` FROM `seqtbl` WHERE `Id` < 33)\nSELECT * FROM `Races` WHERE `RaceAuthor` IN (SELECT `Name` FROM `Users` WHERE `Status` = 'Available') AND `Id` > 55 AND `Value` BETWEEN 18 AND 24", - c[EngineCodes.MySql]); - - Assert.Equal( - "WITH \"range\" AS (SELECT \"d\" FROM generate_series(1, 33) as d)\nSELECT * FROM \"Races\" WHERE \"Name\" = '3778' AND \"Id\" > 55 AND \"Value\" BETWEEN 18 AND 24", - c[EngineCodes.PostgreSql]); - - Assert.Equal( - "WITH \"RANGE\" AS (SELECT \"D\" FROM generate_series(1, 33) as d)\nSELECT * FROM \"RACES\" WHERE \"NAME\" = '3778' AND \"ID\" > 55 AND \"VALUE\" BETWEEN 18 AND 24", - c[EngineCodes.Firebird]); - } - - // test for issue #50 - [Fact] - public void CascadedCteAndBindings() - { - var cte1 = new Query("Table1"); - cte1.Select("Column1", "Column2"); - cte1.Where("Column2", 1); + Assert.Equal( + "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 3000 UNION SELECT * FROM \"LAPTOPS\" UNION ALL SELECT * FROM \"TABLETS\"", + c[EngineCodes.Firebird]); + } - var cte2 = new Query("Table2"); - cte2.With("cte1", cte1); - cte2.Select("Column3", "Column4"); - cte2.Join("cte1", join => join.On("Column1", "Column3")); - cte2.Where("Column4", 2); + [Fact] + public void UnionWithDifferentEngine() + { + var mobiles = new Query("Phones") + .Where("Price", "<", 300) + .ForSqlServer(scope => scope.Except(q => q.From("Phones").WhereNot("Os", "iOS"))) + .ForPostgreSql(scope => scope.Union(q => q.From("Laptops").Where("Price", "<", 800))) + .ForMySql(scope => scope.IntersectAll(q => q.From("Watches").Where("Os", "Android"))) + .ForFirebird(scope => scope.Union(q => q.From("Laptops").Where("Price", "<", 800))) + .UnionAll(q => q.From("Tablets").Where("Price", "<", 100)); + + var c = Compile(mobiles); + + Assert.Equal( + "SELECT * FROM [Phones] WHERE [Price] < 300 EXCEPT SELECT * FROM [Phones] WHERE NOT ([Os] = 'iOS') UNION ALL SELECT * FROM [Tablets] WHERE [Price] < 100", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "SELECT * FROM `Phones` WHERE `Price` < 300 INTERSECT ALL SELECT * FROM `Watches` WHERE `Os` = 'Android' UNION ALL SELECT * FROM `Tablets` WHERE `Price` < 100", + c[EngineCodes.MySql]); + + Assert.Equal( + "SELECT * FROM \"Phones\" WHERE \"Price\" < 300 UNION SELECT * FROM \"Laptops\" WHERE \"Price\" < 800 UNION ALL SELECT * FROM \"Tablets\" WHERE \"Price\" < 100", + c[EngineCodes.PostgreSql]); + + Assert.Equal( + "SELECT * FROM \"PHONES\" WHERE \"PRICE\" < 300 UNION SELECT * FROM \"LAPTOPS\" WHERE \"PRICE\" < 800 UNION ALL SELECT * FROM \"TABLETS\" WHERE \"PRICE\" < 100", + c[EngineCodes.Firebird]); + } - var mainQuery = new Query("Table3"); - mainQuery.With("cte2", cte2); - mainQuery.Select("*"); - mainQuery.From("cte2"); - mainQuery.Where("Column3", 5); + [Fact] + public void CombineRaw() + { + var query = new Query("Mobiles").CombineRaw("UNION ALL SELECT * FROM Devices"); - var c = Compile(mainQuery); + var c = Compile(query); - Assert.Equal("WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1),\n[cte2] AS (SELECT [Column3], [Column4] FROM [Table2] \nINNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2)\nSELECT * FROM [cte2] WHERE [Column3] = 5", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM [Mobiles] UNION ALL SELECT * FROM Devices", c[EngineCodes.SqlServer]); + } - Assert.Equal("WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1),\n`cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` \nINNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2)\nSELECT * FROM `cte2` WHERE `Column3` = 5", c[EngineCodes.MySql]); + [Fact] + public void CombineRawWithPlaceholders() + { + var query = new Query("Mobiles").CombineRaw("UNION ALL SELECT * FROM {Devices}"); - Assert.Equal("WITH \"cte1\" AS (SELECT \"Column1\", \"Column2\" FROM \"Table1\" WHERE \"Column2\" = 1),\n\"cte2\" AS (SELECT \"Column3\", \"Column4\" FROM \"Table2\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3\") WHERE \"Column4\" = 2)\nSELECT * FROM \"cte2\" WHERE \"Column3\" = 5", c[EngineCodes.PostgreSql]); + var c = Compile(query); - Assert.Equal("WITH \"CTE1\" AS (SELECT \"COLUMN1\", \"COLUMN2\" FROM \"TABLE1\" WHERE \"COLUMN2\" = 1),\n\"CTE2\" AS (SELECT \"COLUMN3\", \"COLUMN4\" FROM \"TABLE2\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3\") WHERE \"COLUMN4\" = 2)\nSELECT * FROM \"CTE2\" WHERE \"COLUMN3\" = 5", c[EngineCodes.Firebird]); - } + Assert.Equal("SELECT * FROM [Mobiles] UNION ALL SELECT * FROM [Devices]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `Mobiles` UNION ALL SELECT * FROM `Devices`", c[EngineCodes.MySql]); - // test for issue #50 - [Fact] - public void CascadedAndMultiReferencedCteAndBindings() - { - var cte1 = new Query("Table1"); - cte1.Select("Column1", "Column2"); - cte1.Where("Column2", 1); + Assert.Equal("SELECT * FROM \"MOBILES\" UNION ALL SELECT * FROM \"Devices\"", c[EngineCodes.Firebird]); + } - var cte2 = new Query("Table2"); - cte2.With("cte1", cte1); - cte2.Select("Column3", "Column4"); - cte2.Join("cte1", join => join.On("Column1", "Column3")); - cte2.Where("Column4", 2); + [Fact] + public void NestedEmptyWhere() + { + // Empty nested where should be ignored + var query = new Query("A").Where(_ => new Query().Where(_ => new Query().Where(_ => new Query()))); - var cte3 = new Query("Table3"); - cte3.With("cte1", cte1); - cte3.Select("Column3_3", "Column3_4"); - cte3.Join("cte1", join => join.On("Column1", "Column3_3")); - cte3.Where("Column3_4", 33); + var c = Compile(query); - var mainQuery = new Query("Table3"); - mainQuery.With("cte2", cte2); - mainQuery.With("cte3", cte3); - mainQuery.Select("*"); - mainQuery.From("cte2"); - mainQuery.Where("Column3", 5); + Assert.Equal("SELECT * FROM [A]", c[EngineCodes.SqlServer]); + } - var c = Compile(mainQuery); + [Fact] + public void NestedQuery() + { + var query = new Query("A").Where(_ => new Query("B")); - Assert.Equal("WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1),\n[cte2] AS (SELECT [Column3], [Column4] FROM [Table2] \nINNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2),\n[cte3] AS (SELECT [Column3_3], [Column3_4] FROM [Table3] \nINNER JOIN [cte1] ON ([Column1] = [Column3_3]) WHERE [Column3_4] = 33)\nSELECT * FROM [cte2] WHERE [Column3] = 5", c[EngineCodes.SqlServer]); + var c = Compile(query); - Assert.Equal("WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1),\n`cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` \nINNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2),\n`cte3` AS (SELECT `Column3_3`, `Column3_4` FROM `Table3` \nINNER JOIN `cte1` ON (`Column1` = `Column3_3`) WHERE `Column3_4` = 33)\nSELECT * FROM `cte2` WHERE `Column3` = 5", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM [A]", c[EngineCodes.SqlServer]); + } - Assert.Equal("WITH \"cte1\" AS (SELECT \"Column1\", \"Column2\" FROM \"Table1\" WHERE \"Column2\" = 1),\n\"cte2\" AS (SELECT \"Column3\", \"Column4\" FROM \"Table2\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3\") WHERE \"Column4\" = 2),\n\"cte3\" AS (SELECT \"Column3_3\", \"Column3_4\" FROM \"Table3\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3_3\") WHERE \"Column3_4\" = 33)\nSELECT * FROM \"cte2\" WHERE \"Column3\" = 5", c[EngineCodes.PostgreSql]); + [Fact] + public void NestedQueryAfterNestedJoin() + { + // in this test, i am testing the compiler dynamic caching functionality + var query = new Query("users") + .Join("countries", j => j.On("countries.id", "users.country_id")) + .Where(_ => new Query()); + + var c = Compile(query)[EngineCodes.SqlServer]; + + Assert.Equal( + """ + SELECT * FROM [users] + INNER JOIN [countries] ON ([countries].[id] = [users].[country_id]) + """, c.Replace("\n", "\r\n")); + } - Assert.Equal("WITH \"CTE1\" AS (SELECT \"COLUMN1\", \"COLUMN2\" FROM \"TABLE1\" WHERE \"COLUMN2\" = 1),\n\"CTE2\" AS (SELECT \"COLUMN3\", \"COLUMN4\" FROM \"TABLE2\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3\") WHERE \"COLUMN4\" = 2),\n\"CTE3\" AS (SELECT \"COLUMN3_3\", \"COLUMN3_4\" FROM \"TABLE3\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3_3\") WHERE \"COLUMN3_4\" = 33)\nSELECT * FROM \"CTE2\" WHERE \"COLUMN3\" = 5", c[EngineCodes.Firebird]); - } + [Fact] + public void MultipleCte() + { + var q1 = new Query("A"); + var q2 = new Query("B"); + var q3 = new Query("C"); - // test for issue #50 - [Fact] - public void MultipleCtesAndBindings() - { - var cte1 = new Query("Table1"); - cte1.Select("Column1", "Column2"); - cte1.Where("Column2", 1); + var query = new Query("A") + .With("A", q1) + .With("B", q2) + .With("C", q3); - var cte2 = new Query("Table2"); - cte2.Select("Column3", "Column4"); - cte2.Join("cte1", join => join.On("Column1", "Column3")); - cte2.Where("Column4", 2); + var c = Compile(query); - var cte3 = new Query("Table3"); - cte3.Select("Column3_3", "Column3_4"); - cte3.Join("cte1", join => join.On("Column1", "Column3_3")); - cte3.Where("Column3_4", 33); + Assert.Equal( + "WITH [A] AS (SELECT * FROM [A]),\n[B] AS (SELECT * FROM [B]),\n[C] AS (SELECT * FROM [C])\nSELECT * FROM [A]", + c[EngineCodes.SqlServer]); + } - var mainQuery = new Query("Table3"); - mainQuery.With("cte1", cte1); - mainQuery.With("cte2", cte2); - mainQuery.With("cte3", cte3); - mainQuery.Select("*"); - mainQuery.From("cte3"); - mainQuery.Where("Column3_4", 5); + [Fact] + public void CteAndBindings() + { + var query = new Query("Races") + .For("mysql", s => + s.With("range", q => + q.From("seqtbl") + .Select("Id").Where("Id", "<", 33)) + .WhereIn("RaceAuthor", q => q.From("Users") + .Select("Name").Where("Status", "Available") + ) + ) + .For("sqlsrv", s => + s.With("range", + q => q.From("Sequence").Select("Number").Where("Number", "<", 78) + ) + .Limit(25).Offset(20) + ) + .For("postgres", + s => s.With("range", q => q.FromRaw("generate_series(1, 33) as d").Select("d")) + .Where("Name", "3778") + ) + .For("firebird", + s => s.With("range", q => q.FromRaw("generate_series(1, 33) as d").Select("d")) + .Where("Name", "3778") + ) + .Where("Id", ">", 55) + .WhereBetween("Value", 18, 24); + + var c = Compile(query); + + Assert.Equal( + "WITH [range] AS (" + + "SELECT [Number] " + + "FROM [Sequence] " + + "WHERE [Number] < 78)\n" + + "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [Races] WHERE [Id] > 55 AND [Value] BETWEEN 18 AND 24) AS [results_wrapper] WHERE [row_num] BETWEEN 21 AND 45", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "WITH `range` AS (SELECT `Id` FROM `seqtbl` WHERE `Id` < 33)\nSELECT * FROM `Races` WHERE `RaceAuthor` IN (SELECT `Name` FROM `Users` WHERE `Status` = 'Available') AND `Id` > 55 AND `Value` BETWEEN 18 AND 24", + c[EngineCodes.MySql]); + + Assert.Equal( + "WITH \"range\" AS (SELECT \"d\" FROM generate_series(1, 33) as d)\nSELECT * FROM \"Races\" WHERE \"Name\" = '3778' AND \"Id\" > 55 AND \"Value\" BETWEEN 18 AND 24", + c[EngineCodes.PostgreSql]); + + Assert.Equal( + "WITH \"RANGE\" AS (SELECT \"D\" FROM generate_series(1, 33) as d)\nSELECT * FROM \"RACES\" WHERE \"NAME\" = '3778' AND \"ID\" > 55 AND \"VALUE\" BETWEEN 18 AND 24", + c[EngineCodes.Firebird]); + } - var c = Compile(mainQuery); + // test for issue #50 + [Fact] + public void CascadedCteAndBindings() + { + var cte1 = new Query("Table1"); + cte1.Select("Column1", "Column2"); + cte1.Where("Column2", 1); + + var cte2 = new Query("Table2"); + cte2.With("cte1", cte1); + cte2.Select("Column3", "Column4"); + cte2.Join("cte1", join => join.On("Column1", "Column3")); + cte2.Where("Column4", 2); + + var mainQuery = new Query("Table3"); + mainQuery.With("cte2", cte2); + mainQuery.Select("*"); + mainQuery.From("cte2"); + mainQuery.Where("Column3", 5); + + var c = Compile(mainQuery); + + Assert.Equal( + "WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1),\n[cte2] AS (SELECT [Column3], [Column4] FROM [Table2] \nINNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2)\nSELECT * FROM [cte2] WHERE [Column3] = 5", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1),\n`cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` \nINNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2)\nSELECT * FROM `cte2` WHERE `Column3` = 5", + c[EngineCodes.MySql]); + + Assert.Equal( + "WITH \"cte1\" AS (SELECT \"Column1\", \"Column2\" FROM \"Table1\" WHERE \"Column2\" = 1),\n\"cte2\" AS (SELECT \"Column3\", \"Column4\" FROM \"Table2\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3\") WHERE \"Column4\" = 2)\nSELECT * FROM \"cte2\" WHERE \"Column3\" = 5", + c[EngineCodes.PostgreSql]); + + Assert.Equal( + "WITH \"CTE1\" AS (SELECT \"COLUMN1\", \"COLUMN2\" FROM \"TABLE1\" WHERE \"COLUMN2\" = 1),\n\"CTE2\" AS (SELECT \"COLUMN3\", \"COLUMN4\" FROM \"TABLE2\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3\") WHERE \"COLUMN4\" = 2)\nSELECT * FROM \"CTE2\" WHERE \"COLUMN3\" = 5", + c[EngineCodes.Firebird]); + } - Assert.Equal("WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1),\n[cte2] AS (SELECT [Column3], [Column4] FROM [Table2] \nINNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2),\n[cte3] AS (SELECT [Column3_3], [Column3_4] FROM [Table3] \nINNER JOIN [cte1] ON ([Column1] = [Column3_3]) WHERE [Column3_4] = 33)\nSELECT * FROM [cte3] WHERE [Column3_4] = 5", c[EngineCodes.SqlServer]); + // test for issue #50 + [Fact] + public void CascadedAndMultiReferencedCteAndBindings() + { + var cte1 = new Query("Table1"); + cte1.Select("Column1", "Column2"); + cte1.Where("Column2", 1); + + var cte2 = new Query("Table2"); + cte2.With("cte1", cte1); + cte2.Select("Column3", "Column4"); + cte2.Join("cte1", join => join.On("Column1", "Column3")); + cte2.Where("Column4", 2); + + var cte3 = new Query("Table3"); + cte3.With("cte1", cte1); + cte3.Select("Column3_3", "Column3_4"); + cte3.Join("cte1", join => join.On("Column1", "Column3_3")); + cte3.Where("Column3_4", 33); + + var mainQuery = new Query("Table3"); + mainQuery.With("cte2", cte2); + mainQuery.With("cte3", cte3); + mainQuery.Select("*"); + mainQuery.From("cte2"); + mainQuery.Where("Column3", 5); + + var c = Compile(mainQuery); + + Assert.Equal( + """ + WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1), + [cte2] AS (SELECT [Column3], [Column4] FROM [Table2] + INNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2), + [cte3] AS (SELECT [Column3_3], [Column3_4] FROM [Table3] + INNER JOIN [cte1] ON ([Column1] = [Column3_3]) WHERE [Column3_4] = 33) + SELECT * FROM [cte2] WHERE [Column3] = 5 + """, + c[EngineCodes.SqlServer].Replace("\n", "\r\n")); + + Assert.Equal( + """ + WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1), + `cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` + INNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2), + `cte3` AS (SELECT `Column3_3`, `Column3_4` FROM `Table3` + INNER JOIN `cte1` ON (`Column1` = `Column3_3`) WHERE `Column3_4` = 33) + SELECT * FROM `cte2` WHERE `Column3` = 5 + """, + c[EngineCodes.MySql].Replace("\n", "\r\n")); + + Assert.Equal( + """ + WITH "cte1" AS (SELECT "Column1", "Column2" FROM "Table1" WHERE "Column2" = 1), + "cte2" AS (SELECT "Column3", "Column4" FROM "Table2" + INNER JOIN "cte1" ON ("Column1" = "Column3") WHERE "Column4" = 2), + "cte3" AS (SELECT "Column3_3", "Column3_4" FROM "Table3" + INNER JOIN "cte1" ON ("Column1" = "Column3_3") WHERE "Column3_4" = 33) + SELECT * FROM "cte2" WHERE "Column3" = 5 + """, + c[EngineCodes.PostgreSql].Replace("\n", "\r\n")); + + Assert.Equal( + """ + WITH "CTE1" AS (SELECT "COLUMN1", "COLUMN2" FROM "TABLE1" WHERE "COLUMN2" = 1), + "CTE2" AS (SELECT "COLUMN3", "COLUMN4" FROM "TABLE2" + INNER JOIN "CTE1" ON ("COLUMN1" = "COLUMN3") WHERE "COLUMN4" = 2), + "CTE3" AS (SELECT "COLUMN3_3", "COLUMN3_4" FROM "TABLE3" + INNER JOIN "CTE1" ON ("COLUMN1" = "COLUMN3_3") WHERE "COLUMN3_4" = 33) + SELECT * FROM "CTE2" WHERE "COLUMN3" = 5 + """, + c[EngineCodes.Firebird].Replace("\n", "\r\n")); + } - Assert.Equal("WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1),\n`cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` \nINNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2),\n`cte3` AS (SELECT `Column3_3`, `Column3_4` FROM `Table3` \nINNER JOIN `cte1` ON (`Column1` = `Column3_3`) WHERE `Column3_4` = 33)\nSELECT * FROM `cte3` WHERE `Column3_4` = 5", c[EngineCodes.MySql]); + // test for issue #50 + [Fact] + public void MultipleCtesAndBindings() + { + var cte1 = new Query("Table1"); + cte1.Select("Column1", "Column2"); + cte1.Where("Column2", 1); + + var cte2 = new Query("Table2"); + cte2.Select("Column3", "Column4"); + cte2.Join("cte1", join => join.On("Column1", "Column3")); + cte2.Where("Column4", 2); + + var cte3 = new Query("Table3"); + cte3.Select("Column3_3", "Column3_4"); + cte3.Join("cte1", join => join.On("Column1", "Column3_3")); + cte3.Where("Column3_4", 33); + + var mainQuery = new Query("Table3"); + mainQuery.With("cte1", cte1); + mainQuery.With("cte2", cte2); + mainQuery.With("cte3", cte3); + mainQuery.Select("*"); + mainQuery.From("cte3"); + mainQuery.Where("Column3_4", 5); + + var c = Compile(mainQuery); + + Assert.Equal( + "WITH [cte1] AS (SELECT [Column1], [Column2] FROM [Table1] WHERE [Column2] = 1),\n[cte2] AS (SELECT [Column3], [Column4] FROM [Table2] \nINNER JOIN [cte1] ON ([Column1] = [Column3]) WHERE [Column4] = 2),\n[cte3] AS (SELECT [Column3_3], [Column3_4] FROM [Table3] \nINNER JOIN [cte1] ON ([Column1] = [Column3_3]) WHERE [Column3_4] = 33)\nSELECT * FROM [cte3] WHERE [Column3_4] = 5", + c[EngineCodes.SqlServer]); + + Assert.Equal( + "WITH `cte1` AS (SELECT `Column1`, `Column2` FROM `Table1` WHERE `Column2` = 1),\n`cte2` AS (SELECT `Column3`, `Column4` FROM `Table2` \nINNER JOIN `cte1` ON (`Column1` = `Column3`) WHERE `Column4` = 2),\n`cte3` AS (SELECT `Column3_3`, `Column3_4` FROM `Table3` \nINNER JOIN `cte1` ON (`Column1` = `Column3_3`) WHERE `Column3_4` = 33)\nSELECT * FROM `cte3` WHERE `Column3_4` = 5", + c[EngineCodes.MySql]); + + Assert.Equal( + "WITH \"cte1\" AS (SELECT \"Column1\", \"Column2\" FROM \"Table1\" WHERE \"Column2\" = 1),\n\"cte2\" AS (SELECT \"Column3\", \"Column4\" FROM \"Table2\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3\") WHERE \"Column4\" = 2),\n\"cte3\" AS (SELECT \"Column3_3\", \"Column3_4\" FROM \"Table3\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3_3\") WHERE \"Column3_4\" = 33)\nSELECT * FROM \"cte3\" WHERE \"Column3_4\" = 5", + c[EngineCodes.PostgreSql]); + + Assert.Equal( + "WITH \"CTE1\" AS (SELECT \"COLUMN1\", \"COLUMN2\" FROM \"TABLE1\" WHERE \"COLUMN2\" = 1),\n\"CTE2\" AS (SELECT \"COLUMN3\", \"COLUMN4\" FROM \"TABLE2\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3\") WHERE \"COLUMN4\" = 2),\n\"CTE3\" AS (SELECT \"COLUMN3_3\", \"COLUMN3_4\" FROM \"TABLE3\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3_3\") WHERE \"COLUMN3_4\" = 33)\nSELECT * FROM \"CTE3\" WHERE \"COLUMN3_4\" = 5", + c[EngineCodes.Firebird]); + } - Assert.Equal("WITH \"cte1\" AS (SELECT \"Column1\", \"Column2\" FROM \"Table1\" WHERE \"Column2\" = 1),\n\"cte2\" AS (SELECT \"Column3\", \"Column4\" FROM \"Table2\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3\") WHERE \"Column4\" = 2),\n\"cte3\" AS (SELECT \"Column3_3\", \"Column3_4\" FROM \"Table3\" \nINNER JOIN \"cte1\" ON (\"Column1\" = \"Column3_3\") WHERE \"Column3_4\" = 33)\nSELECT * FROM \"cte3\" WHERE \"Column3_4\" = 5", c[EngineCodes.PostgreSql]); - Assert.Equal("WITH \"CTE1\" AS (SELECT \"COLUMN1\", \"COLUMN2\" FROM \"TABLE1\" WHERE \"COLUMN2\" = 1),\n\"CTE2\" AS (SELECT \"COLUMN3\", \"COLUMN4\" FROM \"TABLE2\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3\") WHERE \"COLUMN4\" = 2),\n\"CTE3\" AS (SELECT \"COLUMN3_3\", \"COLUMN3_4\" FROM \"TABLE3\" \nINNER JOIN \"CTE1\" ON (\"COLUMN1\" = \"COLUMN3_3\") WHERE \"COLUMN3_4\" = 33)\nSELECT * FROM \"CTE3\" WHERE \"COLUMN3_4\" = 5", c[EngineCodes.Firebird]); - } + [Fact] + public void Limit() + { + var q = new Query().From("users").Select("id", "name").Limit(10); + var c = Compile(q); + + // Assert.Equal(c[EngineCodes.SqlServer], "SELECT * FROM (SELECT [id], [name],ROW_NUMBER() OVER (SELECT 0) AS [row_num] FROM [users]) AS [temp_table] WHERE [row_num] >= 10"); + Assert.Equal("SELECT TOP (10) [id], [name] FROM [users]", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT `id`, `name` FROM `users` LIMIT 10", c[EngineCodes.MySql]); + Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" LIMIT 10", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT FIRST 10 \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); + } + [Fact] + public void Offset() + { + var q = new Query().From("users").Offset(10); + var c = Compile(q); + + Assert.Equal( + "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] >= 11", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `users` LIMIT 18446744073709551615 OFFSET 10", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM \"users\" OFFSET 10", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT SKIP 10 * FROM \"USERS\"", c[EngineCodes.Firebird]); + } - [Fact] - public void Limit() - { - var q = new Query().From("users").Select("id", "name").Limit(10); - var c = Compile(q); - - // Assert.Equal(c[EngineCodes.SqlServer], "SELECT * FROM (SELECT [id], [name],ROW_NUMBER() OVER (SELECT 0) AS [row_num] FROM [users]) AS [temp_table] WHERE [row_num] >= 10"); - Assert.Equal("SELECT TOP (10) [id], [name] FROM [users]", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT `id`, `name` FROM `users` LIMIT 10", c[EngineCodes.MySql]); - Assert.Equal("SELECT \"id\", \"name\" FROM \"users\" LIMIT 10", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT FIRST 10 \"ID\", \"NAME\" FROM \"USERS\"", c[EngineCodes.Firebird]); - } - - [Fact] - public void Offset() - { - var q = new Query().From("users").Offset(10); - var c = Compile(q); - - Assert.Equal( - "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] >= 11", - c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `users` LIMIT 18446744073709551615 OFFSET 10", c[EngineCodes.MySql]); - Assert.Equal("SELECT * FROM \"users\" OFFSET 10", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT SKIP 10 * FROM \"USERS\"", c[EngineCodes.Firebird]); - } - - [Fact] - public void LimitOffset() - { - var q = new Query().From("users").Offset(10).Limit(5); + [Fact] + public void LimitOffset() + { + var q = new Query().From("users").Offset(10).Limit(5); - var c = Compile(q); + var c = Compile(q); - Assert.Equal( - "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] BETWEEN 11 AND 15", - c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `users` LIMIT 5 OFFSET 10", c[EngineCodes.MySql]); - Assert.Equal("SELECT * FROM \"users\" LIMIT 5 OFFSET 10", c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM \"USERS\" ROWS 11 TO 15", c[EngineCodes.Firebird]); - } + Assert.Equal( + "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] BETWEEN 11 AND 15", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `users` LIMIT 5 OFFSET 10", c[EngineCodes.MySql]); + Assert.Equal("SELECT * FROM \"users\" LIMIT 5 OFFSET 10", c[EngineCodes.PostgreSql]); + Assert.Equal("SELECT * FROM \"USERS\" ROWS 11 TO 15", c[EngineCodes.Firebird]); + } - [Fact] - public void BasicJoin() - { - var q = new Query().From("users").Join("countries", "countries.id", "users.country_id"); - - var c = Compile(q); - - Assert.Equal("SELECT * FROM [users] \nINNER JOIN [countries] ON [countries].[id] = [users].[country_id]", - c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM `users` \nINNER JOIN `countries` ON `countries`.`id` = `users`.`country_id`", - c[EngineCodes.MySql]); - } - - [Theory] - [InlineData("inner join", "INNER JOIN")] - [InlineData("left join", "LEFT JOIN")] - [InlineData("right join", "RIGHT JOIN")] - [InlineData("cross join", "CROSS JOIN")] - public void JoinTypes(string given, string output) - { - var q = new Query().From("users") - .Join("countries", "countries.id", "users.country_id", "=", given); + [Fact] + public void BasicJoin() + { + var q = new Query().From("users").Join("countries", "countries.id", "users.country_id"); - var c = Compile(q); + var c = Compile(q); - Assert.Equal($"SELECT * FROM [users] \n{output} [countries] ON [countries].[id] = [users].[country_id]", - c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM [users] \nINNER JOIN [countries] ON [countries].[id] = [users].[country_id]", + c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM `users` \nINNER JOIN `countries` ON `countries`.`id` = `users`.`country_id`", + c[EngineCodes.MySql]); + } - Assert.Equal($"SELECT * FROM `users` \n{output} `countries` ON `countries`.`id` = `users`.`country_id`", - c[EngineCodes.MySql]); + [Theory] + [InlineData("inner join", "INNER JOIN")] + [InlineData("left join", "LEFT JOIN")] + [InlineData("right join", "RIGHT JOIN")] + [InlineData("cross join", "CROSS JOIN")] + public void JoinTypes(string given, string output) + { + var q = new Query().From("users") + .Join("countries", "countries.id", "users.country_id", "=", given); - Assert.Equal( - $"SELECT * FROM \"users\" \n{output} \"countries\" ON \"countries\".\"id\" = \"users\".\"country_id\"", - c[EngineCodes.PostgreSql]); + var c = Compile(q); - Assert.Equal( - $"SELECT * FROM \"USERS\" \n{output} \"COUNTRIES\" ON \"COUNTRIES\".\"ID\" = \"USERS\".\"COUNTRY_ID\"", - c[EngineCodes.Firebird]); - } + Assert.Equal($"SELECT * FROM [users] \n{output} [countries] ON [countries].[id] = [users].[country_id]", + c[EngineCodes.SqlServer]); - [Fact] - public void OrWhereRawEscaped() - { - var query = new Query("Table").WhereRaw("[MyCol] = ANY(?::int\\[\\])", "{1,2,3}"); + Assert.Equal($"SELECT * FROM `users` \n{output} `countries` ON `countries`.`id` = `users`.`country_id`", + c[EngineCodes.MySql]); - var c = Compile(query); + Assert.Equal( + $"SELECT * FROM \"users\" \n{output} \"countries\" ON \"countries\".\"id\" = \"users\".\"country_id\"", + c[EngineCodes.PostgreSql]); - Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = ANY('{1,2,3}'::int[])", c[EngineCodes.PostgreSql]); - } + Assert.Equal( + $"SELECT * FROM \"USERS\" \n{output} \"COUNTRIES\" ON \"COUNTRIES\".\"ID\" = \"USERS\".\"COUNTRY_ID\"", + c[EngineCodes.Firebird]); + } - [Fact] - public void Having() - { - var q = new Query("Table1") - .Having("Column1", ">", 1); - var c = Compile(q); + [Fact] + public void OrWhereRawEscaped() + { + var query = new Query("Table").WhereRaw("[MyCol] = ANY(?::int\\[\\])", "{1,2,3}"); - Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1", c[EngineCodes.SqlServer]); - } + var c = Compile(query); - [Fact] - public void MultipleHaving() - { - var q = new Query("Table1") - .Having("Column1", ">", 1) - .Having("Column2", "=", 1); - var c = Compile(q); + Assert.Equal("SELECT * FROM \"Table\" WHERE \"MyCol\" = ANY('{1,2,3}'::int[])", c[EngineCodes.PostgreSql]); + } - Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1 AND [Column2] = 1", c[EngineCodes.SqlServer]); - } + [Fact] + public void Having() + { + var q = new Query("Table1") + .Having("Column1", ">", 1); + var c = Compile(q); - [Fact] - public void MultipleOrHaving() - { - var q = new Query("Table1") - .Having("Column1", ">", 1) - .OrHaving("Column2", "=", 1); - var c = Compile(q); + Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1", c[EngineCodes.SqlServer]); + } - Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1 OR [Column2] = 1", c[EngineCodes.SqlServer]); - } + [Fact] + public void MultipleHaving() + { + var q = new Query("Table1") + .Having("Column1", ">", 1) + .Having("Column2", "=", 1); + var c = Compile(q); - [Fact] - public void ShouldUseILikeOnPostgresWhenNonCaseSensitive() - { - var q = new Query("Table1") - .WhereLike("Column1", "%Upper Word%", false); - var c = Compile(q); + Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1 AND [Column2] = 1", c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%upper word%'", c[EngineCodes.SqlServer]); - Assert.Equal("SELECT * FROM \"Table1\" WHERE \"Column1\" ilike '%Upper Word%'", c[EngineCodes.PostgreSql]); - } + [Fact] + public void MultipleOrHaving() + { + var q = new Query("Table1") + .Having("Column1", ">", 1) + .OrHaving("Column2", "=", 1); + var c = Compile(q); - [Fact] - public void EscapedWhereLike() - { - var q = new Query("Table1") - .WhereLike("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal("SELECT * FROM [Table1] HAVING [Column1] > 1 OR [Column2] = 1", c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like 'teststring\%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void ShouldUseILikeOnPostgresWhenNonCaseSensitive() + { + var q = new Query("Table1") + .WhereLike("Column1", "%Upper Word%"); + var c = Compile(q); - [Fact] - public void EscapedWhereStarts() - { - var q = new Query("Table1") - .WhereStarts("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%upper word%'", c[EngineCodes.SqlServer]); + Assert.Equal("SELECT * FROM \"Table1\" WHERE \"Column1\" ilike '%Upper Word%'", c[EngineCodes.PostgreSql]); + } - Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like 'teststring\%%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedWhereLike() + { + var q = new Query("Table1") + .WhereLike("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedWhereEnds() - { - var q = new Query("Table1") - .WhereEnds("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like 'teststring\%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%teststring\%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedWhereStarts() + { + var q = new Query("Table1") + .WhereStarts("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedWhereContains() - { - var q = new Query("Table1") - .WhereContains("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like 'teststring\%%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%teststring\%%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedWhereEnds() + { + var q = new Query("Table1") + .WhereEnds("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedHavingLike() - { - var q = new Query("Table1") - .HavingLike("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%teststring\%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like 'teststring\%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedWhereContains() + { + var q = new Query("Table1") + .WhereContains("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedHavingStarts() - { - var q = new Query("Table1") - .HavingStarts("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] WHERE LOWER([Column1]) like '%teststring\%%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like 'teststring\%%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedHavingLike() + { + var q = new Query("Table1") + .HavingLike("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedHavingEnds() - { - var q = new Query("Table1") - .HavingEnds("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like 'teststring\%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like '%teststring\%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedHavingStarts() + { + var q = new Query("Table1") + .HavingStarts("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapedHavingContains() - { - var q = new Query("Table1") - .HavingContains("Column1", @"TestString\%", false, @"\"); - var c = Compile(q); + Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like 'teststring\%%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like '%teststring\%%' ESCAPE '\'", c[EngineCodes.SqlServer]); - } + [Fact] + public void EscapedHavingEnds() + { + var q = new Query("Table1") + .HavingEnds("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void EscapeClauseThrowsForMultipleCharacters() - { - Assert.ThrowsAny(() => - { - var q = new Query("Table1") - .HavingContains("Column1", @"TestString\%", false, @"\aa"); - }); - } + Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like '%teststring\%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } + [Fact] + public void EscapedHavingContains() + { + var q = new Query("Table1") + .HavingContains("Column1", @"TestString\%", false, '\\'); + var c = Compile(q); - [Fact] - public void BasicSelectRaw_WithNoTable() - { - var q = new Query().SelectRaw("somefunction() as c1"); + Assert.Equal(@"SELECT * FROM [Table1] HAVING LOWER([Column1]) like '%teststring\%%' ESCAPE '\'", + c[EngineCodes.SqlServer]); + } - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT somefunction() as c1", c.ToString()); - } + [Fact] + public void BasicSelectRaw_WithNoTable() + { + var q = new Query().SelectRaw("somefunction() as c1"); - [Fact] - public void BasicSelect_WithNoTable() - { - var q = new Query().Select("c1"); - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [c1]", c.ToString()); - } + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT somefunction() as c1", c.ToString()); + } - [Fact] - public void BasicSelect_WithNoTableAndWhereClause() - { - var q = new Query().Select("c1").Where("p", 1); - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [c1] WHERE [p] = 1", c.ToString()); - } + [Fact] + public void BasicSelect_WithNoTable() + { + var q = new Query().Select("c1"); + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [c1]", c.ToString()); + } - [Fact] - public void BasicSelect_WithNoTableWhereRawClause() - { - var q = new Query().Select("c1").WhereRaw("1 = 1"); - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [c1] WHERE 1 = 1", c.ToString()); - } + [Fact] + public void BasicSelect_WithNoTableAndWhereClause() + { + var q = new Query().Select("c1").Where("p", 1); + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [c1] WHERE [p] = 1", c.ToString()); + } - [Fact] - public void BasicSelectAggregate() - { - var q = new Query("Posts").Select("Title") - .SelectAggregate("sum", "ViewCount"); + [Fact] + public void BasicSelect_WithNoTableWhereRawClause() + { + var q = new Query().Select("c1").WhereRaw("1 = 1"); + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [c1] WHERE 1 = 1", c.ToString()); + } - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); - } + [Fact] + public void BasicSelectAggregate() + { + var q = new Query("Posts").Select("Title") + .SelectAggregate("sum", "ViewCount"); - [Fact] - public void SelectAggregateShouldIgnoreEmptyFilter() - { - var q = new Query("Posts").Select("Title") - .SelectAggregate("sum", "ViewCount", q => q); + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); + } - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); - } + [Fact] + public void SelectAggregateShouldIgnoreEmptyFilter() + { + var q = new Query("Posts").Select("Title") + .SelectAggregate("sum", "ViewCount", q => q); - [Fact] - public void SelectAggregateShouldIgnoreEmptyQueryFilter() - { - var q = new Query("Posts").Select("Title") - .SelectAggregate("sum", "ViewCount", new Query()); + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); + } - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); - } + [Fact] + public void SelectAggregateShouldIgnoreEmptyQueryFilter() + { + var q = new Query("Posts").Select("Title") + .SelectAggregate("sum", "ViewCount", new Query()); - [Fact] - public void BasicSelectAggregateWithAlias() - { - var q = new Query("Posts").Select("Title") - .SelectAggregate("sum", "ViewCount as TotalViews"); + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [Title], SUM([ViewCount]) FROM [Posts]", sqlServer.ToString()); + } - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [Title], SUM([ViewCount]) AS [TotalViews] FROM [Posts]", sqlServer.ToString()); - } + [Fact] + public void BasicSelectAggregateWithAlias() + { + var q = new Query("Posts").Select("Title") + .SelectAggregate("sum", "ViewCount as TotalViews"); - [Fact] - public void SelectWithFilter() - { - var q = new Query("Posts").Select("Title") - .SelectAggregate("sum", "ViewCount as Published_Jan", q => q.Where("Published_Month", "Jan")) - .SelectAggregate("sum", "ViewCount as Published_Feb", q => q.Where("Published_Month", "Feb")); + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal("SELECT [Title], SUM([ViewCount]) AS [TotalViews] FROM [Posts]", sqlServer.ToString()); + } - var pgSql = Compilers.CompileFor(EngineCodes.PostgreSql, q); - Assert.Equal("SELECT \"Title\", SUM(\"ViewCount\") FILTER (WHERE \"Published_Month\" = 'Jan') AS \"Published_Jan\", SUM(\"ViewCount\") FILTER (WHERE \"Published_Month\" = 'Feb') AS \"Published_Feb\" FROM \"Posts\"", pgSql.ToString()); + [Fact] + public void SelectWithFilter() + { + var q = new Query("Posts").Select("Title") + .SelectAggregate("sum", "ViewCount as Published_Jan", q => q.Where("Published_Month", "Jan")) + .SelectAggregate("sum", "ViewCount as Published_Feb", q => q.Where("Published_Month", "Feb")); + + var pgSql = Compilers.CompileFor(EngineCodes.PostgreSql, q); + Assert.Equal( + """ + SELECT "Title", SUM("ViewCount") FILTER (WHERE "Published_Month" = 'Jan') AS "Published_Jan", SUM("ViewCount") FILTER (WHERE "Published_Month" = 'Feb') AS "Published_Feb" FROM "Posts" + """, + pgSql.ToString()); + + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal( + "SELECT [Title], SUM(CASE WHEN [Published_Month] = 'Jan' THEN [ViewCount] END) AS [Published_Jan], SUM(CASE WHEN [Published_Month] = 'Feb' THEN [ViewCount] END) AS [Published_Feb] FROM [Posts]", + sqlServer.ToString()); + } - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT [Title], SUM(CASE WHEN [Published_Month] = 'Jan' THEN [ViewCount] END) AS [Published_Jan], SUM(CASE WHEN [Published_Month] = 'Feb' THEN [ViewCount] END) AS [Published_Feb] FROM [Posts]", sqlServer.ToString()); - } + [Fact] + public void SelectWithExists() + { + var q = new Query("Posts").WhereExists( + new Query("Comments").WhereColumns("Comments.PostId", "=", "Posts.Id") + ); + + var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal( + "SELECT * FROM [Posts] WHERE EXISTS (SELECT 1 FROM [Comments] WHERE [Comments].[PostId] = [Posts].[Id])", + sqlServer.ToString()); + } - [Fact] - public void SelectWithExists() - { - var q = new Query("Posts").WhereExists( - new Query("Comments").WhereColumns("Comments.PostId", "=", "Posts.Id") - ); + [Fact] + public void SelectWithExists_OmitSelectIsFalse() + { + var q = new Query("Posts").WhereExists( + new Query("Comments").Select("Id").WhereColumns("Comments.PostId", "=", "Posts.Id") + ); - var sqlServer = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal("SELECT * FROM [Posts] WHERE EXISTS (SELECT 1 FROM [Comments] WHERE [Comments].[PostId] = [Posts].[Id])", sqlServer.ToString()); - } - [Fact] - public void SelectWithExists_OmitSelectIsFalse() + var compiler = new SqlServerCompiler { - var q = new Query("Posts").WhereExists( - new Query("Comments").Select("Id").WhereColumns("Comments.PostId", "=", "Posts.Id") - ); - - - var compiler = new SqlServerCompiler - { - OmitSelectInsideExists = false, - }; - - var sqlServer = compiler.Compile(q).ToString(); - Assert.Equal("SELECT * FROM [Posts] WHERE EXISTS (SELECT [Id] FROM [Comments] WHERE [Comments].[PostId] = [Posts].[Id])", sqlServer.ToString()); - } + OmitSelectInsideExists = false + }; + var sqlServer = compiler.Compile(q).ToString(); + Assert.Equal( + "SELECT * FROM [Posts] WHERE EXISTS (SELECT [Id] FROM [Comments] WHERE [Comments].[PostId] = [Posts].[Id])", + sqlServer); } } diff --git a/QueryBuilder.Tests/SqlServer/NestedSelectTests.cs b/QueryBuilder.Tests/SqlServer/NestedSelectTests.cs index 4c591ba2..2b91dbd4 100644 --- a/QueryBuilder.Tests/SqlServer/NestedSelectTests.cs +++ b/QueryBuilder.Tests/SqlServer/NestedSelectTests.cs @@ -1,64 +1,62 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.SqlServer -{ - public class NestedSelectTests : TestSupport - { - private readonly SqlServerCompiler compiler; +namespace SqlKata.Tests.SqlServer; - public NestedSelectTests() - { - compiler = Compilers.Get(EngineCodes.SqlServer); - } - - [Fact] - public void Compile_RawSql_WithLimit_ReturnsCorrectQuery() - { - var q = new Query().From("Foo as src").Limit(1); +public class NestedSelectTests : TestSupport +{ + private readonly SqlServerCompiler _compiler; - var actual = compiler.Compile(q).ToString(); - Assert.Contains("SELECT TOP (1) * FROM [Foo]", actual); - } + public NestedSelectTests() + { + _compiler = Compilers.Get(EngineCodes.SqlServer); + } - [Fact] - public void SqlCompile_QueryAadNestedLimit_ReturnsQueryWithTop() - { - var q = new Query().From("Foo as src").Select("MyData"); - var n = new Query().From("Bar").Limit(1).Select("MyData"); - q.Select(n, "Bar"); + [Fact] + public void Compile_RawSql_WithLimit_ReturnsCorrectQuery() + { + var q = new Query().From("Foo as src").Limit(1); - var actual = compiler.Compile(q).ToString(); - Assert.Contains("SELECT TOP (1) [MyData] FROM [Bar]", actual); - Assert.Contains("SELECT [MyData], (SELECT TOP (1) [MyData] FROM [Bar]) AS [Bar] FROM [Foo] AS [src]", - actual); - } + var actual = _compiler.Compile(q).ToString(); + Assert.Contains("SELECT TOP (1) * FROM [Foo]", actual); + } - [Fact] - public void SqlCompile_QueryLimitAndNestedLimit_ReturnsQueryWithTop() - { - var q = new Query().From("Foo as src").Limit(1).Select("MyData"); - var n = new Query().From("Bar").Limit(1).Select("MyData"); - q.Select(n, "Bar"); + [Fact] + public void SqlCompile_QueryAadNestedLimit_ReturnsQueryWithTop() + { + var q = new Query().From("Foo as src").Select("MyData"); + var n = new Query().From("Bar").Limit(1).Select("MyData"); + q.Select(n, "Bar"); + + var actual = _compiler.Compile(q).ToString(); + Assert.Contains("SELECT TOP (1) [MyData] FROM [Bar]", actual); + Assert.Contains("SELECT [MyData], (SELECT TOP (1) [MyData] FROM [Bar]) AS [Bar] FROM [Foo] AS [src]", + actual); + } + [Fact] + public void SqlCompile_QueryLimitAndNestedLimit_ReturnsQueryWithTop() + { + var q = new Query().From("Foo as src").Limit(1).Select("MyData"); + var n = new Query().From("Bar").Limit(1).Select("MyData"); + q.Select(n, "Bar"); - var actual = compiler.Compile(q).ToString(); - Assert.Contains( - "SELECT TOP (1) [MyData], (SELECT TOP (1) [MyData] FROM [Bar]) AS [Bar] FROM [Foo] AS [src]", actual); - } - [Fact] - public void SqlCompile_QueryLimitAndNestedLimit_BindingValue() - { - var n = new Query().From("Bar"); - var q = new Query().From("Foo").Where("x", true).WhereNotExists(n); - // var q = new Query().From("Foo").Where("C", "c").WhereExists(n).Where("A", "a"); + var actual = _compiler.Compile(q).ToString(); + Assert.Contains( + "SELECT TOP (1) [MyData], (SELECT TOP (1) [MyData] FROM [Bar]) AS [Bar] FROM [Foo] AS [src]", actual); + } - var actual = compiler.Compile(q).ToString(); - Assert.Contains("SELECT * FROM [Foo] WHERE [x] = cast(1 as bit) AND NOT EXISTS (SELECT 1 FROM [Bar])", - actual); - // Assert.Contains("SELECT * FROM [Foo] WHERE [C] = 'c' AND EXISTS (SELECT TOP (1) 1 FROM [Bar]) AND [A] = 'a'", actual); - } + [Fact] + public void SqlCompile_QueryLimitAndNestedLimit_BindingValue() + { + var n = new Query().From("Bar"); + var q = new Query().From("Foo").Where("x", true).WhereNotExists(n); + // var q = new Query().From("Foo").Where("C", "c").WhereExists(n).Where("A", "a"); + + var actual = _compiler.Compile(q).ToString(); + Assert.Contains("SELECT * FROM [Foo] WHERE [x] = cast(1 as bit) AND NOT EXISTS (SELECT 1 FROM [Bar])", + actual); + // Assert.Contains("SELECT * FROM [Foo] WHERE [C] = 'c' AND EXISTS (SELECT TOP (1) 1 FROM [Bar]) AND [A] = 'a'", actual); } } diff --git a/QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs b/QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs index 85493d2f..d6608329 100644 --- a/QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs +++ b/QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs @@ -1,78 +1,75 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.SqlServer +namespace SqlKata.Tests.SqlServer; + +public sealed class SqlServerLegacyLimitTests { - public class SqlServerLegacyLimitTests : TestSupport + private readonly SqlServerCompiler _compiler = new() { - private readonly SqlServerCompiler compiler; - - public SqlServerLegacyLimitTests() - { - compiler = Compilers.Get(EngineCodes.SqlServer); - compiler.UseLegacyPagination = true; - } - - [Fact] - public void NoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; - - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void LimitOnly() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; + UseLegacyPagination = true + }; - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void OffsetOnly() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void NoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM [Table]"); + } - Assert.Null(compiler.CompileLimit(ctx)); - } + [Fact] + public void LimitOnly() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be("SELECT TOP (10) * FROM [Table]"); + } - [Fact] - public void LimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void OffsetOnly() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM (SELECT *, ROW_NUMBER() " + + "OVER (ORDER BY (SELECT 0)) AS [row_num] " + + "FROM [Table]) AS [results_wrapper] " + + "WHERE [row_num] >= 21"); + } - Assert.Null(compiler.CompileLimit(ctx)); - } + [Fact] + public void LimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM (SELECT *, ROW_NUMBER() " + + "OVER (ORDER BY (SELECT 0)) AS [row_num] " + + "FROM [Table]) AS [results_wrapper] " + + "WHERE [row_num] BETWEEN 21 AND 25"); + } - [Fact] - public void ShouldEmulateOrderByIfNoOrderByProvided() - { - var query = new Query("Table").Limit(5).Offset(20); + [Fact] + public void ShouldEmulateOrderByIfNoOrderByProvided() + { + var query = new Query("Table").Limit(5).Offset(20); - Assert.Contains("ORDER BY (SELECT 0)", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY (SELECT 0)", _compiler.Compile(query).ToString()); + } - [Fact] - public void ShouldKeepTheOrdersAsIsIfNoPaginationProvided() - { - var query = new Query("Table").OrderBy("Id"); + [Fact] + public void ShouldKeepTheOrdersAsIsIfNoPaginationProvided() + { + var query = new Query("Table").OrderBy("Id"); - Assert.Contains("ORDER BY [Id]", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY [Id]", _compiler.Compile(query).ToString()); + } - [Fact] - public void ShouldKeepTheOrdersAsIsIfPaginationProvided() - { - var query = new Query("Table").Offset(10).Limit(20).OrderBy("Id"); + [Fact] + public void ShouldKeepTheOrdersAsIsIfPaginationProvided() + { + var query = new Query("Table").Offset(10).Limit(20).OrderBy("Id"); - Assert.Contains("ORDER BY [Id]", compiler.Compile(query).ToString()); - Assert.DoesNotContain("(SELECT 0)", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY [Id]", _compiler.Compile(query).ToString()); + Assert.DoesNotContain("(SELECT 0)", _compiler.Compile(query).ToString()); } } diff --git a/QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs b/QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs index 1e54413c..35b91b64 100644 --- a/QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs +++ b/QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs @@ -1,88 +1,68 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.SqlServer -{ - public class SqlServerLimitTests : TestSupport - { - private readonly SqlServerCompiler compiler; - - public SqlServerLimitTests() - { - compiler = Compilers.Get(EngineCodes.SqlServer); - compiler.UseLegacyPagination = false; - } - - [Fact] - public void NoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; - - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void LimitOnly() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; +namespace SqlKata.Tests.SqlServer; - Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx)); - Assert.Equal(2, ctx.Bindings.Count); - Assert.Equal(0L, ctx.Bindings[0]); - Assert.Equal(10, ctx.Bindings[1]); - } - - [Fact] - public void OffsetOnly() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; - - Assert.EndsWith("OFFSET ? ROWS", compiler.CompileLimit(ctx)); +public sealed class SqlServerLimitTests +{ + private readonly SqlServerCompiler _compiler = new(); - Assert.Single(ctx.Bindings); - Assert.Equal(20L, ctx.Bindings[0]); - } + [Fact] + public void NoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM [Table]"); + } - [Fact] - public void LimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void LimitOnly() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM [Table] ORDER BY (SELECT 0) " + + "OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"); + } - Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx)); + [Fact] + public void OffsetOnly() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM [Table] ORDER BY (SELECT 0) OFFSET 20 ROWS"); + } - Assert.Equal(2, ctx.Bindings.Count); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Equal(5, ctx.Bindings[1]); - } + [Fact] + public void LimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("SELECT * FROM [Table] ORDER BY (SELECT 0) " + + "OFFSET 20 ROWS FETCH NEXT 5 ROWS ONLY"); + } - [Fact] - public void ShouldEmulateOrderByIfNoOrderByProvided() - { - var query = new Query("Table").Limit(5).Offset(20); + [Fact] + public void ShouldEmulateOrderByIfNoOrderByProvided() + { + var query = new Query("Table").Limit(5).Offset(20); - Assert.Contains("ORDER BY (SELECT 0)", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY (SELECT 0)", _compiler.Compile(query).ToString()); + } - [Fact] - public void ShouldKeepTheOrdersAsIsIfNoPaginationProvided() - { - var query = new Query("Table").OrderBy("Id"); + [Fact] + public void ShouldKeepTheOrdersAsIsIfNoPaginationProvided() + { + var query = new Query("Table").OrderBy("Id"); - Assert.Contains("ORDER BY [Id]", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY [Id]", _compiler.Compile(query).ToString()); + } - [Fact] - public void ShouldKeepTheOrdersAsIsIfPaginationProvided() - { - var query = new Query("Table").Offset(10).Limit(20).OrderBy("Id"); + [Fact] + public void ShouldKeepTheOrdersAsIsIfPaginationProvided() + { + var query = new Query("Table").Offset(10).Limit(20).OrderBy("Id"); - Assert.Contains("ORDER BY [Id]", compiler.Compile(query).ToString()); - Assert.DoesNotContain("(SELECT 0)", compiler.Compile(query).ToString()); - } + Assert.Contains("ORDER BY [Id]", _compiler.Compile(query).ToString()); + Assert.DoesNotContain("(SELECT 0)", _compiler.Compile(query).ToString()); } } diff --git a/QueryBuilder.Tests/SqlServer/SqlServerTests.cs b/QueryBuilder.Tests/SqlServer/SqlServerTests.cs index 3adb84f5..4099fb5c 100644 --- a/QueryBuilder.Tests/SqlServer/SqlServerTests.cs +++ b/QueryBuilder.Tests/SqlServer/SqlServerTests.cs @@ -1,62 +1,60 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.SqlServer +namespace SqlKata.Tests.SqlServer; + +public class SqlServerTests : TestSupport { - public class SqlServerTests : TestSupport + private readonly SqlServerCompiler _compiler; + + public SqlServerTests() + { + _compiler = Compilers.Get(EngineCodes.SqlServer); + } + + + [Fact] + public void SqlServerTop() + { + var query = new Query("table").Limit(1); + var result = _compiler.Compile(query); + Assert.Equal("SELECT TOP (@p0) * FROM [table]", result.Sql); + } + + [Fact] + public void SqlServerTopWithDistinct() + { + var query = new Query("table").Limit(1).Distinct(); + var result = _compiler.Compile(query); + Assert.Equal("SELECT DISTINCT TOP (@p0) * FROM [table]", result.Sql); + } + + + [Theory] + [InlineData(-100)] + [InlineData(0)] + public void OffsetSqlServer_Should_Be_Ignored_If_Zero_Or_Negative(int offset) + { + var q = new Query().From("users").Offset(offset); + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + + Assert.Equal("SELECT * FROM [users]", c.ToString()); + } + + + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(100)] + [InlineData(1000000)] + public void OffsetSqlServer_Should_Be_Incremented_By_One(int offset) { - private readonly SqlServerCompiler compiler; - - public SqlServerTests() - { - compiler = Compilers.Get(EngineCodes.SqlServer); - } - - - [Fact] - public void SqlServerTop() - { - var query = new Query("table").Limit(1); - var result = compiler.Compile(query); - Assert.Equal("SELECT TOP (@p0) * FROM [table]", result.Sql); - } - - [Fact] - public void SqlServerTopWithDistinct() - { - var query = new Query("table").Limit(1).Distinct(); - var result = compiler.Compile(query); - Assert.Equal("SELECT DISTINCT TOP (@p0) * FROM [table]", result.Sql); - } - - - [Theory()] - [InlineData(-100)] - [InlineData(0)] - public void OffsetSqlServer_Should_Be_Ignored_If_Zero_Or_Negative(int offset) - { - var q = new Query().From("users").Offset(offset); - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - - Assert.Equal("SELECT * FROM [users]", c.ToString()); - } - - - [Theory()] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(100)] - [InlineData(1000000)] - public void OffsetSqlServer_Should_Be_Incremented_By_One(int offset) - { - var q = new Query().From("users").Offset(offset); - var c = Compilers.CompileFor(EngineCodes.SqlServer, q); - Assert.Equal( - "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] >= " + - (offset + 1), c.ToString()); - } + var q = new Query().From("users").Offset(offset); + var c = Compilers.CompileFor(EngineCodes.SqlServer, q); + Assert.Equal( + "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [users]) AS [results_wrapper] WHERE [row_num] >= " + + (offset + 1), c.ToString()); } } diff --git a/QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs b/QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs index 047605df..c67bf1ec 100644 --- a/QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs +++ b/QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs @@ -1,58 +1,43 @@ +using FluentAssertions; using SqlKata.Compilers; -using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests.Sqlite -{ - public class SqliteLimitTests : TestSupport - { - private readonly SqliteCompiler compiler; - - public SqliteLimitTests() - { - compiler = Compilers.Get(EngineCodes.Sqlite); - } - - [Fact] - public void WithNoLimitNorOffset() - { - var query = new Query("Table"); - var ctx = new SqlResult { Query = query }; +namespace SqlKata.Tests.Sqlite; - Assert.Null(compiler.CompileLimit(ctx)); - } - - [Fact] - public void WithNoOffset() - { - var query = new Query("Table").Limit(10); - var ctx = new SqlResult { Query = query }; - - Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx)); - Assert.Equal(10, ctx.Bindings[0]); - } +public class SqliteLimitTests +{ + private readonly SqliteCompiler _compiler = new(); - [Fact] - public void WithNoLimit() - { - var query = new Query("Table").Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimitNorOffset() + { + var query = new Query("Table"); + _compiler.Compile(query).ToString().Should() + .Be(""" + SELECT * FROM "Table" + """); + } - Assert.Equal("LIMIT -1 OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(20L, ctx.Bindings[0]); - Assert.Single(ctx.Bindings); - } + [Fact] + public void WithNoOffset() + { + var query = new Query("Table").Limit(10); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" LIMIT 10"""); + } - [Fact] - public void WithLimitAndOffset() - { - var query = new Query("Table").Limit(5).Offset(20); - var ctx = new SqlResult { Query = query }; + [Fact] + public void WithNoLimit() + { + var query = new Query("Table").Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" LIMIT -1 OFFSET 20"""); + } - Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx)); - Assert.Equal(5, ctx.Bindings[0]); - Assert.Equal(20L, ctx.Bindings[1]); - Assert.Equal(2, ctx.Bindings.Count); - } + [Fact] + public void WithLimitAndOffset() + { + var query = new Query("Table").Limit(5).Offset(20); + _compiler.Compile(query).ToString().Should() + .Be("""SELECT * FROM "Table" LIMIT 5 OFFSET 20"""); } } diff --git a/QueryBuilder.Tests/UpdateTests.cs b/QueryBuilder.Tests/UpdateTests.cs index bf3dd7d9..42ac5ab8 100644 --- a/QueryBuilder.Tests/UpdateTests.cs +++ b/QueryBuilder.Tests/UpdateTests.cs @@ -1,319 +1,317 @@ -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.Dynamic; -using System.Linq; +using JetBrains.Annotations; using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class UpdateTests : TestSupport { - public class UpdateTests : TestSupport + [Fact] + public void UpdateObject() { - private class Book + var query = new Query("Table").AsUpdate(new { - public Book(string name, string author, decimal price = 1.0m, string color = null) - { - this.Name = name ?? throw new ArgumentNullException(nameof(name)); - this.BookPrice = price; - this.color = color; - this.BookAuthor = author; - } + Name = "The User", + Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) + }); - public string Name { get; set; } + var c = Compile(query); - [Column("Author")] - public string BookAuthor { get; set; } + Assert.Equal( + "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", + c[EngineCodes.SqlServer]); - [Column("Price")] - public decimal BookPrice { get; set; } + Assert.Equal( + "UPDATE \"TABLE\" SET \"NAME\" = 'The User', \"AGE\" = '2018-01-01'", + c[EngineCodes.Firebird]); + } - [Ignore] - public string color { get; set; } - } + [Fact] + public void UpdateWithNullValues() + { + var query = new Query("Books").Where("Id", 1).AsUpdate( + new[] { "Author", "Date", "Version" }, + new object?[] { "Author 1", null, null } + ); - private class OrderProductComposite - { - public OrderProductComposite(string orderid, string productid, int quantity) - { - OrderId = orderid; - ProductId = productid; - Quantity = quantity; - Foo = "baz"; - } + var c = Compile(query); - [Key("OrdId")] - public string OrderId { get; set; } + Assert.Equal( + "UPDATE [Books] SET [Author] = 'Author 1', [Date] = NULL, [Version] = NULL WHERE [Id] = 1", + c[EngineCodes.SqlServer]); - [Key] - public string ProductId { get; set; } + Assert.Equal( + "UPDATE \"BOOKS\" SET \"AUTHOR\" = 'Author 1', \"DATE\" = NULL, \"VERSION\" = NULL WHERE \"ID\" = 1", + c[EngineCodes.Firebird]); + } - public int Quantity { get; set; } + [Fact] + public void UpdateWithEmptyString() + { + var query = new Query("Books").Where("Id", 1).AsUpdate( + new[] { "Author", "Description" }, + new object[] { "Author 1", "" } + ); - [Column("Faa")] - public string Foo { get; set; } - } + var c = Compile(query); - [Fact] - public void UpdateObject() - { - var query = new Query("Table").AsUpdate(new + Assert.Equal("UPDATE [Books] SET [Author] = 'Author 1', [Description] = '' WHERE [Id] = 1", + c[EngineCodes.SqlServer]); + + Assert.Equal("UPDATE \"BOOKS\" SET \"AUTHOR\" = 'Author 1', \"DESCRIPTION\" = '' WHERE \"ID\" = 1", + c[EngineCodes.Firebird]); + } + + [Fact] + public void UpdateWithCte() + { + var now = DateTime.UtcNow.ToString("yyyy-MM-dd"); + + var query = new Query("Books") + .With("OldBooks", q => q.From("Books").Where("Date", "<", now)) + .Where("Price", ">", 100) + .AsUpdate(new Dictionary { - Name = "The User", - Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc), + { "Price", "150" } }); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", - c[EngineCodes.SqlServer]); - - Assert.Equal( - "UPDATE \"TABLE\" SET \"NAME\" = 'The User', \"AGE\" = '2018-01-01'", - c[EngineCodes.Firebird]); - } + Assert.Equal( + $"WITH [OldBooks] AS " + + $"(SELECT * FROM [Books] WHERE [Date] < '{now}')\n" + + $"UPDATE [Books] SET [Price] = '150' " + + $"WHERE [Price] > 100", + c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateWithNullValues() - { - var query = new Query("Books").Where("Id", 1).AsUpdate( - new[] { "Author", "Date", "Version" }, - new object[] { "Author 1", null, null } - ); + [Fact] + public void UpdateWithIgnoreAndColumnProperties() + { + var book = new Book("SqlKataBook", "Kata", color: "red", price: 100m); + var query = new Query("Book").AsUpdate(book); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "UPDATE [Books] SET [Author] = 'Author 1', [Date] = NULL, [Version] = NULL WHERE [Id] = 1", - c[EngineCodes.SqlServer]); + Assert.Equal( + "UPDATE [Book] SET [Name] = 'SqlKataBook', [Author] = 'Kata', [Price] = 100", + c[EngineCodes.SqlServer]); - Assert.Equal( - "UPDATE \"BOOKS\" SET \"AUTHOR\" = 'Author 1', \"DATE\" = NULL, \"VERSION\" = NULL WHERE \"ID\" = 1", - c[EngineCodes.Firebird]); - } + Assert.Equal( + "UPDATE \"BOOK\" SET \"NAME\" = 'SqlKataBook', \"AUTHOR\" = 'Kata', \"PRICE\" = 100", + c[EngineCodes.Firebird]); + } - [Fact] - public void UpdateWithEmptyString() - { - var query = new Query("Books").Where("Id", 1).AsUpdate( - new[] { "Author", "Description" }, - new object[] { "Author 1", "" } - ); + [Fact] + public void UpdateWithKeyAttribute() + { + var order = new OrderProductComposite("ORD01", "PROD02", 20); + var query = new Query("OrderProductComposite").AsUpdate(order); - var c = Compile(query); + var c = Compile(query); - Assert.Equal("UPDATE [Books] SET [Author] = 'Author 1', [Description] = '' WHERE [Id] = 1", c[EngineCodes.SqlServer]); + Assert.Equal( + "UPDATE [OrderProductComposite] SET [OrdId] = 'ORD01', [ProductId] = 'PROD02', [Quantity] = 20, [Faa] = 'baz' WHERE [OrdId] = 'ORD01' AND [ProductId] = 'PROD02'", + c[EngineCodes.SqlServer]); - Assert.Equal("UPDATE \"BOOKS\" SET \"AUTHOR\" = 'Author 1', \"DESCRIPTION\" = '' WHERE \"ID\" = 1", c[EngineCodes.Firebird]); - } + Assert.Equal( + // ReSharper disable StringLiteralTypo + """UPDATE "ORDERPRODUCTCOMPOSITE" SET "ORDID" = 'ORD01', "PRODUCTID" = 'PROD02', "QUANTITY" = 20, "FAA" = 'baz' WHERE "ORDID" = 'ORD01' AND "PRODUCTID" = 'PROD02'""", + // ReSharper restore StringLiteralTypo + c[EngineCodes.Firebird]); + } - [Fact] - public void UpdateWithCte() + [Fact] + public void UpdateFromRaw() + { + var query = new Query().FromRaw("Table.With.Dots").AsUpdate(new { - var now = DateTime.UtcNow.ToString("yyyy-MM-dd"); + Name = "The User" + }); - var query = new Query("Books") - .With("OldBooks", q => q.From("Books").Where("Date", "<", now)) - .Where("Price", ">", 100) - .AsUpdate(new Dictionary - { - {"Price", "150"} - }); + var c = Compile(query); - var c = Compile(query); - - Assert.Equal( - $"WITH [OldBooks] AS (SELECT * FROM [Books] WHERE [Date] < '{now}')\nUPDATE [Books] SET [Price] = '150' WHERE [Price] > 100", - c[EngineCodes.SqlServer]); - } + Assert.Equal( + "UPDATE Table.With.Dots SET [Name] = 'The User'", + c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateWithIgnoreAndColumnProperties() + [Fact] + public void UpdateFromQueryShouldFail() + { + var query = new Query().From(new Query("InnerTable")).AsUpdate(new { - var book = new Book(name: $"SqlKataBook", author: "Kata", color: $"red", price: 100m); - var query = new Query("Book").AsUpdate(book); + Name = "The User" + }); - var c = Compile(query); + Assert.Throws(() => { Compile(query); }); + } - Assert.Equal( - "UPDATE [Book] SET [Name] = 'SqlKataBook', [Author] = 'Kata', [Price] = 100", - c[EngineCodes.SqlServer]); + [Fact] + public void update_should_compile_literal_without_parameters_holders() + { + var query = new Query("MyTable").AsUpdate(new + { + Name = "The User", + Address = new UnsafeLiteral("@address") + }); - Assert.Equal( - "UPDATE \"BOOK\" SET \"NAME\" = 'SqlKataBook', \"AUTHOR\" = 'Kata', \"PRICE\" = 100", - c[EngineCodes.Firebird]); - } + var compiler = new SqlServerCompiler(); + var result = compiler.Compile(query); - [Fact] - public void UpdateWithKeyAttribute() - { - var order = new OrderProductComposite("ORD01", "PROD02", 20); - var query = new Query("OrderProductComposite").AsUpdate(order); + Assert.Equal( + "UPDATE [MyTable] SET [Name] = ?, [Address] = @address", + result.RawSql); + } - var c = Compile(query); + [Fact] + public void UpdateUsingKeyValuePairs() + { + var dictionaryUser = new Dictionary + { + { "Name", "The User" }, + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } + } + .ToArray(); - Assert.Equal( - "UPDATE [OrderProductComposite] SET [OrdId] = 'ORD01', [ProductId] = 'PROD02', [Quantity] = 20, [Faa] = 'baz' WHERE [OrdId] = 'ORD01' AND [ProductId] = 'PROD02'", - c[EngineCodes.SqlServer]); + var query = new Query("Table") + .AsUpdate(dictionaryUser); - Assert.Equal( - "UPDATE \"ORDERPRODUCTCOMPOSITE\" SET \"ORDID\" = 'ORD01', \"PRODUCTID\" = 'PROD02', \"QUANTITY\" = 20, \"FAA\" = 'baz' WHERE \"ORDID\" = 'ORD01' AND \"PRODUCTID\" = 'PROD02'", - c[EngineCodes.Firebird]); - } + var c = Compile(query); + + Assert.Equal( + "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", + c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateFromRaw() + [Fact] + public void UpdateUsingDictionary() + { + var dictionaryUser = new Dictionary { - var query = new Query().FromRaw("Table.With.Dots").AsUpdate(new - { - Name = "The User", - }); + { "Name", "The User" }, + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } + }; - var c = Compile(query); + var query = new Query("Table") + .AsUpdate(dictionaryUser); - Assert.Equal( - "UPDATE Table.With.Dots SET [Name] = 'The User'", - c[EngineCodes.SqlServer]); - } + var c = Compile(query); - [Fact] - public void UpdateFromQueryShouldFail() - { - var query = new Query().From(new Query("InnerTable")).AsUpdate(new - { - Name = "The User", - }); + Assert.Equal( + "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", + c[EngineCodes.SqlServer]); + } - Assert.Throws(() => + [Fact] + public void UpdateUsingReadOnlyDictionary() + { + var dictionaryUser = new ReadOnlyDictionary( + new Dictionary { - Compile(query); + { "Name", "The User" }, + { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) } }); - } - [Fact] - public void update_should_compile_literal_without_parameters_holders() - { - var query = new Query("MyTable").AsUpdate(new - { - Name = "The User", - Address = new UnsafeLiteral("@address") - }); + var query = new Query("Table") + .AsUpdate(dictionaryUser); - var compiler = new SqlServerCompiler(); - var result = compiler.Compile(query); + var c = Compile(query); - Assert.Equal( - "UPDATE [MyTable] SET [Name] = ?, [Address] = @address", - result.RawSql); - } + Assert.Equal( + "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", + c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateUsingKeyValuePairs() - { - var dictionaryUser = new Dictionary - { - { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - } - .ToArray(); + [Fact] + public void UpdateUsingExpandoObject() + { + dynamic expandoUser = new ExpandoObject(); + expandoUser.Name = "The User"; + expandoUser.Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); - var query = new Query("Table") - .AsUpdate(dictionaryUser); + var query = new Query("Table") + .AsUpdate(expandoUser); - var c = Compile(query); + var c = Compile(query); - Assert.Equal( - "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", - c[EngineCodes.SqlServer]); - } + Assert.Equal( + "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", + c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateUsingDictionary() - { - var dictionaryUser = new Dictionary { - { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - }; + [Fact] + public void IncrementUpdate() + { + var query = new Query("Table").AsIncrement("Total"); + var c = Compile(query); + Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 1", c[EngineCodes.SqlServer]); + } - var query = new Query("Table") - .AsUpdate(dictionaryUser); + [Fact] + public void IncrementUpdateWithValue() + { + var query = new Query("Table").AsIncrement("Total", 2); + var c = Compile(query); + Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 2", c[EngineCodes.SqlServer]); + } - var c = Compile(query); + [Fact] + public void IncrementUpdateWithWheres() + { + var query = new Query("Table").Where("Name", "A").AsIncrement("Total", 2); + var c = Compile(query); + Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 2 WHERE [Name] = 'A'", c[EngineCodes.SqlServer]); + } - Assert.Equal( - "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", - c[EngineCodes.SqlServer]); - } + [Fact] + public void DecrementUpdate() + { + var query = new Query("Table").Where("Name", "A").AsDecrement("Total", 2); + var c = Compile(query); + Assert.Equal("UPDATE [Table] SET [Total] = [Total] - 2 WHERE [Name] = 'A'", c[EngineCodes.SqlServer]); + } - [Fact] - public void UpdateUsingReadOnlyDictionary() + [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] + private class Book + { + public Book(string name, string author, decimal price = 1.0m, string? color = null) { - var dictionaryUser = new ReadOnlyDictionary( - new Dictionary - { - { "Name", "The User" }, - { "Age", new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc) }, - }); - - var query = new Query("Table") - .AsUpdate(dictionaryUser); - - var c = Compile(query); - - Assert.Equal( - "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", - c[EngineCodes.SqlServer]); + Name = name ?? throw new ArgumentNullException(nameof(name)); + BookPrice = price; + Color = color; + BookAuthor = author; } - [Fact] - public void UpdateUsingExpandoObject() - { - dynamic expandoUser = new ExpandoObject(); - expandoUser.Name = "The User"; - expandoUser.Age = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc); + public string Name { get; set; } - var query = new Query("Table") - .AsUpdate(expandoUser); + [Column("Author")] public string BookAuthor { get; set; } - var c = Compile(query); + [Column("Price")] public decimal BookPrice { get; set; } - Assert.Equal( - "UPDATE [Table] SET [Name] = 'The User', [Age] = '2018-01-01'", - c[EngineCodes.SqlServer]); - } + [Ignore] public string? Color { get; set; } + } - [Fact] - public void IncrementUpdate() + [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] + private class OrderProductComposite + { + public OrderProductComposite(string orderId, string productId, int quantity) { - var query = new Query("Table").AsIncrement("Total"); - var c = Compile(query); - Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 1", c[EngineCodes.SqlServer]); + OrderIdRenamed = orderId; + ProductId = productId; + Quantity = quantity; + Foo = "baz"; } - [Fact] - public void IncrementUpdateWithValue() - { - var query = new Query("Table").AsIncrement("Total", 2); - var c = Compile(query); - Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 2", c[EngineCodes.SqlServer]); - } + // ReSharper disable once ExplicitCallerInfoArgument + [Key("OrdId")] public string OrderIdRenamed { get; set; } - [Fact] - public void IncrementUpdateWithWheres() - { - var query = new Query("Table").Where("Name", "A").AsIncrement("Total", 2); - var c = Compile(query); - Assert.Equal("UPDATE [Table] SET [Total] = [Total] + 2 WHERE [Name] = 'A'", c[EngineCodes.SqlServer]); - } + [Key] public string ProductId { get; set; } - [Fact] - public void DecrementUpdate() - { - var query = new Query("Table").Where("Name", "A").AsDecrement("Total", 2); - var c = Compile(query); - Assert.Equal("UPDATE [Table] SET [Total] = [Total] - 2 WHERE [Name] = 'A'", c[EngineCodes.SqlServer]); - } + public int Quantity { get; set; } + + [Column("Faa")] public string Foo { get; set; } } } diff --git a/QueryBuilder.Tests/WhereTests.cs b/QueryBuilder.Tests/WhereTests.cs index 0c1254b2..0efab851 100644 --- a/QueryBuilder.Tests/WhereTests.cs +++ b/QueryBuilder.Tests/WhereTests.cs @@ -1,33 +1,38 @@ using SqlKata.Compilers; using SqlKata.Tests.Infrastructure; -using Xunit; -namespace SqlKata.Tests +namespace SqlKata.Tests; + +public class WhereTests : TestSupport { - public class WhereTests : TestSupport + [Fact] + public void GroupedWhereFilters() { - [Fact] - public void GroupedWhereFilters() - { - var q = new Query("Table1") - .Where(q => q.Or().Where("Column1", 10).Or().Where("Column2", 20)) - .Where("Column3", 30); + var q = new Query("T") + .Where(q => q.Or().Where("A", 10).Or().Where("B", 20)) + .Where(q => q.And().Where("C", 30).Where("D", 40)) + .Where("E", 50); - var c = Compile(q); + var c = Compile(q); - Assert.Equal(@"SELECT * FROM ""Table1"" WHERE (""Column1"" = 10 OR ""Column2"" = 20) AND ""Column3"" = 30", c[EngineCodes.PostgreSql]); - } + Assert.Equal("SELECT * FROM [T] " + + "WHERE ([A] = 10 OR [B] = 20) " + + "AND ([C] = 30 AND [D] = 40) " + + "AND [E] = 50", + c[EngineCodes.SqlServer]); + } - [Fact] - public void GroupedHavingFilters() - { - var q = new Query("Table1") - .Having(q => q.Or().HavingRaw("SUM([Column1]) = ?", 10).Or().HavingRaw("SUM([Column2]) = ?", 20)) - .HavingRaw("SUM([Column3]) = ?", 30); + [Fact] + public void GroupedHavingFilters() + { + var q = new Query("Table1") + .Having(q => q.Or().HavingRaw("SUM([Column1]) = ?", 10).Or().HavingRaw("SUM([Column2]) = ?", 20)) + .HavingRaw("SUM([Column3]) = ?", 30); - var c = Compile(q); + var c = Compile(q); - Assert.Equal(@"SELECT * FROM ""Table1"" HAVING (SUM(""Column1"") = 10 OR SUM(""Column2"") = 20) AND SUM(""Column3"") = 30", c[EngineCodes.PostgreSql]); - } + Assert.Equal( + @"SELECT * FROM ""Table1"" HAVING (SUM(""Column1"") = 10 OR SUM(""Column2"") = 20) AND SUM(""Column3"") = 30", + c[EngineCodes.PostgreSql]); } } diff --git a/QueryBuilder/Base.Where.cs b/QueryBuilder/Base.Where.cs deleted file mode 100644 index c40cc40a..00000000 --- a/QueryBuilder/Base.Where.cs +++ /dev/null @@ -1,699 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SqlKata -{ - public abstract partial class BaseQuery - { - public Q Where(string column, string op, object value) - { - - // If the value is "null", we will just assume the developer wants to add a - // where null clause to the query. So, we will allow a short-cut here to - // that method for convenience so the developer doesn't have to check. - if (value == null) - { - return Not(op != "=").WhereNull(column); - } - - if (value is bool boolValue) - { - if (op != "=") - { - Not(); - } - - return boolValue ? WhereTrue(column) : WhereFalse(column); - } - - return AddComponent("where", new BasicCondition - { - Column = column, - Operator = op, - Value = value, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNot(string column, string op, object value) - { - return Not().Where(column, op, value); - } - - public Q OrWhere(string column, string op, object value) - { - return Or().Where(column, op, value); - } - - public Q OrWhereNot(string column, string op, object value) - { - return this.Or().Not().Where(column, op, value); - } - - public Q Where(string column, object value) - { - return Where(column, "=", value); - } - public Q WhereNot(string column, object value) - { - return WhereNot(column, "=", value); - } - public Q OrWhere(string column, object value) - { - return OrWhere(column, "=", value); - } - public Q OrWhereNot(string column, object value) - { - return OrWhereNot(column, "=", value); - } - - /// - /// Perform a where constraint - /// - /// - /// - public Q Where(object constraints) - { - var dictionary = new Dictionary(); - - foreach (var item in constraints.GetType().GetRuntimeProperties()) - { - dictionary.Add(item.Name, item.GetValue(constraints)); - } - - return Where(dictionary); - } - - public Q Where(IEnumerable> values) - { - var query = (Q)this; - var orFlag = GetOr(); - var notFlag = GetNot(); - - foreach (var tuple in values) - { - if (orFlag) - { - query = query.Or(); - } - else - { - query.And(); - } - - query = this.Not(notFlag).Where(tuple.Key, tuple.Value); - } - - return query; - } - - public Q WhereRaw(string sql, params object[] bindings) - { - return AddComponent("where", new RawCondition - { - Expression = sql, - Bindings = bindings, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q OrWhereRaw(string sql, params object[] bindings) - { - return Or().WhereRaw(sql, bindings); - } - - /// - /// Apply a nested where clause - /// - /// - /// - public Q Where(Func callback) - { - var query = callback.Invoke(NewChild()); - - // omit empty queries - if (!query.Clauses.Where(x => x.Component == "where").Any()) - { - return (Q)this; - } - - return AddComponent("where", new NestedCondition - { - Query = query, - IsNot = GetNot(), - IsOr = GetOr(), - }); - } - - public Q WhereNot(Func callback) - { - return Not().Where(callback); - } - - public Q OrWhere(Func callback) - { - return Or().Where(callback); - } - - public Q OrWhereNot(Func callback) - { - return Not().Or().Where(callback); - } - - public Q WhereColumns(string first, string op, string second) - { - return AddComponent("where", new TwoColumnsCondition - { - First = first, - Second = second, - Operator = op, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q OrWhereColumns(string first, string op, string second) - { - return Or().WhereColumns(first, op, second); - } - - public Q WhereNull(string column) - { - return AddComponent("where", new NullCondition - { - Column = column, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNotNull(string column) - { - return Not().WhereNull(column); - } - - public Q OrWhereNull(string column) - { - return this.Or().WhereNull(column); - } - - public Q OrWhereNotNull(string column) - { - return Or().Not().WhereNull(column); - } - - public Q WhereTrue(string column) - { - return AddComponent("where", new BooleanCondition - { - Column = column, - Value = true, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q OrWhereTrue(string column) - { - return Or().WhereTrue(column); - } - - public Q WhereFalse(string column) - { - return AddComponent("where", new BooleanCondition - { - Column = column, - Value = false, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q OrWhereFalse(string column) - { - return Or().WhereFalse(column); - } - - public Q WhereLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return AddComponent("where", new BasicStringCondition - { - Operator = "like", - Column = column, - Value = value, - CaseSensitive = caseSensitive, - EscapeCharacter = escapeCharacter, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNotLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Not().WhereLike(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().WhereLike(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereNotLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().Not().WhereLike(column, value, caseSensitive, escapeCharacter); - } - public Q WhereStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return AddComponent("where", new BasicStringCondition - { - Operator = "starts", - Column = column, - Value = value, - CaseSensitive = caseSensitive, - EscapeCharacter = escapeCharacter, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNotStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Not().WhereStarts(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().WhereStarts(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereNotStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().Not().WhereStarts(column, value, caseSensitive, escapeCharacter); - } - - public Q WhereEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return AddComponent("where", new BasicStringCondition - { - Operator = "ends", - Column = column, - Value = value, - CaseSensitive = caseSensitive, - EscapeCharacter = escapeCharacter, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNotEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Not().WhereEnds(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().WhereEnds(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereNotEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().Not().WhereEnds(column, value, caseSensitive, escapeCharacter); - } - - public Q WhereContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return AddComponent("where", new BasicStringCondition - { - Operator = "contains", - Column = column, - Value = value, - CaseSensitive = caseSensitive, - EscapeCharacter = escapeCharacter, - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - - public Q WhereNotContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Not().WhereContains(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().WhereContains(column, value, caseSensitive, escapeCharacter); - } - - public Q OrWhereNotContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) - { - return Or().Not().WhereContains(column, value, caseSensitive, escapeCharacter); - } - - public Q WhereBetween(string column, T lower, T higher) - { - return AddComponent("where", new BetweenCondition - { - Column = column, - IsOr = GetOr(), - IsNot = GetNot(), - Lower = lower, - Higher = higher - }); - } - - public Q OrWhereBetween(string column, T lower, T higher) - { - return Or().WhereBetween(column, lower, higher); - } - public Q WhereNotBetween(string column, T lower, T higher) - { - return Not().WhereBetween(column, lower, higher); - } - public Q OrWhereNotBetween(string column, T lower, T higher) - { - return Or().Not().WhereBetween(column, lower, higher); - } - - public Q WhereIn(string column, IEnumerable values) - { - - // If the developer has passed a string they most likely want a List - // since string is considered as List - if (values is string) - { - string val = values as string; - - return AddComponent("where", new InCondition - { - Column = column, - IsOr = GetOr(), - IsNot = GetNot(), - Values = new List { val } - }); - } - - return AddComponent("where", new InCondition - { - Column = column, - IsOr = GetOr(), - IsNot = GetNot(), - Values = values.Distinct().ToList() - }); - - - } - - public Q OrWhereIn(string column, IEnumerable values) - { - return Or().WhereIn(column, values); - } - - public Q WhereNotIn(string column, IEnumerable values) - { - return Not().WhereIn(column, values); - } - - public Q OrWhereNotIn(string column, IEnumerable values) - { - return Or().Not().WhereIn(column, values); - } - - - public Q WhereIn(string column, Query query) - { - return AddComponent("where", new InQueryCondition - { - Column = column, - IsOr = GetOr(), - IsNot = GetNot(), - Query = query, - }); - } - public Q WhereIn(string column, Func callback) - { - var query = callback.Invoke(new Query().SetParent(this)); - - return WhereIn(column, query); - } - - public Q OrWhereIn(string column, Query query) - { - return Or().WhereIn(column, query); - } - - public Q OrWhereIn(string column, Func callback) - { - return Or().WhereIn(column, callback); - } - public Q WhereNotIn(string column, Query query) - { - return Not().WhereIn(column, query); - } - - public Q WhereNotIn(string column, Func callback) - { - return Not().WhereIn(column, callback); - } - - public Q OrWhereNotIn(string column, Query query) - { - return Or().Not().WhereIn(column, query); - } - - public Q OrWhereNotIn(string column, Func callback) - { - return Or().Not().WhereIn(column, callback); - } - - - /// - /// Perform a sub query where clause - /// - /// - /// - /// - /// - public Q Where(string column, string op, Func callback) - { - var query = callback.Invoke(NewChild()); - - return Where(column, op, query); - } - - public Q Where(string column, string op, Query query) - { - return AddComponent("where", new QueryCondition - { - Column = column, - Operator = op, - Query = query, - IsNot = GetNot(), - IsOr = GetOr(), - }); - } - - public Q WhereSub(Query query, object value) - { - return WhereSub(query, "=", value); - } - - public Q WhereSub(Query query, string op, object value) - { - return AddComponent("where", new SubQueryCondition - { - Value = value, - Operator = op, - Query = query, - IsNot = GetNot(), - IsOr = GetOr(), - }); - } - - public Q OrWhereSub(Query query, object value) - { - return Or().WhereSub(query, value); - } - - public Q OrWhereSub(Query query, string op, object value) - { - return Or().WhereSub(query, op, value); - } - - public Q OrWhere(string column, string op, Query query) - { - return Or().Where(column, op, query); - } - public Q OrWhere(string column, string op, Func callback) - { - return Or().Where(column, op, callback); - } - - public Q WhereExists(Query query) - { - if (!query.HasComponent("from")) - { - throw new ArgumentException($"'{nameof(FromClause)}' cannot be empty if used inside a '{nameof(WhereExists)}' condition"); - } - - return AddComponent("where", new ExistsCondition - { - Query = query, - IsNot = GetNot(), - IsOr = GetOr(), - }); - } - public Q WhereExists(Func callback) - { - var childQuery = new Query().SetParent(this); - return WhereExists(callback.Invoke(childQuery)); - } - - public Q WhereNotExists(Query query) - { - return Not().WhereExists(query); - } - - public Q WhereNotExists(Func callback) - { - return Not().WhereExists(callback); - } - - public Q OrWhereExists(Query query) - { - return Or().WhereExists(query); - } - public Q OrWhereExists(Func callback) - { - return Or().WhereExists(callback); - } - public Q OrWhereNotExists(Query query) - { - return Or().Not().WhereExists(query); - } - public Q OrWhereNotExists(Func callback) - { - return Or().Not().WhereExists(callback); - } - - #region date - public Q WhereDatePart(string part, string column, string op, object value) - { - return AddComponent("where", new BasicDateCondition - { - Operator = op, - Column = column, - Value = value, - Part = part?.ToLowerInvariant(), - IsOr = GetOr(), - IsNot = GetNot(), - }); - } - public Q WhereNotDatePart(string part, string column, string op, object value) - { - return Not().WhereDatePart(part, column, op, value); - } - - public Q OrWhereDatePart(string part, string column, string op, object value) - { - return Or().WhereDatePart(part, column, op, value); - } - - public Q OrWhereNotDatePart(string part, string column, string op, object value) - { - return Or().Not().WhereDatePart(part, column, op, value); - } - - public Q WhereDate(string column, string op, object value) - { - return WhereDatePart("date", column, op, value); - } - public Q WhereNotDate(string column, string op, object value) - { - return Not().WhereDate(column, op, value); - } - public Q OrWhereDate(string column, string op, object value) - { - return Or().WhereDate(column, op, value); - } - public Q OrWhereNotDate(string column, string op, object value) - { - return Or().Not().WhereDate(column, op, value); - } - - public Q WhereTime(string column, string op, object value) - { - return WhereDatePart("time", column, op, value); - } - public Q WhereNotTime(string column, string op, object value) - { - return Not().WhereTime(column, op, value); - } - public Q OrWhereTime(string column, string op, object value) - { - return Or().WhereTime(column, op, value); - } - public Q OrWhereNotTime(string column, string op, object value) - { - return Or().Not().WhereTime(column, op, value); - } - - public Q WhereDatePart(string part, string column, object value) - { - return WhereDatePart(part, column, "=", value); - } - public Q WhereNotDatePart(string part, string column, object value) - { - return WhereNotDatePart(part, column, "=", value); - } - - public Q OrWhereDatePart(string part, string column, object value) - { - return OrWhereDatePart(part, column, "=", value); - } - - public Q OrWhereNotDatePart(string part, string column, object value) - { - return OrWhereNotDatePart(part, column, "=", value); - } - - public Q WhereDate(string column, object value) - { - return WhereDate(column, "=", value); - } - public Q WhereNotDate(string column, object value) - { - return WhereNotDate(column, "=", value); - } - public Q OrWhereDate(string column, object value) - { - return OrWhereDate(column, "=", value); - } - public Q OrWhereNotDate(string column, object value) - { - return OrWhereNotDate(column, "=", value); - } - - public Q WhereTime(string column, object value) - { - return WhereTime(column, "=", value); - } - public Q WhereNotTime(string column, object value) - { - return WhereNotTime(column, "=", value); - } - public Q OrWhereTime(string column, object value) - { - return OrWhereTime(column, "=", value); - } - public Q OrWhereNotTime(string column, object value) - { - return OrWhereNotTime(column, "=", value); - } - - #endregion - } -} diff --git a/QueryBuilder/BaseQuery.cs b/QueryBuilder/BaseQuery.cs deleted file mode 100644 index 86b44a23..00000000 --- a/QueryBuilder/BaseQuery.cs +++ /dev/null @@ -1,310 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace SqlKata -{ - public abstract class AbstractQuery - { - public AbstractQuery Parent; - } - - public abstract partial class BaseQuery : AbstractQuery where Q : BaseQuery - { - public List Clauses { get; set; } = new List(); - - private bool orFlag = false; - private bool notFlag = false; - public string EngineScope = null; - - public Q SetEngineScope(string engine) - { - this.EngineScope = engine; - - return (Q)this; - } - - public BaseQuery() - { - } - - /// - /// Return a cloned copy of the current query. - /// - /// - public virtual Q Clone() - { - var q = NewQuery(); - - q.Clauses = this.Clauses.Select(x => x.Clone()).ToList(); - - return q; - } - - public Q SetParent(AbstractQuery parent) - { - if (this == parent) - { - throw new ArgumentException($"Cannot set the same {nameof(AbstractQuery)} as a parent of itself"); - } - - this.Parent = parent; - return (Q)this; - } - - public abstract Q NewQuery(); - - public Q NewChild() - { - var newQuery = NewQuery().SetParent((Q)this); - newQuery.EngineScope = this.EngineScope; - return newQuery; - } - - /// - /// Add a component clause to the query. - /// - /// - /// - /// - /// - public Q AddComponent(string component, AbstractClause clause, string engineCode = null) - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - clause.Engine = engineCode; - clause.Component = component; - Clauses.Add(clause); - - return (Q)this; - } - - /// - /// If the query already contains a clause for the given component - /// and engine, replace it with the specified clause. Otherwise, just - /// add the clause. - /// - /// - /// - /// - /// - public Q AddOrReplaceComponent(string component, AbstractClause clause, string engineCode = null) - { - engineCode = engineCode ?? EngineScope; - - var current = GetComponents(component).SingleOrDefault(c => c.Engine == engineCode); - if (current != null) - Clauses.Remove(current); - - return AddComponent(component, clause, engineCode); - } - - - - /// - /// Get the list of clauses for a component. - /// - /// - public List GetComponents(string component, string engineCode = null) where C : AbstractClause - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - var clauses = Clauses - .Where(x => x.Component == component) - .Where(x => engineCode == null || x.Engine == null || engineCode == x.Engine) - .Cast(); - - return clauses.ToList(); - } - - /// - /// Get the list of clauses for a component. - /// - /// - /// - /// - public List GetComponents(string component, string engineCode = null) - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - return GetComponents(component, engineCode); - } - - /// - /// Get a single component clause from the query. - /// - /// - public C GetOneComponent(string component, string engineCode = null) where C : AbstractClause - { - engineCode = engineCode ?? EngineScope; - - var all = GetComponents(component, engineCode); - return all.FirstOrDefault(c => c.Engine == engineCode) ?? all.FirstOrDefault(c => c.Engine == null); - } - - /// - /// Get a single component clause from the query. - /// - /// - /// - /// - public AbstractClause GetOneComponent(string component, string engineCode = null) - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - return GetOneComponent(component, engineCode); - } - - /// - /// Return whether the query has clauses for a component. - /// - /// - /// - /// - public bool HasComponent(string component, string engineCode = null) - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - return GetComponents(component, engineCode).Any(); - } - - /// - /// Remove all clauses for a component. - /// - /// - /// - /// - public Q ClearComponent(string component, string engineCode = null) - { - if (engineCode == null) - { - engineCode = EngineScope; - } - - Clauses = Clauses - .Where(x => !(x.Component == component && (engineCode == null || x.Engine == null || engineCode == x.Engine))) - .ToList(); - - return (Q)this; - } - - /// - /// Set the next boolean operator to "and" for the "where" clause. - /// - /// - protected Q And() - { - orFlag = false; - return (Q)this; - } - - /// - /// Set the next boolean operator to "or" for the "where" clause. - /// - /// - public Q Or() - { - orFlag = true; - return (Q)this; - } - - /// - /// Set the next "not" operator for the "where" clause. - /// - /// - public Q Not(bool flag = true) - { - notFlag = flag; - return (Q)this; - } - - /// - /// Get the boolean operator and reset it to "and" - /// - /// - protected bool GetOr() - { - var ret = orFlag; - - // reset the flag - orFlag = false; - return ret; - } - - /// - /// Get the "not" operator and clear it - /// - /// - protected bool GetNot() - { - var ret = notFlag; - - // reset the flag - notFlag = false; - return ret; - } - - /// - /// Add a from Clause - /// - /// - /// - public Q From(string table) - { - return AddOrReplaceComponent("from", new FromClause - { - Table = table, - }); - } - - public Q From(Query query, string alias = null) - { - query = query.Clone(); - query.SetParent((Q)this); - - if (alias != null) - { - query.As(alias); - }; - - return AddOrReplaceComponent("from", new QueryFromClause - { - Query = query - }); - } - - public Q FromRaw(string sql, params object[] bindings) - { - return AddOrReplaceComponent("from", new RawFromClause - { - Expression = sql, - Bindings = bindings, - }); - } - - public Q From(Func callback, string alias = null) - { - var query = new Query(); - - query.SetParent((Q)this); - - return From(callback.Invoke(query), alias); - } - - } -} diff --git a/QueryBuilder/BindingExtensions.cs b/QueryBuilder/BindingExtensions.cs new file mode 100644 index 00000000..c89191f1 --- /dev/null +++ b/QueryBuilder/BindingExtensions.cs @@ -0,0 +1,162 @@ +using System.Collections; +using System.Globalization; +using System.Text; +using SqlKata.Compilers; + +namespace SqlKata +{ + public static class BindingExtensions + { + private static readonly Type[] NumberTypes = + { + typeof(int), + typeof(long), + typeof(decimal), + typeof(double), + typeof(float), + typeof(short), + typeof(ushort), + typeof(ulong) + }; + + /// + /// For example replaces "... WHERE `Id` in (?)" -> "... WHERE `Id` in (?,?,?)" + /// + public static string ExpandParameters(string sql, string placeholder, object?[] bindings) + { + return ReplaceAll(sql, placeholder, i => + { + if (bindings[i]?.AsArray() is not { } arr) return placeholder; + + var count = arr.Cast().Count(); + return string.Join(",", placeholder.Repeat(count)); + + }); + } + public static string ReplaceAll(string subject, string match, Func replace) + { + if (string.IsNullOrWhiteSpace(subject) || !subject.Contains(match)) return subject; + + var split = subject.Split( + new[] { match }, + StringSplitOptions.None + ); + + return split.Skip(1) + .Select((item, index) => replace(index) + item) + .Aggregate(new StringBuilder(split.First()), (prev, right) => prev.Append(right)) + .ToString(); + } + public static string BindArgs(this IReadOnlyList bindings, string rawSql) + { + var deepParameters = bindings.FlattenOneLevel().ToList(); + + return ReplaceAll(rawSql, "?", i => + { + if (i >= deepParameters.Count) + throw new Exception( + $"Failed to retrieve a binding at index {i}, the total bindings count is {bindings.Count}"); + + return ChangeToSqlValue(deepParameters[i]); + }); + + + static string ChangeToSqlValue(object? value) + { + if (value == null) return "NULL"; + + if (AsArray(value) is { } arr) + return arr.StrJoin(","); + + if (NumberTypes.Contains(value.GetType())) + return Convert.ToString(value, CultureInfo.InvariantCulture)!; + + if (value is DateTime date) + { + if (date.Date == date) return "'" + date.ToString("yyyy-MM-dd") + "'"; + + return "'" + date.ToString("yyyy-MM-dd HH:mm:ss") + "'"; + } + + if (value is bool vBool) return vBool ? "true" : "false"; + + if (value is Enum vEnum) return Convert.ToInt32(vEnum) + $" /* {vEnum} */"; + + // fallback to string + return "'" + value.ToString()!.Replace("'", "''") + "'"; + } + } + public static Dictionary GenerateNamedBindings(this IEnumerable bindings, string parameterPrefix) + { + return bindings.FlattenOneLevel().Select((v, i) => new { i, v }) + .ToDictionary(x => parameterPrefix + x.i, x => x.v); + } + + public static IEnumerable? AsArray(this object value) + { + if (value is string) return null; + + if (value is byte[]) return null; + + return value as IEnumerable; + } + + /// + /// {1, { 2, 3, {4}}, 5} -> { 1, 2, 3, {4}, 5} + /// + public static IEnumerable FlattenOneLevel(this IEnumerable array) + { + foreach (var item in array) + if (item?.AsArray() is { } arr) + foreach (var sub in arr) + { + if (sub == null) + throw new InvalidOperationException( + "Sub-item cannot be null!"); + yield return (T)sub; + } + else + yield return item; + } + + + public static void RenderSqlValue(this StringBuilder sb, object? value) + { + if (value == null) + { + sb.Append("NULL"); + } + else if (AsArray(value) is { } arr) + { + sb.RenderList(",", arr.Cast()); + } + else if (NumberTypes.Contains(value.GetType())) + { + sb.Append(value); + } + else if (value is DateTime date) + { + sb.Append('\''); + sb.Append(date.Date == date + ? date.ToString("yyyy-MM-dd") + : date.ToString("yyyy-MM-dd HH:mm:ss")); + sb.Append('\''); + + } + else if (value is bool b) + { + sb.Append(b ? "true" : "false"); + } + else if (value is Enum e) + { + sb.Append(Convert.ToInt32(e) + $" /* {e} */"); + } + else + { + sb.Append('\''); + sb.Append(value.ToString()!.Replace("'", "''")); + sb.Append('\''); + } + } + } +} diff --git a/QueryBuilder/Clauses/AbstractClause.cs b/QueryBuilder/Clauses/AbstractClause.cs deleted file mode 100644 index 1f286594..00000000 --- a/QueryBuilder/Clauses/AbstractClause.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace SqlKata -{ - public abstract class AbstractClause - { - /// - /// Gets or sets the SQL engine. - /// - /// - /// The SQL engine. - /// - public string Engine { get; set; } = null; - - /// - /// Gets or sets the component name. - /// - /// - /// The component name. - /// - public string Component { get; set; } - public abstract AbstractClause Clone(); - } -} diff --git a/QueryBuilder/Clauses/AggregateClause.cs b/QueryBuilder/Clauses/AggregateClause.cs deleted file mode 100644 index 2d18d78e..00000000 --- a/QueryBuilder/Clauses/AggregateClause.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Collections.Generic; - -namespace SqlKata -{ - /// - /// Represents aggregate clause like "COUNT", "MAX" or etc. - /// - /// - public class AggregateClause : AbstractClause - { - /// - /// Gets or sets columns that used in aggregate clause. - /// - /// - /// The columns to be aggregated. - /// - public List Columns { get; set; } - - /// - /// Gets or sets the type of aggregate function. - /// - /// - /// The type of aggregate function, e.g. "MAX", "MIN", etc. - /// - public string Type { get; set; } - - /// - public override AbstractClause Clone() - { - return new AggregateClause - { - Engine = Engine, - Type = Type, - Columns = new List(Columns), - Component = Component, - }; - } - } -} diff --git a/QueryBuilder/Clauses/ColumnClause.cs b/QueryBuilder/Clauses/ColumnClause.cs deleted file mode 100644 index dd51a85e..00000000 --- a/QueryBuilder/Clauses/ColumnClause.cs +++ /dev/null @@ -1,109 +0,0 @@ -namespace SqlKata -{ - public abstract class AbstractColumn : AbstractClause - { - } - - /// - /// Represents "column" or "column as alias" clause. - /// - /// - public class Column : AbstractColumn - { - /// - /// Gets or sets the column name. Can be "columnName" or "columnName as columnAlias". - /// - /// - /// The column name. - /// - public string Name { get; set; } - - /// - public override AbstractClause Clone() - { - return new Column - { - Engine = Engine, - Name = Name, - Component = Component, - }; - } - } - - /// - /// Represents column clause calculated using query. - /// - /// - public class QueryColumn : AbstractColumn - { - /// - /// Gets or sets the query that will be used for column value calculation. - /// - /// - /// The query for column value calculation. - /// - public Query Query { get; set; } - public override AbstractClause Clone() - { - return new QueryColumn - { - Engine = Engine, - Query = Query.Clone(), - Component = Component, - }; - } - } - - public class RawColumn : AbstractColumn - { - /// - /// Gets or sets the RAW expression. - /// - /// - /// The RAW expression. - /// - public string Expression { get; set; } - public object[] Bindings { set; get; } - - /// - public override AbstractClause Clone() - { - return new RawColumn - { - Engine = Engine, - Expression = Expression, - Bindings = Bindings, - Component = Component, - }; - } - } - - /// - /// Represents an aggregated column clause with an optional filter - /// - /// - public class AggregatedColumn : AbstractColumn - { - /// - /// Gets or sets the a query that used to filter the data, - /// the compiler will consider only the `Where` clause. - /// - /// - /// The filter query. - /// - public Query Filter { get; set; } = null; - public string Aggregate { get; set; } - public AbstractColumn Column { get; set; } - public override AbstractClause Clone() - { - return new AggregatedColumn - { - Engine = Engine, - Filter = Filter?.Clone(), - Column = Column.Clone() as AbstractColumn, - Aggregate = Aggregate, - Component = Component, - }; - } - } -} diff --git a/QueryBuilder/Clauses/Combine.cs b/QueryBuilder/Clauses/Combine.cs deleted file mode 100644 index da0f5e37..00000000 --- a/QueryBuilder/Clauses/Combine.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Linq; - -namespace SqlKata -{ - public abstract class AbstractCombine : AbstractClause - { - - } - - public class Combine : AbstractCombine - { - /// - /// Gets or sets the query to be combined with. - /// - /// - /// The query that will be combined. - /// - public Query Query { get; set; } - - /// - /// Gets or sets the combine operation, e.g. "UNION", etc. - /// - /// - /// The combine operation. - /// - public string Operation { get; set; } - - /// - /// Gets or sets a value indicating whether this clause will combine all. - /// - /// - /// true if all; otherwise, false. - /// - public bool All { get; set; } = false; - - public override AbstractClause Clone() - { - return new Combine - { - Engine = Engine, - Operation = Operation, - Component = Component, - Query = Query, - All = All, - }; - } - } - - public class RawCombine : AbstractCombine - { - public string Expression { get; set; } - - public object[] Bindings { get; set; } - - public override AbstractClause Clone() - { - return new RawCombine - { - Engine = Engine, - Component = Component, - Expression = Expression, - Bindings = Bindings, - }; - } - } -} diff --git a/QueryBuilder/Clauses/ConditionClause.cs b/QueryBuilder/Clauses/ConditionClause.cs deleted file mode 100644 index 287149e5..00000000 --- a/QueryBuilder/Clauses/ConditionClause.cs +++ /dev/null @@ -1,339 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace SqlKata -{ - public abstract class AbstractCondition : AbstractClause - { - public bool IsOr { get; set; } = false; - public bool IsNot { get; set; } = false; - } - - /// - /// Represents a comparison between a column and a value. - /// - public class BasicCondition : AbstractCondition - { - public string Column { get; set; } - public string Operator { get; set; } - public virtual object Value { get; set; } - - /// - public override AbstractClause Clone() - { - return new BasicCondition - { - Engine = Engine, - Column = Column, - Operator = Operator, - Value = Value, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - public class BasicStringCondition : BasicCondition - { - - public bool CaseSensitive { get; set; } = false; - - private string escapeCharacter = null; - public string EscapeCharacter - { - get => escapeCharacter; - set - { - if (string.IsNullOrWhiteSpace(value)) - value = null; - else if (value.Length > 1) - throw new ArgumentOutOfRangeException($"The {nameof(EscapeCharacter)} can only contain a single character!"); - escapeCharacter = value; - } - } - /// - public override AbstractClause Clone() - { - return new BasicStringCondition - { - Engine = Engine, - Column = Column, - Operator = Operator, - Value = Value, - IsOr = IsOr, - IsNot = IsNot, - CaseSensitive = CaseSensitive, - EscapeCharacter = EscapeCharacter, - Component = Component, - }; - } - } - - public class BasicDateCondition : BasicCondition - { - public string Part { get; set; } - - /// - public override AbstractClause Clone() - { - return new BasicDateCondition - { - Engine = Engine, - Column = Column, - Operator = Operator, - Value = Value, - IsOr = IsOr, - IsNot = IsNot, - Part = Part, - Component = Component, - }; - } - } - - /// - /// Represents a comparison between two columns. - /// - public class TwoColumnsCondition : AbstractCondition - { - public string First { get; set; } - public string Operator { get; set; } - public string Second { get; set; } - - /// - public override AbstractClause Clone() - { - return new TwoColumnsCondition - { - Engine = Engine, - First = First, - Operator = Operator, - Second = Second, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents a comparison between a column and a full "subquery". - /// - public class QueryCondition : AbstractCondition where T : BaseQuery - { - public string Column { get; set; } - public string Operator { get; set; } - public Query Query { get; set; } - - /// - public override AbstractClause Clone() - { - return new QueryCondition - { - Engine = Engine, - Column = Column, - Operator = Operator, - Query = Query.Clone(), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents a comparison between a full "subquery" and a value. - /// - public class SubQueryCondition : AbstractCondition where T : BaseQuery - { - public object Value { get; set; } - public string Operator { get; set; } - public Query Query { get; set; } - - /// - public override AbstractClause Clone() - { - return new SubQueryCondition - { - Engine = Engine, - Value = Value, - Operator = Operator, - Query = Query.Clone(), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents a "is in" condition. - /// - public class InCondition : AbstractCondition - { - public string Column { get; set; } - public IEnumerable Values { get; set; } - public override AbstractClause Clone() - { - return new InCondition - { - Engine = Engine, - Column = Column, - Values = new List(Values), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - - } - - /// - /// Represents a "is in subquery" condition. - /// - public class InQueryCondition : AbstractCondition - { - public Query Query { get; set; } - public string Column { get; set; } - public override AbstractClause Clone() - { - return new InQueryCondition - { - Engine = Engine, - Column = Column, - Query = Query.Clone(), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents a "is between" condition. - /// - public class BetweenCondition : AbstractCondition - { - public string Column { get; set; } - public T Higher { get; set; } - public T Lower { get; set; } - public override AbstractClause Clone() - { - return new BetweenCondition - { - Engine = Engine, - Column = Column, - Higher = Higher, - Lower = Lower, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents an "is null" condition. - /// - public class NullCondition : AbstractCondition - { - public string Column { get; set; } - - /// - public override AbstractClause Clone() - { - return new NullCondition - { - Engine = Engine, - Column = Column, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents a boolean (true/false) condition. - /// - public class BooleanCondition : AbstractCondition - { - public string Column { get; set; } - public bool Value { get; set; } - - /// - public override AbstractClause Clone() - { - return new BooleanCondition - { - Engine = Engine, - Column = Column, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - Value = Value, - }; - } - } - - /// - /// Represents a "nested" clause condition. - /// i.e OR (myColumn = "A") - /// - public class NestedCondition : AbstractCondition where T : BaseQuery - { - public T Query { get; set; } - public override AbstractClause Clone() - { - return new NestedCondition - { - Engine = Engine, - Query = Query.Clone(), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - /// - /// Represents an "exists sub query" clause condition. - /// - public class ExistsCondition : AbstractCondition - { - public Query Query { get; set; } - - /// - public override AbstractClause Clone() - { - return new ExistsCondition - { - Engine = Engine, - Query = Query.Clone(), - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } - - public class RawCondition : AbstractCondition - { - public string Expression { get; set; } - public object[] Bindings { set; get; } - - /// - public override AbstractClause Clone() - { - return new RawCondition - { - Engine = Engine, - Expression = Expression, - Bindings = Bindings, - IsOr = IsOr, - IsNot = IsNot, - Component = Component, - }; - } - } -} diff --git a/QueryBuilder/Clauses/FromClause.cs b/QueryBuilder/Clauses/FromClause.cs deleted file mode 100644 index 1410facf..00000000 --- a/QueryBuilder/Clauses/FromClause.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace SqlKata -{ - public abstract class AbstractFrom : AbstractClause - { - protected string _alias; - - /// - /// Try to extract the Alias for the current clause. - /// - /// - public virtual string Alias { get => _alias; set => _alias = value; } - } - - /// - /// Represents a "from" clause. - /// - public class FromClause : AbstractFrom - { - public string Table { get; set; } - - public override string Alias - { - get - { - if (Table.IndexOf(" as ", StringComparison.OrdinalIgnoreCase) >= 0) - { - var segments = Table.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - - return segments[2]; - } - - return Table; - } - } - - /// - public override AbstractClause Clone() - { - return new FromClause - { - Engine = Engine, - Alias = Alias, - Table = Table, - Component = Component, - }; - } - } - - /// - /// Represents a "from subquery" clause. - /// - public class QueryFromClause : AbstractFrom - { - public Query Query { get; set; } - - public override string Alias - { - get - { - return string.IsNullOrEmpty(_alias) ? Query.QueryAlias : _alias; - } - } - - /// - public override AbstractClause Clone() - { - return new QueryFromClause - { - Engine = Engine, - Alias = Alias, - Query = Query.Clone(), - Component = Component, - }; - } - } - - public class RawFromClause : AbstractFrom - { - public string Expression { get; set; } - public object[] Bindings { set; get; } - - /// - public override AbstractClause Clone() - { - return new RawFromClause - { - Engine = Engine, - Alias = Alias, - Expression = Expression, - Bindings = Bindings, - Component = Component, - }; - } - } - - /// - /// Represents a FROM clause that is an ad-hoc table built with predefined values. - /// - public class AdHocTableFromClause : AbstractFrom - { - public List Columns { get; set; } - public List Values { get; set; } - - public override AbstractClause Clone() - { - return new AdHocTableFromClause - { - Engine = Engine, - Alias = Alias, - Columns = Columns, - Values = Values, - Component = Component, - }; - } - } -} \ No newline at end of file diff --git a/QueryBuilder/Clauses/IncrementClause.cs b/QueryBuilder/Clauses/IncrementClause.cs deleted file mode 100644 index 4ee5a194..00000000 --- a/QueryBuilder/Clauses/IncrementClause.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace SqlKata -{ - public class IncrementClause : InsertClause - { - public string Column { get; set; } - public int Value { get; set; } = 1; - - public override AbstractClause Clone() - { - return new IncrementClause - { - Engine = Engine, - Component = Component, - Column = Column, - Value = Value - }; - } - } -} \ No newline at end of file diff --git a/QueryBuilder/Clauses/InsertClause.cs b/QueryBuilder/Clauses/InsertClause.cs deleted file mode 100644 index 14ece2d2..00000000 --- a/QueryBuilder/Clauses/InsertClause.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; - -namespace SqlKata -{ - public abstract class AbstractInsertClause : AbstractClause - { - - } - - public class InsertClause : AbstractInsertClause - { - public List Columns { get; set; } - public List Values { get; set; } - public bool ReturnId { get; set; } = false; - - public override AbstractClause Clone() - { - return new InsertClause - { - Engine = Engine, - Component = Component, - Columns = Columns, - Values = Values, - ReturnId = ReturnId, - }; - } - } - - public class InsertQueryClause : AbstractInsertClause - { - public List Columns { get; set; } - public Query Query { get; set; } - - public override AbstractClause Clone() - { - return new InsertQueryClause - { - Engine = Engine, - Component = Component, - Columns = Columns, - Query = Query.Clone(), - }; - } - } -} diff --git a/QueryBuilder/Clauses/JoinClause.cs b/QueryBuilder/Clauses/JoinClause.cs deleted file mode 100644 index 94c6b322..00000000 --- a/QueryBuilder/Clauses/JoinClause.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; - -namespace SqlKata -{ - public abstract class AbstractJoin : AbstractClause - { - - } - - public class BaseJoin : AbstractJoin - { - public Join Join { get; set; } - - public override AbstractClause Clone() - { - return new BaseJoin - { - Engine = Engine, - Join = Join.Clone(), - Component = Component, - }; - } - } - - public class DeepJoin : AbstractJoin - { - public string Type { get; set; } - public string Expression { get; set; } - public string SourceKeySuffix { get; set; } - public string TargetKey { get; set; } - public Func SourceKeyGenerator { get; set; } - public Func TargetKeyGenerator { get; set; } - - /// - public override AbstractClause Clone() - { - return new DeepJoin - { - Engine = Engine, - Component = Component, - Type = Type, - Expression = Expression, - SourceKeySuffix = SourceKeySuffix, - TargetKey = TargetKey, - SourceKeyGenerator = SourceKeyGenerator, - TargetKeyGenerator = TargetKeyGenerator, - }; - } - } -} diff --git a/QueryBuilder/Clauses/LimitClause.cs b/QueryBuilder/Clauses/LimitClause.cs deleted file mode 100644 index 89defc99..00000000 --- a/QueryBuilder/Clauses/LimitClause.cs +++ /dev/null @@ -1,35 +0,0 @@ -namespace SqlKata -{ - public class LimitClause : AbstractClause - { - private int _limit; - - public int Limit - { - get => _limit; - set => _limit = value > 0 ? value : _limit; - } - - public bool HasLimit() - { - return _limit > 0; - } - - public LimitClause Clear() - { - _limit = 0; - return this; - } - - /// - public override AbstractClause Clone() - { - return new LimitClause - { - Engine = Engine, - Limit = Limit, - Component = Component, - }; - } - } -} diff --git a/QueryBuilder/Clauses/OffsetClause.cs b/QueryBuilder/Clauses/OffsetClause.cs deleted file mode 100644 index a33a7f47..00000000 --- a/QueryBuilder/Clauses/OffsetClause.cs +++ /dev/null @@ -1,35 +0,0 @@ -namespace SqlKata -{ - public class OffsetClause : AbstractClause - { - private long _offset; - - public long Offset - { - get => _offset; - set => _offset = value > 0 ? value : _offset; - } - - public bool HasOffset() - { - return _offset > 0; - } - - public OffsetClause Clear() - { - _offset = 0; - return this; - } - - /// - public override AbstractClause Clone() - { - return new OffsetClause - { - Engine = Engine, - Offset = Offset, - Component = Component, - }; - } - } -} diff --git a/QueryBuilder/Clauses/OrderClause.cs b/QueryBuilder/Clauses/OrderClause.cs deleted file mode 100644 index 69af772e..00000000 --- a/QueryBuilder/Clauses/OrderClause.cs +++ /dev/null @@ -1,55 +0,0 @@ -namespace SqlKata -{ - public abstract class AbstractOrderBy : AbstractClause - { - - } - - public class OrderBy : AbstractOrderBy - { - public string Column { get; set; } - public bool Ascending { get; set; } = true; - - /// - public override AbstractClause Clone() - { - return new OrderBy - { - Engine = Engine, - Component = Component, - Column = Column, - Ascending = Ascending - }; - } - } - - public class RawOrderBy : AbstractOrderBy - { - public string Expression { get; set; } - public object[] Bindings { set; get; } - - /// - public override AbstractClause Clone() - { - return new RawOrderBy - { - Engine = Engine, - Component = Component, - Expression = Expression, - Bindings = Bindings, - }; - } - } - - public class OrderByRandom : AbstractOrderBy - { - /// - public override AbstractClause Clone() - { - return new OrderByRandom - { - Engine = Engine, - }; - } - } -} diff --git a/QueryBuilder/ColumnAttribute.cs b/QueryBuilder/ColumnAttribute.cs index 35e96343..765d112d 100644 --- a/QueryBuilder/ColumnAttribute.cs +++ b/QueryBuilder/ColumnAttribute.cs @@ -1,34 +1,30 @@ -using System; +using System.Runtime.CompilerServices; namespace SqlKata { /// - /// This class is used as metadata on a property to generate different name in the output query. + /// This class is used as metadata on a property to generate different name in the output query. /// public class ColumnAttribute : Attribute { - public string Name { get; private set; } public ColumnAttribute(string name) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name)); Name = name; } + + public string Name { get; private set; } } /// - /// This class is used as metadata on a property to determine if it is a primary key + /// This class is used as metadata on a property to determine if it is a primary key /// public class KeyAttribute : ColumnAttribute { - public KeyAttribute([System.Runtime.CompilerServices.CallerMemberName] string name = "") - : base(name) + public KeyAttribute([CallerMemberName] string name = "") + : base(name) { - } - } } diff --git a/QueryBuilder/Compilers/CompilationExtensions.cs b/QueryBuilder/Compilers/CompilationExtensions.cs new file mode 100644 index 00000000..cb8ba0b8 --- /dev/null +++ b/QueryBuilder/Compilers/CompilationExtensions.cs @@ -0,0 +1,45 @@ +namespace SqlKata.Compilers +{ + public static class CompilationExtensions + { + public static SqlResult Compile(this Compiler compiler, Query query) + { + var writer = new Writer(compiler.XService); + compiler.CompileRaw(query, writer); + var ctx = new SqlResult(); + ctx.ReplaceRaw(writer); + ctx.ReplaceBindings(writer.Bindings); + ctx = compiler.PrepareResult(ctx, writer); + return ctx; + } + + public static SqlResult Compile(this Compiler compiler, IEnumerable queries) + { + var writer = new Writer(compiler.XService); + var ctx = Accumulate(); + + ctx.ReplaceRaw(writer); + ctx = compiler.PrepareResult(ctx, writer); + return ctx; + + SqlResult Accumulate() + { + var sqlResult = new SqlResult(); + writer.List(";\n", queries, query => + { + compiler.CompileRaw(query, writer); + }); + return sqlResult; + } + } + + private static SqlResult PrepareResult(this Compiler compiler, SqlResult ctx, Writer writer) + { + ctx.NamedBindings = ctx.Bindings.GenerateNamedBindings(compiler.ParameterPrefix); + ctx.Sql = BindingExtensions.ReplaceAll(writer, + "?", i => compiler.ParameterPrefix + i); + writer.EnsureBindingMatch(); + return ctx; + } + } +} diff --git a/QueryBuilder/Compilers/Compiler.Conditions.cs b/QueryBuilder/Compilers/Compiler.Conditions.cs index 6615c246..cbfaeae8 100644 --- a/QueryBuilder/Compilers/Compiler.Conditions.cs +++ b/QueryBuilder/Compilers/Compiler.Conditions.cs @@ -1,266 +1,247 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - namespace SqlKata.Compilers { public partial class Compiler { - protected virtual MethodInfo FindCompilerMethodInfo(Type clauseType, string methodName) - { - return _compileConditionMethodsProvider.GetMethodInfo(clauseType, methodName); - } + private static readonly string[] LikeOperators = { "starts", "ends", "contains", "like" }; - protected virtual string CompileCondition(SqlResult ctx, AbstractCondition clause) + private void CompileCondition(Query query, AbstractCondition clause, Writer writer) { - var clauseType = clause.GetType(); - - var name = clauseType.Name; - - name = name.Substring(0, name.IndexOf("Condition")); - - var methodName = "Compile" + name + "Condition"; - - var methodInfo = FindCompilerMethodInfo(clauseType, methodName); - - try - { - - var result = methodInfo.Invoke(this, new object[] { - ctx, - clause - }); - - return result as string; - } - catch (Exception ex) + switch (clause) { - throw new Exception($"Failed to invoke '{methodName}'", ex); + case BasicDateCondition basicDateCondition: + CompileBasicDateCondition(query, basicDateCondition, writer); + break; + case BasicStringCondition basicStringCondition: + CompileBasicStringCondition(query, basicStringCondition, writer); + break; + case BasicCondition basicCondition: + CompileBasicCondition(query, basicCondition, writer); + break; + case BetweenCondition betweenCondition: + CompileBetweenCondition(query, betweenCondition, writer); + break; + case BooleanCondition booleanCondition: + CompileBooleanCondition(booleanCondition, writer); + break; + case ExistsCondition existsCondition: + CompileExistsCondition(existsCondition, writer); + break; + case InCondition inCondition: + CompileInCondition(query, inCondition, writer); + break; + case InQueryCondition inQueryCondition: + CompileInQueryCondition(inQueryCondition, writer); + break; + case NestedCondition nestedCondition: + CompileNestedCondition(query, nestedCondition, writer); + break; + case NullCondition nullCondition: + CompileNullCondition(nullCondition, writer); + break; + case QueryCondition queryCondition: + CompileQueryCondition(queryCondition, writer); + break; + case RawCondition rawCondition: + CompileRawCondition(rawCondition, writer); + break; + case SubQueryCondition subQueryCondition: + CompileSubQueryCondition(query, subQueryCondition, writer); + break; + case TwoColumnsCondition twoColumnsCondition: + CompileTwoColumnsCondition(twoColumnsCondition, writer); + break; + default: + throw new ArgumentOutOfRangeException(nameof(clause)); } - } - protected virtual string CompileConditions(SqlResult ctx, List conditions) + private void CompileConditions(Query query, List conditions, Writer writer) { - var result = new List(); - - for (var i = 0; i < conditions.Count; i++) + writer.List(" ", conditions, (c, i) => { - var compiled = CompileCondition(ctx, conditions[i]); - - if (string.IsNullOrEmpty(compiled)) - { - continue; - } - - var boolOperator = i == 0 ? "" : (conditions[i].IsOr ? "OR " : "AND "); - - result.Add(boolOperator + compiled); - } - - return string.Join(" ", result); + if (i != 0) + writer.Append(c.IsOr ? "OR " : "AND "); + CompileCondition(query, c, writer); + }); } - protected virtual string CompileRawCondition(SqlResult ctx, RawCondition x) + private void CompileRawCondition(RawCondition x, Writer writer) { - ctx.Bindings.AddRange(x.Bindings); - return WrapIdentifiers(x.Expression); + writer.AppendRaw(x.Expression, x.Bindings); } - protected virtual string CompileQueryCondition(SqlResult ctx, QueryCondition x) where T : BaseQuery + private void CompileQueryCondition(QueryCondition x, Writer writer) { - var subCtx = CompileSelectQuery(x.Query); - - ctx.Bindings.AddRange(subCtx.Bindings); - - return Wrap(x.Column) + " " + checkOperator(x.Operator) + " (" + subCtx.RawSql + ")"; + writer.AppendName(x.Column); + writer.Append(" "); + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" ("); + CompileSelectQuery(x.Query, writer); + writer.Append(")"); } - protected virtual string CompileSubQueryCondition(SqlResult ctx, SubQueryCondition x) where T : BaseQuery + private void CompileSubQueryCondition(Query query, SubQueryCondition x, Writer writer) { - var subCtx = CompileSelectQuery(x.Query); - - ctx.Bindings.AddRange(subCtx.Bindings); - - return "(" + subCtx.RawSql + ") " + checkOperator(x.Operator) + " " + Parameter(ctx, x.Value); + writer.Append("("); + CompileSelectQuery(x.Query, writer); + writer.Append(") "); + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" "); + writer.AppendParameter(query, x.Value); } - protected virtual string CompileBasicCondition(SqlResult ctx, BasicCondition x) + private void CompileBasicCondition(Query query, BasicCondition x, Writer writer) { - var sql = $"{Wrap(x.Column)} {checkOperator(x.Operator)} {Parameter(ctx, x.Value)}"; - if (x.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; + writer.Append("NOT ("); + writer.AppendName(x.Column); + writer.Append(" "); + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" "); + writer.AppendParameter(query, x.Value); + if (x.IsNot) + writer.Append(")"); } - protected virtual string CompileBasicStringCondition(SqlResult ctx, BasicStringCondition x) + protected virtual void CompileBasicStringCondition( + Query query, BasicStringCondition x, Writer writer) { - - var column = Wrap(x.Column); - - var value = Resolve(ctx, x.Value) as string; - - if (value == null) - { + if (CompilerQueryExtensions.Resolve(query, x.Value) is not string value) throw new ArgumentException("Expecting a non nullable string"); - } - - var method = x.Operator; - - if (new[] { "starts", "ends", "contains", "like" }.Contains(x.Operator)) - { - - method = "LIKE"; - - switch (x.Operator) - { - case "starts": - value = $"{value}%"; - break; - case "ends": - value = $"%{value}"; - break; - case "contains": - value = $"%{value}%"; - break; - } - } - - string sql; - + if (x.IsNot) + writer.Append("NOT ("); if (!x.CaseSensitive) + writer.Append("LOWER("); + writer.AppendName(x.Column); + if (!x.CaseSensitive) + writer.Append(")"); + + writer.Append(" "); + var isLikeOperator = LikeOperators.Contains(x.Operator); + var method = isLikeOperator ? "LIKE" : x.Operator; + writer.Append(Operators.CheckOperator(method)); + writer.Append(" "); + if (isLikeOperator) { - column = CompileLower(column); - value = value.ToLowerInvariant(); - } - - if (x.Value is UnsafeLiteral) - { - sql = $"{column} {checkOperator(method)} {value}"; - } - else - { - sql = $"{column} {checkOperator(method)} {Parameter(ctx, value)}"; + value = x.Operator switch + { + "starts" => $"{value}%", + "ends" => $"%{value}", + "contains" => $"%{value}%", + _ => value + }; } - - if (!string.IsNullOrEmpty(x.EscapeCharacter)) + writer.AppendParameter(query, + x.CaseSensitive ? value : value.ToLowerInvariant()); + if (x.EscapeCharacter is { } esc) { - sql = $"{sql} ESCAPE '{x.EscapeCharacter}'"; + writer.Append(" ESCAPE '"); + writer.Append(esc); + writer.Append('\''); } - return x.IsNot ? $"NOT ({sql})" : sql; - + if (x.IsNot) + writer.Append(")"); } - protected virtual string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition x) + protected virtual void CompileBasicDateCondition( + Query query, BasicDateCondition x, Writer writer) { - var column = Wrap(x.Column); - var op = checkOperator(x.Operator); - - var sql = $"{x.Part.ToUpperInvariant()}({column}) {op} {Parameter(ctx, x.Value)}"; - - return x.IsNot ? $"NOT ({sql})" : sql; + if (x.IsNot) + writer.Append("NOT ("); + writer.AppendKeyword(x.Part); + writer.Append("("); + writer.AppendName(x.Column); + writer.Append(") "); + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" "); + writer.AppendParameter(query, x.Value); + if (x.IsNot) + writer.Append(")"); } - protected virtual string CompileNestedCondition(SqlResult ctx, NestedCondition x) where Q : BaseQuery + private void CompileNestedCondition(Query query, NestedCondition x, Writer writer) { - if (!(x.Query.HasComponent("where", EngineCode) || x.Query.HasComponent("having", EngineCode))) - { - return null; - } + var conditions = x.Query.GetComponents("where", EngineCode).NullIfEmpty() ?? + x.Query.GetComponents("having", EngineCode); - var clause = x.Query.HasComponent("where", EngineCode) ? "where" : "having"; + if (conditions.Count == 0) return; - var clauses = x.Query.GetComponents(clause, EngineCode); - - var sql = CompileConditions(ctx, clauses); - - return x.IsNot ? $"NOT ({sql})" : $"({sql})"; + if (x.IsNot) + writer.Append("NOT "); + writer.Append("("); + CompileConditions(query, conditions, writer); + writer.Append(")"); } - protected string CompileTwoColumnsCondition(SqlResult ctx, TwoColumnsCondition clause) + private void CompileTwoColumnsCondition(TwoColumnsCondition x, Writer writer) { - var op = clause.IsNot ? "NOT " : ""; - return $"{op}{Wrap(clause.First)} {checkOperator(clause.Operator)} {Wrap(clause.Second)}"; + if (x.IsNot) + writer.Append("NOT "); + writer.AppendName(x.First); + writer.Append(" "); + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" "); + writer.AppendName(x.Second); } - protected virtual string CompileBetweenCondition(SqlResult ctx, BetweenCondition item) + private void CompileBetweenCondition(Query query, BetweenCondition x, Writer writer) { - var between = item.IsNot ? "NOT BETWEEN" : "BETWEEN"; - var lower = Parameter(ctx, item.Lower); - var higher = Parameter(ctx, item.Higher); - - return Wrap(item.Column) + $" {between} {lower} AND {higher}"; + writer.AppendName(x.Column); + writer.Append(x.IsNot ? " NOT BETWEEN " : " BETWEEN "); + writer.AppendParameter(query, x.Lower); + writer.Append(" AND "); + writer.AppendParameter(query, x.Higher); } - protected virtual string CompileInCondition(SqlResult ctx, InCondition item) + private void CompileInCondition(Query query, InCondition x, Writer writer) { - var column = Wrap(item.Column); - - if (!item.Values.Any()) + if (!x.Values.Any()) { - return item.IsNot ? $"1 = 1 /* NOT IN [empty list] */" : "1 = 0 /* IN [empty list] */"; + writer.Append(x.IsNot + ? "1 = 1 /* NOT IN [empty list] */" + : "1 = 0 /* IN [empty list] */"); + return; } - var inOperator = item.IsNot ? "NOT IN" : "IN"; - - var values = Parameterize(ctx, item.Values); - - return column + $" {inOperator} ({values})"; + writer.AppendName(x.Column); + writer.Append(x.IsNot ? " NOT IN (" : " IN ("); + writer.CommaSeparatedParameters(query, x.Values.OfType()); + writer.Append(")"); } - protected virtual string CompileInQueryCondition(SqlResult ctx, InQueryCondition item) + private void CompileInQueryCondition(InQueryCondition x, Writer writer) { - - var subCtx = CompileSelectQuery(item.Query); - - ctx.Bindings.AddRange(subCtx.Bindings); - - var inOperator = item.IsNot ? "NOT IN" : "IN"; - - return Wrap(item.Column) + $" {inOperator} ({subCtx.RawSql})"; + writer.AppendName(x.Column); + writer.Append(x.IsNot ? " NOT IN (" : " IN ("); + CompileSelectQuery(x.Query, writer); + writer.Append(")"); } - protected virtual string CompileNullCondition(SqlResult ctx, NullCondition item) + private void CompileNullCondition(NullCondition x, Writer writer) { - var op = item.IsNot ? "IS NOT NULL" : "IS NULL"; - return Wrap(item.Column) + " " + op; + writer.AppendName(x.Column); + writer.Append(x.IsNot ? " IS NOT NULL" : " IS NULL"); } - protected virtual string CompileBooleanCondition(SqlResult ctx, BooleanCondition item) + private void CompileBooleanCondition(BooleanCondition x, Writer writer) { - var column = Wrap(item.Column); - var value = item.Value ? CompileTrue() : CompileFalse(); - - var op = item.IsNot ? "!=" : "="; - - return $"{column} {op} {value}"; + writer.AppendName(x.Column); + writer.Append(x.IsNot ? " != " : " = "); + writer.Append(x.Value ? CompileTrue() : CompileFalse()); } - protected virtual string CompileExistsCondition(SqlResult ctx, ExistsCondition item) + private void CompileExistsCondition(ExistsCondition item, Writer writer) { - var op = item.IsNot ? "NOT EXISTS" : "EXISTS"; - - - // remove unneeded components - var query = item.Query.Clone(); - - if (OmitSelectInsideExists) - { - query.ClearComponent("select").SelectRaw("1"); - } - - var subCtx = CompileSelectQuery(query); + writer.Append(item.IsNot ? "NOT EXISTS (" : "EXISTS ("); - ctx.Bindings.AddRange(subCtx.Bindings); + var query = OmitSelectInsideExists + ? item.Query.Clone().RemoveComponent("select").SelectRaw("1") + : item.Query; - return $"{op} ({subCtx.RawSql})"; + CompileSelectQuery(query, writer); + writer.Append(")"); } } } diff --git a/QueryBuilder/Compilers/Compiler.cs b/QueryBuilder/Compilers/Compiler.cs index aa15c789..ba948463 100644 --- a/QueryBuilder/Compilers/Compiler.cs +++ b/QueryBuilder/Compilers/Compiler.cs @@ -1,1062 +1,639 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Collections.Immutable; +using System.Diagnostics; namespace SqlKata.Compilers { public partial class Compiler { - private readonly ConditionsCompilerProvider _compileConditionMethodsProvider; - protected virtual string parameterPlaceholder { get; set; } = "?"; - protected virtual string parameterPrefix { get; set; } = "@p"; - protected virtual string OpeningIdentifier { get; set; } = "\""; - protected virtual string ClosingIdentifier { get; set; } = "\""; - protected virtual string ColumnAsKeyword { get; set; } = "AS "; - protected virtual string TableAsKeyword { get; set; } = "AS "; - protected virtual string LastId { get; set; } = ""; - protected virtual string EscapeCharacter { get; set; } = "\\"; + protected WhiteList Operators { get; } = new(); + public string ParameterPrefix { get; protected init; } = "@p"; + public X XService { get; protected init; } = new("\"", "\"", "AS "); + protected string TableAsKeyword { get; init; } = "AS "; + protected string LastId { get; init; } = ""; - protected virtual string SingleInsertStartClause { get; set; } = "INSERT INTO"; - protected virtual string MultiInsertStartClause { get; set; } = "INSERT INTO"; - - - protected Compiler() - { - _compileConditionMethodsProvider = new ConditionsCompilerProvider(this); - } - - public virtual string EngineCode { get; } + private const string SingleInsertStartClause = "INSERT INTO"; + protected string MultiInsertStartClause { get; init; } = "INSERT INTO"; + protected string? EngineCode { get; init; } + protected string? SingleRowDummyTableName { get; init; } /// - /// Whether the compiler supports the `SELECT ... FILTER` syntax + /// Whether the compiler supports the `SELECT ... FILTER` syntax /// - /// - public virtual bool SupportsFilterClause { get; set; } = false; + /// + protected bool SupportsFilterClause { get; init; } /// - /// If true the compiler will remove the SELECT clause for the query used inside WHERE EXISTS + /// If true the compiler will remove the SELECT clause for the query used inside WHERE EXISTS /// - /// - public virtual bool OmitSelectInsideExists { get; set; } = true; - - protected virtual string SingleRowDummyTableName { get => null; } + /// + public bool OmitSelectInsideExists { get; init; } = true; /// - /// A list of white-listed operators + /// Add the passed operator(s) to the white list so they can be used with + /// the Where/Having methods, this prevent passing arbitrary operators + /// that opens the door for SQL injections. /// - /// - protected readonly HashSet operators = new HashSet - { - "=", "<", ">", "<=", ">=", "<>", "!=", "<=>", - "like", "not like", - "ilike", "not ilike", - "like binary", "not like binary", - "rlike", "not rlike", - "regexp", "not regexp", - "similar to", "not similar to" - }; - - protected HashSet userOperators = new HashSet - { - - }; - - protected Dictionary generateNamedBindings(object[] bindings) + /// + /// + public Compiler Whitelist(params string[] operators) { - return Helper.Flatten(bindings).Select((v, i) => new { i, v }) - .ToDictionary(x => parameterPrefix + x.i, x => x.v); - } + Operators.Whitelist(operators); - protected SqlResult PrepareResult(SqlResult ctx) - { - ctx.NamedBindings = generateNamedBindings(ctx.Bindings.ToArray()); - ctx.Sql = Helper.ReplaceAll(ctx.RawSql, parameterPlaceholder, i => parameterPrefix + i); - return ctx; + return this; } - - private Query TransformAggregateQuery(Query query) + internal void CompileRaw(Query query, Writer writer) { - var clause = query.GetOneComponent("aggregate", EngineCode); - - if (clause.Columns.Count == 1 && !query.IsDistinct) return query; - - if (query.IsDistinct) - { - query.ClearComponent("aggregate", EngineCode); - query.ClearComponent("select", EngineCode); - query.Select(clause.Columns.ToArray()); - } - else + // handle CTEs + if (query.HasComponent("cte", EngineCode)) { - foreach (var column in clause.Columns) - { - query.WhereNotNull(column); - } + CompileCteQuery(query, writer); } - - var outerClause = new AggregateClause() - { - Columns = new List { "*" }, - Type = clause.Type - }; - - return new Query() - .AddComponent("aggregate", outerClause) - .From(query, $"{clause.Type}Query"); - } - - protected virtual SqlResult CompileRaw(Query query) - { - SqlResult ctx; - if (query.Method == "insert") { - ctx = CompileInsertQuery(query); + CompileInsertQuery(query, writer); } else if (query.Method == "update") { - ctx = CompileUpdateQuery(query); + CompileUpdateQuery(query, writer); } else if (query.Method == "delete") { - ctx = CompileDeleteQuery(query); + CompileDeleteQuery(query, writer); } else { if (query.Method == "aggregate") { - query.ClearComponent("limit") - .ClearComponent("order") - .ClearComponent("group"); + query.RemoveComponent("limit") + .RemoveComponent("order") + .RemoveComponent("group"); query = TransformAggregateQuery(query); } - ctx = CompileSelectQuery(query); + CompileSelectQuery(query, writer); } - // handle CTEs - if (query.HasComponent("cte", EngineCode)) - { - ctx = CompileCteQuery(ctx, query); - } - - ctx.RawSql = Helper.ExpandParameters(ctx.RawSql, parameterPlaceholder, ctx.Bindings.ToArray()); + return; - return ctx; - } - - /// - /// Add the passed operator(s) to the white list so they can be used with - /// the Where/Having methods, this prevent passing arbitrary operators - /// that opens the door for SQL injections. - /// - /// - /// - public Compiler Whitelist(params string[] operators) - { - foreach (var op in operators) + Query TransformAggregateQuery(Query input) { - this.userOperators.Add(op); - } - - return this; - } + var clause = input.GetOneComponent("aggregate", EngineCode)!; - public virtual SqlResult Compile(Query query) - { - var ctx = CompileRaw(query); - - ctx = PrepareResult(ctx); + if (clause.Columns.Length == 1 && !input.IsDistinct) return input; - return ctx; - } + if (input.IsDistinct) + { + input.RemoveComponent("aggregate", EngineCode); + input.RemoveComponent("select", EngineCode); + input.Select(clause.Columns.ToArray()); + } + else + { + foreach (var column in clause.Columns) + input.WhereNotNull(column); + } - public virtual SqlResult Compile(IEnumerable queries) - { - var compiled = queries.Select(CompileRaw).ToArray(); - var bindings = compiled.Select(r => r.Bindings).ToArray(); - var totalBindingsCount = bindings.Select(b => b.Count).Aggregate((a, b) => a + b); + var outerClause = new AggregateClause + { + Engine = EngineCode, + Component = "aggregate", + Columns = ImmutableArray.Create("*"), + Type = clause.Type + }; - var combinedBindings = new List(totalBindingsCount); - foreach (var cb in bindings) - { - combinedBindings.AddRange(cb); + return new Query() + .AddComponent(outerClause) + .From(input, $"{clause.Type}Query"); } - var ctx = new SqlResult - { - RawSql = compiled.Select(r => r.RawSql).Aggregate((a, b) => a + ";\n" + b), - Bindings = combinedBindings, - }; - - ctx = PrepareResult(ctx); - - return ctx; } - protected virtual SqlResult CompileSelectQuery(Query query) - { - var ctx = new SqlResult - { - Query = query.Clone(), - }; - - var results = new[] { - this.CompileColumns(ctx), - this.CompileFrom(ctx), - this.CompileJoins(ctx), - this.CompileWheres(ctx), - this.CompileGroups(ctx), - this.CompileHaving(ctx), - this.CompileOrders(ctx), - this.CompileLimit(ctx), - this.CompileUnion(ctx), - } - .Where(x => x != null) - .Where(x => !string.IsNullOrEmpty(x)) - .ToList(); - - string sql = string.Join(" ", results); - ctx.RawSql = sql; - - return ctx; + protected virtual void CompileSelectQuery(Query query, Writer writer) + { + writer.WhitespaceSeparated( + () => CompileColumns(query, writer), + () => CompileFrom(query, writer), + () => CompileJoins(query, writer), + () => CompileWheres(query, writer), + () => CompileGroups(query, writer), + () => CompileHaving(query, writer), + () => CompileOrders(query, writer), + () => CompileLimit(query, writer), + () => CompileUnion(query, writer)); } - protected virtual SqlResult CompileAdHocQuery(AdHocTableFromClause adHoc) + protected virtual void CompileAdHocQuery(AdHocTableFromClause adHoc, Writer writer) { - var ctx = new SqlResult(); - - var row = "SELECT " + string.Join(", ", adHoc.Columns.Select(col => $"{parameterPlaceholder} AS {Wrap(col)}")); - - var fromTable = SingleRowDummyTableName; - - if (fromTable != null) - { - row += $" FROM {fromTable}"; - } - - var rows = string.Join(" UNION ALL ", Enumerable.Repeat(row, adHoc.Values.Count / adHoc.Columns.Count)); - - ctx.RawSql = rows; - ctx.Bindings = adHoc.Values; - - return ctx; + Debug.Assert(adHoc.Alias != null, "adHoc.Alias != null"); + writer.AppendValue(adHoc.Alias); + writer.Append(" AS ("); + writer.List(" UNION ALL ", + adHoc.Values.Length / adHoc.Columns.Length, _ => + { + writer.Append("SELECT "); + writer.List(", ", adHoc.Columns, column => + { + writer.Append("? AS "); + writer.AppendName(column); + }); + if (SingleRowDummyTableName != null) + { + writer.Append(" FROM "); + writer.Append(SingleRowDummyTableName); + } + }); + writer.BindMany(adHoc.Values); + writer.Append(")"); } - protected virtual SqlResult CompileDeleteQuery(Query query) + private void CompileDeleteQuery(Query query, Writer writer) { - var ctx = new SqlResult - { - Query = query - }; - - if (!ctx.Query.HasComponent("from", EngineCode)) + if (!query.HasComponent("join", EngineCode)) { - throw new InvalidOperationException("No table set to delete"); - } - - var fromClause = ctx.Query.GetOneComponent("from", EngineCode); - - string table = null; - - if (fromClause is FromClause fromClauseCast) - { - table = Wrap(fromClauseCast.Table); - } - - if (fromClause is RawFromClause rawFromClause) - { - table = WrapIdentifiers(rawFromClause.Expression); - ctx.Bindings.AddRange(rawFromClause.Bindings); - } - - if (table is null) - { - throw new InvalidOperationException("Invalid table expression"); - } - - var joins = CompileJoins(ctx); - - var where = CompileWheres(ctx); - - if (!string.IsNullOrEmpty(where)) - { - where = " " + where; - } - - if (string.IsNullOrEmpty(joins)) - { - ctx.RawSql = $"DELETE FROM {table}{where}"; + writer.Append("DELETE FROM "); + WriteTable(query, writer, "delete"); + CompileWheres(query, writer); } else { - // check if we have alias - if (fromClause is FromClause && !string.IsNullOrEmpty(fromClause.Alias)) - { - ctx.RawSql = $"DELETE {Wrap(fromClause.Alias)} FROM {table} {joins}{where}"; - } - else - { - ctx.RawSql = $"DELETE {table} FROM {table} {joins}{where}"; - } + var fromClause = query.GetOneComponent("from", EngineCode); + if (fromClause is not FromClause c) + throw new InvalidOperationException("No table set to delete"); + writer.Append("DELETE "); + writer.AppendName(c.Alias); + writer.Append(" FROM "); + WriteTable(fromClause, writer, "delete"); + CompileJoins(query, writer); + CompileWheres(query, writer); } - - return ctx; } - protected virtual SqlResult CompileUpdateQuery(Query query) + private void CompileUpdateQuery(Query query, Writer writer) { - var ctx = new SqlResult - { - Query = query - }; - - if (!ctx.Query.HasComponent("from", EngineCode)) - { - throw new InvalidOperationException("No table set to update"); - } - - var fromClause = ctx.Query.GetOneComponent("from", EngineCode); + writer.Append("UPDATE "); - string table = null; + WriteTable(query, writer, "update"); - if (fromClause is FromClause fromClauseCast) + var clause = query.GetOneComponent("update", EngineCode); + if (clause is IncrementClause increment) { - table = Wrap(fromClauseCast.Table); + CompileIncrement(increment); + return; } - if (fromClause is RawFromClause rawFromClause) - { - table = WrapIdentifiers(rawFromClause.Expression); - ctx.Bindings.AddRange(rawFromClause.Bindings); - } + var toUpdate = query.GetOneComponent("update", EngineCode); + Debug.Assert(toUpdate != null); + CompileUpdate(toUpdate); - if (table is null) + void CompileIncrement(IncrementClause incrementClause) { - throw new InvalidOperationException("Invalid table expression"); + writer.Append(" SET "); + writer.AppendName(incrementClause.Column); + writer.Append(" = "); + writer.AppendName(incrementClause.Column); + writer.Append(" "); + writer.Append(incrementClause.Value >= 0 ? "+" : "-"); + writer.Append(" "); + writer.AppendParameter(query, + Math.Abs(incrementClause.Value)); + CompileWheres(query, writer); } - // check for increment statements - var clause = ctx.Query.GetOneComponent("update", EngineCode); - - string wheres; - - if (clause != null && clause is IncrementClause increment) + void CompileUpdate(InsertClause insertClause) { - var column = Wrap(increment.Column); - var value = Parameter(ctx, Math.Abs(increment.Value)); - var sign = increment.Value >= 0 ? "+" : "-"; - - wheres = CompileWheres(ctx); - - if (!string.IsNullOrEmpty(wheres)) + writer.Append(" SET "); + writer.List(", ", insertClause.Columns, (column, i) => { - wheres = " " + wheres; - } - - ctx.RawSql = $"UPDATE {table} SET {column} = {column} {sign} {value}{wheres}"; - - return ctx; + writer.AppendName(column); + writer.Append(" = "); + writer.AppendParameter(query, insertClause.Values[i]); + }); + CompileWheres(query, writer); } + } + protected virtual void CompileInsertQuery(Query query, Writer writer) + { + var inserts = query.GetComponents("insert", EngineCode); + var isMultiValueInsert = inserts.OfType().Skip(1).Any(); - var toUpdate = ctx.Query.GetOneComponent("update", EngineCode); - var parts = new List(); + writer.Append(isMultiValueInsert + ? MultiInsertStartClause + : SingleInsertStartClause); + writer.Append(" "); + var table = WriteTable(query, writer, "insert"); - for (var i = 0; i < toUpdate.Columns.Count; i++) + if (inserts[0] is InsertQueryClause insertQueryClause) { - parts.Add(Wrap(toUpdate.Columns[i]) + " = " + Parameter(ctx, toUpdate.Values[i])); - } - var sets = string.Join(", ", parts); - - wheres = CompileWheres(ctx); - - if (!string.IsNullOrEmpty(wheres)) - { - wheres = " " + wheres; + CompileInsertQueryClause(insertQueryClause, writer); + return; } - ctx.RawSql = $"UPDATE {table} SET {sets}{wheres}"; + CompileValueInsertClauses(); + return; - return ctx; - } - protected virtual SqlResult CompileInsertQuery(Query query) - { - var ctx = new SqlResult + void CompileInsertQueryClause(InsertQueryClause clause, Writer w) { - Query = query - }; - - if (!ctx.Query.HasComponent("from", EngineCode)) - throw new InvalidOperationException("No table set to insert"); + w.WriteInsertColumnsList(clause.Columns); + w.Append(" "); - var fromClause = ctx.Query.GetOneComponent("from", EngineCode); - if (fromClause is null) - throw new InvalidOperationException("Invalid table expression"); - - string table = null; - if (fromClause is FromClause fromClauseCast) - table = Wrap(fromClauseCast.Table); - if (fromClause is RawFromClause rawFromClause) - { - table = WrapIdentifiers(rawFromClause.Expression); - ctx.Bindings.AddRange(rawFromClause.Bindings); + CompileSelectQuery(clause.Query, w); } - if (table is null) - throw new InvalidOperationException("Invalid table expression"); - - var inserts = ctx.Query.GetComponents("insert", EngineCode); - if (inserts[0] is InsertQueryClause insertQueryClause) - return CompileInsertQueryClause(ctx, table, insertQueryClause); - else - return CompileValueInsertClauses(ctx, table, inserts.Cast()); - } - - protected virtual SqlResult CompileInsertQueryClause( - SqlResult ctx, string table, InsertQueryClause clause) - { - string columns = GetInsertColumnsList(clause.Columns); - - var subCtx = CompileSelectQuery(clause.Query); - ctx.Bindings.AddRange(subCtx.Bindings); - - ctx.RawSql = $"{SingleInsertStartClause} {table}{columns} {subCtx.RawSql}"; - - return ctx; - } - - protected virtual SqlResult CompileValueInsertClauses( - SqlResult ctx, string table, IEnumerable insertClauses) - { - bool isMultiValueInsert = insertClauses.Skip(1).Any(); - - var insertInto = (isMultiValueInsert) ? MultiInsertStartClause : SingleInsertStartClause; - - var firstInsert = insertClauses.First(); - string columns = GetInsertColumnsList(firstInsert.Columns); - var values = string.Join(", ", Parameterize(ctx, firstInsert.Values)); - - ctx.RawSql = $"{insertInto} {table}{columns} VALUES ({values})"; - - if (isMultiValueInsert) - return CompileRemainingInsertClauses(ctx, table, insertClauses); + void CompileValueInsertClauses() + { + var insertClauses = inserts.Cast().ToArray(); + var firstInsert = insertClauses.First(); + writer.WriteInsertColumnsList(firstInsert.Columns); + writer.Append(" VALUES ("); + writer.CommaSeparatedParameters(query, firstInsert.Values); + writer.Append(")"); - if (firstInsert.ReturnId && !string.IsNullOrEmpty(LastId)) - ctx.RawSql += ";" + LastId; + if (isMultiValueInsert) + { + CompileRemainingInsertClauses(query, table, writer, insertClauses); - return ctx; + return; + } + if (firstInsert.ReturnId && !string.IsNullOrEmpty(LastId)) + { + writer.Append(";"); + writer.Append(LastId); + } + } } - protected virtual SqlResult CompileRemainingInsertClauses(SqlResult ctx, string table, IEnumerable inserts) + protected virtual void CompileRemainingInsertClauses(Query query, + string table, Writer writer, IEnumerable inserts) { foreach (var insert in inserts.Skip(1)) { - string values = string.Join(", ", Parameterize(ctx, insert.Values)); - ctx.RawSql += $", ({values})"; + writer.Append(", ("); + writer.CommaSeparatedParameters(query, insert.Values); + writer.Append(")"); } - return ctx; } - protected string GetInsertColumnsList(List columnList) + private void CompileCteQuery(Query query, Writer writer) { - var columns = ""; - if (columnList.Any()) - columns = $" ({string.Join(", ", WrapArray(columnList))})"; + writer.Append("WITH "); - return columns; - } + writer.List(",\n", query.FindCte(EngineCode), CompileCte); - protected virtual SqlResult CompileCteQuery(SqlResult ctx, Query query) - { - var cteFinder = new CteFinder(query, EngineCode); - var cteSearchResult = cteFinder.Find(); + writer.Append('\n'); + return; - var rawSql = new StringBuilder("WITH "); - var cteBindings = new List(); - foreach (var cte in cteSearchResult) + void CompileCte(AbstractFrom? cte) { - var cteCtx = CompileCte(cte); - - cteBindings.AddRange(cteCtx.Bindings); - rawSql.Append(cteCtx.RawSql.Trim()); - rawSql.Append(",\n"); + switch (cte) + { + case RawFromClause raw: + Debug.Assert(raw.Alias != null, "raw.Alias != null"); + writer.AppendValue(raw.Alias); + writer.Append(" AS ("); + writer.AppendRaw(raw.Expression, raw.Bindings); + writer.Append(")"); + break; + case QueryFromClause queryFromClause: + Debug.Assert(queryFromClause.Alias != null, "queryFromClause.Alias != null"); + writer.AppendValue(queryFromClause.Alias); + writer.Append(" AS ("); + CompileSelectQuery(queryFromClause.Query, writer); + writer.Append(")"); + break; + case AdHocTableFromClause adHoc: + CompileAdHocQuery(adHoc, writer); + break; + } } - - rawSql.Length -= 2; // remove last comma - rawSql.Append('\n'); - rawSql.Append(ctx.RawSql); - - ctx.Bindings.InsertRange(0, cteBindings); - ctx.RawSql = rawSql.ToString(); - - return ctx; } - /// - /// Compile a single column clause - /// - /// - /// - /// - public virtual string CompileColumn(SqlResult ctx, AbstractColumn column) + + private void CompileColumnList(Query query, IEnumerable columns, Writer writer) { - if (column is RawColumn raw) - { - ctx.Bindings.AddRange(raw.Bindings); - return WrapIdentifiers(raw.Expression); - } + writer.List(", ", columns, CompileColumn); + return; - if (column is QueryColumn queryColumn) + void CompileColumn(AbstractColumn column) { - var alias = ""; - - if (!string.IsNullOrWhiteSpace(queryColumn.Query.QueryAlias)) + switch (column) { - alias = $" {ColumnAsKeyword}{WrapValue(queryColumn.Query.QueryAlias)}"; + case Column col: + writer.AppendName(col.Name); + break; + case AggregatedColumn aggregatedColumn: + CompileAggregatedColumn(aggregatedColumn); + return; + case QueryColumn queryColumn: + writer.Append("("); + CompileSelectQuery(queryColumn.Query, writer); + writer.Append(") "); + writer.AppendAsAlias(queryColumn.Query.QueryAlias); + return; + case RawColumn raw: + writer.AppendRaw(raw.Expression, raw.Bindings); + return; } - var subCtx = CompileSelectQuery(queryColumn.Query); - - ctx.Bindings.AddRange(subCtx.Bindings); - - return "(" + subCtx.RawSql + $"){alias}"; } - if (column is AggregatedColumn aggregatedColumn) + void CompileAggregatedColumn(AggregatedColumn c) { - string agg = aggregatedColumn.Aggregate.ToUpperInvariant(); - - var (col, alias) = SplitAlias(CompileColumn(ctx, aggregatedColumn.Column)); + writer.AppendKeyword(c.Aggregate); - alias = string.IsNullOrEmpty(alias) ? "" : $" {ColumnAsKeyword}{alias}"; + var (col, alias) = XService.SplitAlias( + XService.WrapName(c.Column.Name)); - string filterCondition = CompileFilterConditions(ctx, aggregatedColumn); + var filterConditions = c.GetFilterConditions(); - if (string.IsNullOrEmpty(filterCondition)) + if (filterConditions.Count == 0) { - return $"{agg}({col}){alias}"; + writer.Append("("); + writer.Append(col); + writer.Append(")"); + writer.Append(alias); + return; } if (SupportsFilterClause) { - return $"{agg}({col}) FILTER (WHERE {filterCondition}){alias}"; + writer.Append("("); + writer.Append(col); + writer.Append(") FILTER (WHERE "); + CompileConditions(query, filterConditions, writer); + writer.Append(")"); + writer.Append(alias); + return; } - return $"{agg}(CASE WHEN {filterCondition} THEN {col} END){alias}"; + writer.Append("(CASE WHEN "); + CompileConditions(query, filterConditions, writer); + writer.Append(" THEN "); + writer.Append(col); + writer.Append(" END)"); + writer.Append(alias); } - - return Wrap((column as Column).Name); - } - protected virtual string CompileFilterConditions(SqlResult ctx, AggregatedColumn aggregatedColumn) + protected virtual void CompileColumns(Query query, Writer writer) { - if (aggregatedColumn.Filter == null) - { - return null; - } - - var wheres = aggregatedColumn.Filter.GetComponents("where"); - - return CompileConditions(ctx, wheres); + writer.Append("SELECT "); + CompileColumnsAfterSelect(query, writer); } - public virtual SqlResult CompileCte(AbstractFrom cte) + protected void CompileColumnsAfterSelect(Query query, Writer writer) { - var ctx = new SqlResult(); - - if (null == cte) + var aggregate = query.GetOneComponent("aggregate", EngineCode); + if (aggregate != null) { - return ctx; - } - - if (cte is RawFromClause raw) - { - ctx.Bindings.AddRange(raw.Bindings); - ctx.RawSql = $"{WrapValue(raw.Alias)} AS ({WrapIdentifiers(raw.Expression)})"; - } - else if (cte is QueryFromClause queryFromClause) - { - var subCtx = CompileSelectQuery(queryFromClause.Query); - ctx.Bindings.AddRange(subCtx.Bindings); - - ctx.RawSql = $"{WrapValue(queryFromClause.Alias)} AS ({subCtx.RawSql})"; - } - else if (cte is AdHocTableFromClause adHoc) - { - var subCtx = CompileAdHocQuery(adHoc); - ctx.Bindings.AddRange(subCtx.Bindings); - - ctx.RawSql = $"{WrapValue(adHoc.Alias)} AS ({subCtx.RawSql})"; - } - - return ctx; - } - - protected virtual SqlResult OnBeforeSelect(SqlResult ctx) - { - return ctx; - } - - protected virtual string CompileColumns(SqlResult ctx) - { - if (ctx.Query.HasComponent("aggregate", EngineCode)) - { - var aggregate = ctx.Query.GetOneComponent("aggregate", EngineCode); - - var aggregateColumns = aggregate.Columns - .Select(x => CompileColumn(ctx, new Column { Name = x })) - .ToList(); - - string sql = string.Empty; - - if (aggregateColumns.Count == 1) + D.IsFalse(query.IsDistinct, "TransformAggregateQuery should have taken care of it"); + if (aggregate.Columns.Length == 1) { - sql = string.Join(", ", aggregateColumns); - - if (ctx.Query.IsDistinct) - { - sql = "DISTINCT " + sql; - } - - return "SELECT " + aggregate.Type.ToUpperInvariant() + "(" + sql + $") {ColumnAsKeyword}" + WrapValue(aggregate.Type); - } - - return "SELECT 1"; - } - - var columns = ctx.Query - .GetComponents("select", EngineCode) - .Select(x => CompileColumn(ctx, x)) - .ToList(); - - var distinct = ctx.Query.IsDistinct ? "DISTINCT " : ""; - - var select = columns.Any() ? string.Join(", ", columns) : "*"; - - return $"SELECT {distinct}{select}"; - - } - - public virtual string CompileUnion(SqlResult ctx) - { - - // Handle UNION, EXCEPT and INTERSECT - if (!ctx.Query.GetComponents("combine", EngineCode).Any()) - { - return null; - } - - var combinedQueries = new List(); - - var clauses = ctx.Query.GetComponents("combine", EngineCode); - - foreach (var clause in clauses) - { - if (clause is Combine combineClause) - { - var combineOperator = combineClause.Operation.ToUpperInvariant() + " " + (combineClause.All ? "ALL " : ""); - - var subCtx = CompileSelectQuery(combineClause.Query); - - ctx.Bindings.AddRange(subCtx.Bindings); - - combinedQueries.Add($"{combineOperator}{subCtx.RawSql}"); + writer.AppendKeyword(aggregate.Type); + writer.Append("("); + writer.AppendName(aggregate.Columns[0]); + writer.Append(") "); + writer.AppendAsAlias(aggregate.Type); } else { - var combineRawClause = clause as RawCombine; - - ctx.Bindings.AddRange(combineRawClause.Bindings); - - combinedQueries.Add(WrapIdentifiers(combineRawClause.Expression)); - + writer.Append("1"); } } - - return string.Join(" ", combinedQueries); - - } - - public virtual string CompileTableExpression(SqlResult ctx, AbstractFrom from) - { - if (from is RawFromClause raw) - { - ctx.Bindings.AddRange(raw.Bindings); - return WrapIdentifiers(raw.Expression); - } - - if (from is QueryFromClause queryFromClause) - { - var fromQuery = queryFromClause.Query; - - var alias = string.IsNullOrEmpty(fromQuery.QueryAlias) ? "" : $" {TableAsKeyword}" + WrapValue(fromQuery.QueryAlias); - - var subCtx = CompileSelectQuery(fromQuery); - - ctx.Bindings.AddRange(subCtx.Bindings); - - return "(" + subCtx.RawSql + ")" + alias; - } - - if (from is FromClause fromClause) - { - return Wrap(fromClause.Table); - } - - throw InvalidClauseException("TableExpression", from); - } - - public virtual string CompileFrom(SqlResult ctx) - { - if (ctx.Query.HasComponent("from", EngineCode)) - { - var from = ctx.Query.GetOneComponent("from", EngineCode); - - return "FROM " + CompileTableExpression(ctx, from); - } - - return string.Empty; - } - - public virtual string CompileJoins(SqlResult ctx) - { - if (!ctx.Query.HasComponent("join", EngineCode)) + else { - return null; + if (query.IsDistinct) + writer.Append("DISTINCT "); + CompileFlatColumns(query, writer); } - - var joins = ctx.Query - .GetComponents("join", EngineCode) - .Select(x => CompileJoin(ctx, x.Join)); - - return "\n" + string.Join("\n", joins); } - public virtual string CompileJoin(SqlResult ctx, Join join, bool isNested = false) + protected void CompileFlatColumns(Query query, Writer writer) { - - var from = join.GetOneComponent("from", EngineCode); - var conditions = join.GetComponents("where", EngineCode); - - var joinTable = CompileTableExpression(ctx, from); - var constraints = CompileConditions(ctx, conditions); - - var onClause = conditions.Any() ? $" ON {constraints}" : ""; - - return $"{join.Type} {joinTable}{onClause}"; - } - - public virtual string CompileWheres(SqlResult ctx) - { - if (!ctx.Query.HasComponent("where", EngineCode)) + var columns = query + .GetComponents("select", EngineCode); + if (columns.Count == 0) { - return null; + writer.Append("*"); } - - var conditions = ctx.Query.GetComponents("where", EngineCode); - var sql = CompileConditions(ctx, conditions).Trim(); - - return string.IsNullOrEmpty(sql) ? null : $"WHERE {sql}"; - } - - public virtual string CompileGroups(SqlResult ctx) - { - if (!ctx.Query.HasComponent("group", EngineCode)) + else { - return null; + CompileColumnList(query, columns, writer); } - - var columns = ctx.Query - .GetComponents("group", EngineCode) - .Select(x => CompileColumn(ctx, x)); - - return "GROUP BY " + string.Join(", ", columns); } - public virtual string CompileOrders(SqlResult ctx) + private void CompileUnion(Query query, Writer writer) { - if (!ctx.Query.HasComponent("order", EngineCode)) - { - return null; - } - - var columns = ctx.Query - .GetComponents("order", EngineCode) - .Select(x => - { - - if (x is RawOrderBy raw) + // Handle UNION, EXCEPT and INTERSECT + writer.List(" ", + query.GetComponents("combine", EngineCode), + clause => { - ctx.Bindings.AddRange(raw.Bindings); - return WrapIdentifiers(raw.Expression); - } - - var direction = (x as OrderBy).Ascending ? "" : " DESC"; - - return Wrap((x as OrderBy).Column) + direction; - }); + if (clause is Combine combine) + { + writer.AppendKeyword(combine.Operation); + writer.Append(" "); + if (combine.All) + writer.Append("ALL "); - return "ORDER BY " + string.Join(", ", columns); + CompileSelectQuery(combine.Query, writer); + } + else if (clause is RawCombine c) + { + writer.AppendRaw(c.Expression, c.Bindings); + } + }); } - public virtual string CompileHaving(SqlResult ctx) + private void CompileTableExpression(AbstractFrom from, Writer writer) { - if (!ctx.Query.HasComponent("having", EngineCode)) + switch (from) { - return null; - } - - var sql = new List(); - string boolOperator; - - var having = ctx.Query.GetComponents("having", EngineCode) - .Cast() - .ToList(); + case RawFromClause raw: + writer.AppendRaw(raw.Expression, raw.Bindings); + return; + case QueryFromClause queryFromClause: + { + var q = queryFromClause.Query; + writer.Append("("); + CompileSelectQuery(q, writer); - for (var i = 0; i < having.Count; i++) - { - var compiled = CompileCondition(ctx, having[i]); + writer.Append(")"); + if (string.IsNullOrEmpty(q.QueryAlias)) + return; - if (!string.IsNullOrEmpty(compiled)) - { - boolOperator = i > 0 ? having[i].IsOr ? "OR " : "AND " : ""; + writer.Append(" "); + writer.Append(TableAsKeyword); + writer.AppendValue(q.QueryAlias); - sql.Add(boolOperator + compiled); + return; } + case FromClause fromClause: + writer.AppendName(fromClause.Table); + return; + default: + throw InvalidClauseException("TableExpression", from); } - - return $"HAVING {string.Join(" ", sql)}"; } - public virtual string CompileLimit(SqlResult ctx) + protected string WriteTable(Query query, Writer writer, string operationName) { - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); - - if (limit == 0 && offset == 0) - { - return null; - } - - if (offset == 0) - { - ctx.Bindings.Add(limit); - return $"LIMIT {parameterPlaceholder}"; - } - - if (limit == 0) - { - ctx.Bindings.Add(offset); - return $"OFFSET {parameterPlaceholder}"; - } - - ctx.Bindings.Add(limit); - ctx.Bindings.Add(offset); - - return $"LIMIT {parameterPlaceholder} OFFSET {parameterPlaceholder}"; + return WriteTable(query.GetOneComponent("from", EngineCode), + writer, operationName); } - /// - /// Compile the random statement into SQL. - /// - /// - /// - public virtual string CompileRandom(string seed) + private static string WriteTable(AbstractFrom? abstractFrom, Writer writer, string operationName) { - return "RANDOM()"; - } + switch (abstractFrom) + { + case null: + throw new InvalidOperationException($"No table set to {operationName}"); - public virtual string CompileLower(string value) - { - return $"LOWER({value})"; + case FromClause fromClauseCast: + writer.AppendName(fromClauseCast.Table); + return fromClauseCast.Table; + case RawFromClause raw: + writer.AppendRaw(raw.Expression, raw.Bindings); + return writer; + default: + throw new InvalidOperationException("Invalid table expression"); + } } - public virtual string CompileUpper(string value) + private void CompileFrom(Query query, Writer writer) { - return $"UPPER({value})"; - } + var from = query.GetOneComponent("from", EngineCode); + if (from == null) + return; - public virtual string CompileTrue() - { - return "true"; + writer.Append("FROM "); + CompileTableExpression(from, writer); } - public virtual string CompileFalse() + private void CompileJoins(Query query, Writer writer) { - return "false"; - } - - private InvalidCastException InvalidClauseException(string section, AbstractClause clause) - { - return new InvalidCastException($"Invalid type \"{clause.GetType().Name}\" provided for the \"{section}\" clause."); - } - - protected string checkOperator(string op) - { - op = op.ToLowerInvariant(); - - var valid = operators.Contains(op) || userOperators.Contains(op); - - if (!valid) + var baseJoins = query.GetComponents("join", EngineCode); + if (baseJoins.Count == 0) { - throw new InvalidOperationException($"The operator '{op}' cannot be used. Please consider white listing it before using it."); + return; } - return op; + writer.Whitespace(); + writer.Append("\n"); + writer.List("\n", baseJoins, x => CompileJoin(query, x.Join, writer)); } - /// - /// Wrap a single string in a column identifier. - /// - /// - /// - public virtual string Wrap(string value) + private void CompileJoin(Query query, Join join, Writer writer) { + var from = join.BaseQuery.GetOneComponent("from", EngineCode); + var conditions = join.BaseQuery.GetComponents("where", EngineCode); - if (value.ToLowerInvariant().Contains(" as ")) - { - var (before, after) = SplitAlias(value); + Debug.Assert(from != null, nameof(from) + " != null"); - return Wrap(before) + $" {ColumnAsKeyword}" + WrapValue(after); - } + writer.Append(join.Type); + writer.Append(" "); + CompileTableExpression(from, writer); - if (value.Contains(".")) + if (conditions.Count > 0) { - return string.Join(".", value.Split('.').Select((x, index) => - { - return WrapValue(x); - })); + writer.Append(" ON "); + CompileConditions(query, conditions, writer); } - - // If we reach here then the value does not contain an "AS" alias - // nor dot "." expression, so wrap it as regular value. - return WrapValue(value); } - public virtual (string, string) SplitAlias(string value) + private void CompileWheres(Query query, Writer writer) { - var index = value.LastIndexOf(" as ", StringComparison.OrdinalIgnoreCase); - - if (index > 0) - { - var before = value.Substring(0, index); - var after = value.Substring(index + 4); - return (before, after); - } + var conditions = query.GetComponents("where", EngineCode); + if (!conditions.Any()) return; - return (value, null); + writer.Whitespace(); + writer.Append("WHERE "); + CompileConditions(query, conditions, writer); } - /// - /// Wrap a single string in keyword identifiers. - /// - /// - /// - public virtual string WrapValue(string value) + private void CompileGroups(Query query, Writer writer) { - if (value == "*") return value; - - var opening = this.OpeningIdentifier; - var closing = this.ClosingIdentifier; - - if (string.IsNullOrWhiteSpace(opening) && string.IsNullOrWhiteSpace(closing)) return value; - - return opening + value.Replace(closing, closing + closing) + closing; + var components = query.GetComponents("group", EngineCode); + if (components.Count == 0) return; + writer.Append("GROUP BY "); + CompileColumnList(query, components, writer); } - /// - /// Resolve a parameter - /// - /// - /// - /// - public virtual object Resolve(SqlResult ctx, object parameter) + protected string? CompileOrders(Query query, Writer writer) { - // if we face a literal value we have to return it directly - if (parameter is UnsafeLiteral literal) - { - return literal.Value; - } + var clauses = query + .GetComponents("order", EngineCode); + if (clauses.Count == 0) return null; - // if we face a variable we have to lookup the variable from the predefined variables - if (parameter is Variable variable) - { - var value = ctx.Query.FindVariable(variable.Name); - return value; - } + writer.Append("ORDER BY "); + writer.List(", ", clauses, x => + { + if (x is RawOrderBy raw) + { + writer.AppendRaw(raw.Expression, raw.Bindings); + } + else if (x is OrderBy orderBy) + { + writer.AppendName(orderBy.Column); + if (!orderBy.Ascending) + writer.Append(" DESC"); + } + }); + return writer; + } - return parameter; + private void CompileHaving(Query query, Writer writer) + { + var havingClauses = query.GetComponents("having", EngineCode); + if (havingClauses.Count == 0) return; + writer.Append("HAVING "); + CompileConditions(query, + havingClauses.Cast().ToList(), + writer); } - /// - /// Resolve a parameter and add it to the binding list - /// - /// - /// - /// - public virtual string Parameter(SqlResult ctx, object parameter) + protected virtual string? CompileLimit(Query query, Writer writer) { - // if we face a literal value we have to return it directly - if (parameter is UnsafeLiteral literal) + var limit = query.GetLimit(EngineCode); + if (limit != 0) { - return literal.Value; + writer.Append("LIMIT "); + writer.AppendParameter(limit); } - // if we face a variable we have to lookup the variable from the predefined variables - if (parameter is Variable variable) + var offset = query.GetOffset(EngineCode); + if (offset != 0) { - var value = ctx.Query.FindVariable(variable.Name); - ctx.Bindings.Add(value); - return parameterPlaceholder; + writer.Whitespace(); + writer.Append("OFFSET "); + writer.AppendParameter(offset); } - - ctx.Bindings.Add(parameter); - return parameterPlaceholder; + return writer; } - /// - /// Create query parameter place-holders for an array. - /// - /// - /// - /// - public virtual string Parameterize(SqlResult ctx, IEnumerable values) + protected virtual string CompileTrue() { - return string.Join(", ", values.Select(x => Parameter(ctx, x))); + return "true"; } - /// - /// Wrap an array of values. - /// - /// - /// - public virtual List WrapArray(List values) + protected virtual string CompileFalse() { - return values.Select(x => Wrap(x)).ToList(); + return "false"; } - public virtual string WrapIdentifiers(string input) + private InvalidCastException InvalidClauseException(string section, AbstractClause clause) { - return input - - // deprecated - .ReplaceIdentifierUnlessEscaped(this.EscapeCharacter, "{", this.OpeningIdentifier) - .ReplaceIdentifierUnlessEscaped(this.EscapeCharacter, "}", this.ClosingIdentifier) - - .ReplaceIdentifierUnlessEscaped(this.EscapeCharacter, "[", this.OpeningIdentifier) - .ReplaceIdentifierUnlessEscaped(this.EscapeCharacter, "]", this.ClosingIdentifier); + return new InvalidCastException( + $"Invalid type \"{clause.GetType().Name}\" provided for the \"{section}\" clause."); } } } diff --git a/QueryBuilder/Compilers/CompilerQueryExtensions.cs b/QueryBuilder/Compilers/CompilerQueryExtensions.cs new file mode 100644 index 00000000..472c9aad --- /dev/null +++ b/QueryBuilder/Compilers/CompilerQueryExtensions.cs @@ -0,0 +1,17 @@ +namespace SqlKata.Compilers +{ + public static class CompilerQueryExtensions + { + public static object? Resolve(Query query, object parameter) + { + // if we face a literal value we have to return it directly + if (parameter is UnsafeLiteral literal) return literal.Value; + + // if we face a variable we have to lookup the variable from the predefined variables + if (parameter is Variable variable) + return query.FindVariable(variable.Name); + + return parameter; + } + } +} diff --git a/QueryBuilder/Compilers/ConditionsCompilerProvider.cs b/QueryBuilder/Compilers/ConditionsCompilerProvider.cs deleted file mode 100644 index 6439da94..00000000 --- a/QueryBuilder/Compilers/ConditionsCompilerProvider.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SqlKata.Compilers -{ - internal class ConditionsCompilerProvider - { - private readonly Type compilerType; - private readonly Dictionary methodsCache = new Dictionary(); - private readonly object syncRoot = new object(); - - public ConditionsCompilerProvider(Compiler compiler) - { - this.compilerType = compiler.GetType(); - } - - public MethodInfo GetMethodInfo(Type clauseType, string methodName) - { - // The cache key should take the type and the method name into consideration - var cacheKey = methodName + "::" + clauseType.FullName; - - lock (syncRoot) - { - if (methodsCache.ContainsKey(cacheKey)) - { - return methodsCache[cacheKey]; - } - - return methodsCache[cacheKey] = FindMethodInfo(clauseType, methodName); - } - } - - private MethodInfo FindMethodInfo(Type clauseType, string methodName) - { - MethodInfo methodInfo = compilerType - .GetRuntimeMethods() - .FirstOrDefault(x => x.Name == methodName); - - if (methodInfo == null) - { - throw new Exception($"Failed to locate a compiler for '{methodName}'."); - } - - if (clauseType.IsConstructedGenericType && methodInfo.GetGenericArguments().Any()) - { - methodInfo = methodInfo.MakeGenericMethod(clauseType.GenericTypeArguments); - } - - return methodInfo; - } - } -} diff --git a/QueryBuilder/Compilers/CteFinder.cs b/QueryBuilder/Compilers/CteFinder.cs index fbb0800a..24b6c632 100644 --- a/QueryBuilder/Compilers/CteFinder.cs +++ b/QueryBuilder/Compilers/CteFinder.cs @@ -1,56 +1,35 @@ -using System.Collections.Generic; - namespace SqlKata.Compilers { - public class CteFinder + public static class CteFinder { - private readonly Query query; - private readonly string engineCode; - private HashSet namesOfPreviousCtes; - private List orderedCteList; - - public CteFinder(Query query, string engineCode) - { - this.query = query; - this.engineCode = engineCode; - } - - public List Find() + public static List FindCte(this Query queryToSearch, string? engineCode) { - if (null != orderedCteList) - return orderedCteList; - - namesOfPreviousCtes = new HashSet(); - - orderedCteList = findInternal(query); - - namesOfPreviousCtes.Clear(); - namesOfPreviousCtes = null; - - return orderedCteList; - } + var already = new HashSet(); + return FindRecursively(queryToSearch); - private List findInternal(Query queryToSearch) - { - var cteList = queryToSearch.GetComponents("cte", engineCode); - - var resultList = new List(); - - foreach (var cte in cteList) + List FindRecursively(Query query) { - if (namesOfPreviousCtes.Contains(cte.Alias)) - continue; - - namesOfPreviousCtes.Add(cte.Alias); - resultList.Add(cte); - - if (cte is QueryFromClause queryFromClause) + var result = new List(); + foreach (var cte in query.GetComponents("cte", engineCode)) { - resultList.InsertRange(0, findInternal(queryFromClause.Query)); + if (!already.Add(cte.GetAlias())) + continue; + if (cte is QueryFromClause qfc) + result.InsertRange(0, FindRecursively(qfc.Query)); + result.Add(cte); } - } - return resultList; + return result; + } } + + private static string GetAlias(this AbstractFrom cte) => + cte switch + { + AdHocTableFromClause x => x.Alias, + QueryFromClause x => x.Alias!, + RawFromClause x => x.Alias!, + _ => throw new ArgumentOutOfRangeException(nameof(cte)) + }; } } diff --git a/QueryBuilder/Compilers/FirebirdCompiler.cs b/QueryBuilder/Compilers/FirebirdCompiler.cs index 61ab9547..259a03f9 100644 --- a/QueryBuilder/Compilers/FirebirdCompiler.cs +++ b/QueryBuilder/Compilers/FirebirdCompiler.cs @@ -1,118 +1,138 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; - namespace SqlKata.Compilers { public class FirebirdCompiler : Compiler { public FirebirdCompiler() { + EngineCode = EngineCodes.Firebird; + SingleRowDummyTableName = "RDB$DATABASE"; + XService = new("\"", "\"", "AS ", true); } - public override string EngineCode { get; } = EngineCodes.Firebird; - protected override string SingleRowDummyTableName => "RDB$DATABASE"; - - protected override SqlResult CompileInsertQuery(Query query) + protected override void CompileInsertQuery(Query query, Writer writer) { - var ctx = base.CompileInsertQuery(query); - - var inserts = ctx.Query.GetComponents("insert", EngineCode); + var inserts = query.GetComponents("insert", EngineCode); + if (inserts[0] is InsertQueryClause) + { + base.CompileInsertQuery(query, writer); + return; + } - if (inserts.Count > 1) + var clauses = inserts.Cast().ToArray(); + if (clauses.Length == 1) { - ctx.RawSql = Regex.Replace(ctx.RawSql, @"\)\s+VALUES\s+\(", ") SELECT "); - ctx.RawSql = Regex.Replace(ctx.RawSql, @"\),\s*\(", " FROM RDB$DATABASE UNION ALL SELECT "); - ctx.RawSql = Regex.Replace(ctx.RawSql, @"\)$", " FROM RDB$DATABASE"); + base.CompileInsertQuery(query, writer); + return; } + CompileValueInsertClauses(clauses); + return; - return ctx; + void CompileValueInsertClauses(InsertClause[] insertClauses) + { + var firstInsert = insertClauses.First(); + + writer.Append(MultiInsertStartClause); + writer.Append(" "); + var table = WriteTable(query, writer, "insert"); + writer.WriteInsertColumnsList(firstInsert.Columns); + writer.Append(" SELECT "); + writer.CommaSeparatedParameters(query, firstInsert.Values); + CompileRemainingInsertClauses(query, table, writer, insertClauses); + } } - public override string CompileLimit(SqlResult ctx) + protected override void CompileRemainingInsertClauses(Query query, + string table, Writer writer, IEnumerable inserts) { - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + foreach (var insert in inserts.Skip(1)) + { + writer.Append(" FROM RDB$DATABASE UNION ALL SELECT "); + writer.CommaSeparatedParameters(query, insert.Values); + } + writer.Append(" FROM RDB$DATABASE"); + } + protected override string? CompileLimit(Query query, Writer writer) + { + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); if (limit > 0 && offset > 0) { - ctx.Bindings.Add(offset + 1); - ctx.Bindings.Add(limit + offset); - - return $"ROWS {parameterPlaceholder} TO {parameterPlaceholder}"; + writer.Append("ROWS "); + writer.AppendParameter(offset + 1); + writer.Append(" TO "); + writer.AppendParameter(limit + offset); + return writer; } return null; } - protected override string CompileColumns(SqlResult ctx) + protected override void CompileColumns(Query query, Writer writer) { - var compiled = base.CompileColumns(ctx); - - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); if (limit > 0 && offset == 0) { - ctx.Bindings.Insert(0, limit); - - ctx.Query.ClearComponent("limit"); - - return $"SELECT FIRST {parameterPlaceholder}" + compiled.Substring(6); + writer.Append("SELECT FIRST "); + writer.AppendParameter(limit); + writer.Append(" "); + CompileColumnsAfterSelect(query, writer); + return; } - else if (limit == 0 && offset > 0) - { - ctx.Bindings.Insert(0, offset); - ctx.Query.ClearComponent("offset"); - - return $"SELECT SKIP {parameterPlaceholder}" + compiled.Substring(6); + if (limit == 0 && offset > 0) + { + writer.Append("SELECT SKIP "); + writer.AppendParameter(offset); + writer.Append(" "); + CompileColumnsAfterSelect(query, writer); + return; } - return compiled; + base.CompileColumns(query, writer); } - protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition condition) + protected override void CompileBasicDateCondition(Query query, BasicDateCondition x, Writer writer) { - var column = Wrap(condition.Column); - - string left; - - if (condition.Part == "time") + if (x.IsNot) + writer.Append("NOT ("); + if (x.Part == "time") { - left = $"CAST({column} as TIME)"; + writer.Append("CAST("); + writer.AppendName(x.Column); + writer.Append(" as TIME) "); } - else if (condition.Part == "date") + else if (x.Part == "date") { - left = $"CAST({column} as DATE)"; + writer.Append("CAST("); + writer.AppendName(x.Column); + writer.Append(" as DATE) "); } else { - left = $"EXTRACT({condition.Part.ToUpperInvariant()} FROM {column})"; + writer.Append("EXTRACT("); + writer.Append(x.Part.ToUpperInvariant()); + writer.Append(" FROM "); + writer.AppendName(x.Column); + writer.Append(") "); } - - var sql = $"{left} {condition.Operator} {Parameter(ctx, condition.Value)}"; - - if (condition.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; + writer.Append(Operators.CheckOperator(x.Operator)); + writer.Append(" "); + writer.AppendParameter(query, x.Value); + if (x.IsNot) + writer.Append(")"); } - public override string WrapValue(string value) - { - return base.WrapValue(value).ToUpperInvariant(); - } - public override string CompileTrue() + protected override string CompileTrue() { return "1"; } - public override string CompileFalse() + protected override string CompileFalse() { return "0"; } diff --git a/QueryBuilder/Compilers/MySqlCompiler.cs b/QueryBuilder/Compilers/MySqlCompiler.cs index 4729125b..eb459cba 100644 --- a/QueryBuilder/Compilers/MySqlCompiler.cs +++ b/QueryBuilder/Compilers/MySqlCompiler.cs @@ -4,46 +4,43 @@ public class MySqlCompiler : Compiler { public MySqlCompiler() { - OpeningIdentifier = ClosingIdentifier = "`"; + XService = new X("`", "`", "AS "); LastId = "SELECT last_insert_id() as Id"; + EngineCode = EngineCodes.MySql; } - public override string EngineCode { get; } = EngineCodes.MySql; - - public override string CompileLimit(SqlResult ctx) + protected override string? CompileLimit(Query query, Writer writer) { - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); - + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); - if (offset == 0 && limit == 0) - { - return null; - } + if (offset == 0 && limit == 0) return null; if (offset == 0) { - ctx.Bindings.Add(limit); - return $"LIMIT {parameterPlaceholder}"; + writer.Append("LIMIT "); + writer.AppendParameter(limit); + return writer; } 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}"; + writer.Append("LIMIT 18446744073709551615 OFFSET "); + writer.AppendParameter(offset); + return writer; } // We have both values - ctx.Bindings.Add(limit); - ctx.Bindings.Add(offset); - - return $"LIMIT {parameterPlaceholder} OFFSET {parameterPlaceholder}"; + writer.Append("LIMIT "); + writer.AppendParameter(limit); + writer.Append(" OFFSET "); + writer.AppendParameter(offset); + return writer; } } } diff --git a/QueryBuilder/Compilers/OracleCompiler.cs b/QueryBuilder/Compilers/OracleCompiler.cs index 610ec20d..eb7049d1 100644 --- a/QueryBuilder/Compilers/OracleCompiler.cs +++ b/QueryBuilder/Compilers/OracleCompiler.cs @@ -1,137 +1,145 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text.RegularExpressions; - namespace SqlKata.Compilers { public class OracleCompiler : Compiler { public OracleCompiler() { - ColumnAsKeyword = ""; + XService = new("\"", "\"", ""); TableAsKeyword = ""; - parameterPrefix = ":p"; + ParameterPrefix = ":p"; MultiInsertStartClause = "INSERT ALL INTO"; + EngineCode = EngineCodes.Oracle; + SingleRowDummyTableName = "DUAL"; } - public override string EngineCode { get; } = EngineCodes.Oracle; - public bool UseLegacyPagination { get; set; } = false; - protected override string SingleRowDummyTableName => "DUAL"; + public bool UseLegacyPagination { get; init; } - protected override SqlResult CompileSelectQuery(Query query) + protected override void CompileSelectQuery(Query query, Writer writer) { if (!UseLegacyPagination) { - return base.CompileSelectQuery(query); + base.CompileSelectQuery(query, writer); + return; } - var result = base.CompileSelectQuery(query); + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); - ApplyLegacyLimit(result); - - return result; - } - - public override string CompileLimit(SqlResult ctx) - { - if (UseLegacyPagination) + if (limit == 0 && offset == 0) { - // in pre-12c versions of Oracle, limit is handled by ROWNUM techniques - return null; + base.CompileSelectQuery(query, writer); + return; } - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); - - if (limit == 0 && offset == 0) + if (limit == 0) { - return null; + writer.Append("""SELECT * FROM (SELECT "results_wrapper".*, ROWNUM "row_num" FROM ("""); + base.CompileSelectQuery(query, writer); + writer.Append(""") "results_wrapper") WHERE "row_num" > """); + writer.AppendParameter(offset); } - - var safeOrder = ""; - - if (!ctx.Query.HasComponent("order")) + else if (offset == 0) { - safeOrder = "ORDER BY (SELECT 0 FROM DUAL) "; + writer.Append("""SELECT * FROM ("""); + base.CompileSelectQuery(query, writer); + writer.Append(""") WHERE ROWNUM <= """); + writer.AppendParameter(limit); } - - if (limit == 0) + else { - ctx.Bindings.Add(offset); - return $"{safeOrder}OFFSET {parameterPlaceholder} ROWS"; + writer.Append("""SELECT * FROM (SELECT "results_wrapper".*, ROWNUM "row_num" FROM ("""); + base.CompileSelectQuery(query, writer); + writer.Append(""") "results_wrapper" WHERE ROWNUM <= """); + writer.AppendParameter(limit + offset); + writer.Append(""") WHERE "row_num" > """); + writer.AppendParameter(offset); } - - ctx.Bindings.Add(offset); - ctx.Bindings.Add(limit); - - return $"{safeOrder}OFFSET {parameterPlaceholder} ROWS FETCH NEXT {parameterPlaceholder} ROWS ONLY"; } - internal void ApplyLegacyLimit(SqlResult ctx) + protected override string? CompileLimit(Query query, Writer writer) { - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + if (UseLegacyPagination) + // in pre-12c versions of Oracle, + // limit is handled by ROWNUM techniques + return null; - if (limit == 0 && offset == 0) + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); + + if (limit == 0 && offset == 0) return null; + + if (!query.HasComponent("order")) { - return; + writer.Append("ORDER BY (SELECT 0 FROM DUAL) "); } - string newSql; if (limit == 0) { - newSql = $"SELECT * FROM (SELECT \"results_wrapper\".*, ROWNUM \"row_num\" FROM ({ctx.RawSql}) \"results_wrapper\") WHERE \"row_num\" > {parameterPlaceholder}"; - ctx.Bindings.Add(offset); - } - else if (offset == 0) - { - newSql = $"SELECT * FROM ({ctx.RawSql}) WHERE ROWNUM <= {parameterPlaceholder}"; - ctx.Bindings.Add(limit); - } - else - { - newSql = $"SELECT * FROM (SELECT \"results_wrapper\".*, ROWNUM \"row_num\" FROM ({ctx.RawSql}) \"results_wrapper\" WHERE ROWNUM <= {parameterPlaceholder}) WHERE \"row_num\" > {parameterPlaceholder}"; - ctx.Bindings.Add(limit + offset); - ctx.Bindings.Add(offset); + writer.Append("OFFSET "); + writer.AppendParameter(offset); + writer.Append(" ROWS"); + return writer; } - ctx.RawSql = newSql; + writer.Append("OFFSET "); + writer.AppendParameter(offset); + writer.Append(" ROWS FETCH NEXT "); + writer.AppendParameter(limit); + writer.Append(" ROWS ONLY"); + return writer; } - protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition condition) + protected override void CompileBasicDateCondition(Query query, BasicDateCondition condition, Writer writer) { + var isDateTime = condition.Value is DateTime; - var column = Wrap(condition.Column); - var value = Parameter(ctx, condition.Value); - - var sql = ""; - var valueFormat = ""; - - var isDateTime = (condition.Value is DateTime dt); - + if (condition.IsNot) + writer.Append("NOT ("); switch (condition.Part) { case "date": // assume YY-MM-DD format + writer.Append("TO_CHAR("); + writer.AppendName(condition.Column); + writer.Append(", 'YY-MM-DD') "); + writer.Append(condition.Operator); + writer.Append(" TO_CHAR("); if (isDateTime) - valueFormat = $"{value}"; + { + writer.AppendParameter(query, condition.Value); + } else - valueFormat = $"TO_DATE({value}, 'YY-MM-DD')"; - sql = $"TO_CHAR({column}, 'YY-MM-DD') {condition.Operator} TO_CHAR({valueFormat}, 'YY-MM-DD')"; + { + writer.Append("TO_DATE("); + writer.AppendParameter(query, condition.Value); + writer.Append(", 'YY-MM-DD')"); + } + writer.Append(", 'YY-MM-DD')"); break; case "time": if (isDateTime) - valueFormat = $"{value}"; + { + writer.Append("TO_CHAR("); + writer.AppendName(condition.Column); + writer.Append(", 'HH24:MI:SS') "); + writer.Append(condition.Operator); + writer.Append(" TO_CHAR("); + writer.AppendParameter(query, condition.Value); + writer.Append(", 'HH24:MI:SS')"); + } else { - // assume HH:MM format - if (condition.Value.ToString().Split(':').Count() == 2) - valueFormat = $"TO_DATE({value}, 'HH24:MI')"; - else // assume HH:MM:SS format - valueFormat = $"TO_DATE({value}, 'HH24:MI:SS')"; + writer.Append("TO_CHAR("); + writer.AppendName(condition.Column); + writer.Append(", 'HH24:MI:SS') "); + writer.Append(condition.Operator); + writer.Append(" TO_CHAR("); + writer.Append("TO_DATE("); + writer.AppendParameter(query, condition.Value); + var isHhSs = condition.Value.ToString()! + .Split(':').Length == 2; + writer.Append(isHhSs ? ", 'HH24:MI')" : ", 'HH24:MI:SS')"); + writer.Append(", 'HH24:MI:SS')"); } - sql = $"TO_CHAR({column}, 'HH24:MI:SS') {condition.Operator} TO_CHAR({valueFormat}, 'HH24:MI:SS')"; break; case "year": case "month": @@ -139,38 +147,41 @@ protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCond case "hour": case "minute": case "second": - sql = $"EXTRACT({condition.Part.ToUpperInvariant()} FROM {column}) {condition.Operator} {value}"; + writer.Append("EXTRACT("); + writer.AppendKeyword(condition.Part); + writer.Append(" FROM "); + writer.AppendName(condition.Column); + writer.Append(") "); + writer.Append(condition.Operator); + writer.Append(" "); + writer.AppendParameter(query, condition.Value); break; default: - sql = $"{column} {condition.Operator} {value}"; + writer.AppendName(condition.Column); + writer.Append(" "); + writer.Append(condition.Operator); + writer.Append(" "); + writer.AppendParameter(query, condition.Value); break; } - if (condition.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; - + writer.Append(")"); } - protected override SqlResult CompileRemainingInsertClauses( - SqlResult ctx, string table, IEnumerable inserts) + protected override void CompileRemainingInsertClauses(Query query, string table, + Writer writer, + IEnumerable inserts) { foreach (var insert in inserts.Skip(1)) { - string columns = GetInsertColumnsList(insert.Columns); - string values = string.Join(", ", Parameterize(ctx, insert.Values)); - - string intoFormat = " INTO {0}{1} VALUES ({2})"; - var nextInsert = string.Format(intoFormat, table, columns, values); - - ctx.RawSql += nextInsert; + writer.Append(" INTO "); + writer.AppendName(table); + writer.WriteInsertColumnsList(insert.Columns); + writer.Append(" VALUES ("); + writer.CommaSeparatedParameters(query, insert.Values); + writer.Append(")"); } - - ctx.RawSql += " SELECT 1 FROM DUAL"; - return ctx; + writer.Append(" SELECT 1 FROM DUAL"); } } } diff --git a/QueryBuilder/Compilers/PostgresCompiler.cs b/QueryBuilder/Compilers/PostgresCompiler.cs index 3b45d0e6..0039f627 100644 --- a/QueryBuilder/Compilers/PostgresCompiler.cs +++ b/QueryBuilder/Compilers/PostgresCompiler.cs @@ -1,99 +1,91 @@ -using System; -using System.Linq; - namespace SqlKata.Compilers { public class PostgresCompiler : Compiler { + private static readonly string[] LikeOperators = { "starts", "ends", "contains", "like", "ilike" }; + public PostgresCompiler() { LastId = "SELECT lastval() AS id"; + EngineCode = EngineCodes.PostgreSql; + SupportsFilterClause = true; } - public override string EngineCode { get; } = EngineCodes.PostgreSql; - public override bool SupportsFilterClause { get; set; } = true; - - - protected override string CompileBasicStringCondition(SqlResult ctx, BasicStringCondition x) + protected override void CompileBasicStringCondition( + Query query, BasicStringCondition x, Writer writer) { - - var column = Wrap(x.Column); - - var value = Resolve(ctx, x.Value) as string; - - if (value == null) - { + if (CompilerQueryExtensions.Resolve(query, x.Value) is not string value) throw new ArgumentException("Expecting a non nullable string"); - } - var method = x.Operator; + var isLikeOperator = LikeOperators.Contains(x.Operator); - if (new[] { "starts", "ends", "contains", "like", "ilike" }.Contains(x.Operator)) + if (x.IsNot) + writer.Append("NOT ("); + writer.AppendName(x.Column); + writer.Append(" "); + writer.Append(Operators.CheckOperator(isLikeOperator + ? x.CaseSensitive ? "LIKE" : "ILIKE" : x.Operator)); + writer.Append(" "); + if (isLikeOperator) { - method = x.CaseSensitive ? "LIKE" : "ILIKE"; - - switch (x.Operator) + value = x.Operator switch { - case "starts": - value = $"{value}%"; - break; - case "ends": - value = $"%{value}"; - break; - case "contains": - value = $"%{value}%"; - break; - } - } - - string sql; - - if (x.Value is UnsafeLiteral) - { - sql = $"{column} {checkOperator(method)} {value}"; + "starts" => $"{value}%", + "ends" => $"%{value}", + "contains" => $"%{value}%", + _ => value + }; + writer.AppendParameter(query, value); } else { - sql = $"{column} {checkOperator(method)} {Parameter(ctx, value)}"; + // This code is written as if other than "like" + // operators are possible, but the public API + // does not instantiate BasicStringCondition + writer.AppendParameter(query, value); } - - if (!string.IsNullOrEmpty(x.EscapeCharacter)) + if (x.EscapeCharacter is { } esc1) { - sql = $"{sql} ESCAPE '{x.EscapeCharacter}'"; + writer.Append(" ESCAPE '"); + writer.Append(esc1); + writer.Append('\''); } - return x.IsNot ? $"NOT ({sql})" : sql; - + if (x.IsNot) + writer.Append(")"); } - - - protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition condition) + + protected override void CompileBasicDateCondition( + Query query, BasicDateCondition condition, Writer writer) { - var column = Wrap(condition.Column); - - string left; + if (condition.IsNot) + writer.Append("NOT ("); if (condition.Part == "time") { - left = $"{column}::time"; + writer.AppendName(condition.Column); + writer.Append("::time"); } else if (condition.Part == "date") { - left = $"{column}::date"; + writer.AppendName(condition.Column); + writer.Append("::date"); } else { - left = $"DATE_PART('{condition.Part.ToUpperInvariant()}', {column})"; + writer.Append("DATE_PART('"); + writer.AppendKeyword(condition.Part); + writer.Append("', "); + writer.AppendName(condition.Column); + writer.Append(")"); } - var sql = $"{left} {condition.Operator} {Parameter(ctx, condition.Value)}"; - + writer.Append(" "); + writer.Append(condition.Operator); + writer.Append(" "); + writer.AppendParameter(query, condition.Value); if (condition.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; + writer.Append(")"); } } } diff --git a/QueryBuilder/Compilers/SqlServerCompiler.cs b/QueryBuilder/Compilers/SqlServerCompiler.cs index 0202f0f1..35d406c7 100644 --- a/QueryBuilder/Compilers/SqlServerCompiler.cs +++ b/QueryBuilder/Compilers/SqlServerCompiler.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Diagnostics; namespace SqlKata.Compilers { @@ -6,185 +6,185 @@ public class SqlServerCompiler : Compiler { public SqlServerCompiler() { - OpeningIdentifier = "["; - ClosingIdentifier = "]"; + XService = new X("[", "]", "AS "); LastId = "SELECT scope_identity() as Id"; + EngineCode = EngineCodes.SqlServer; } - public override string EngineCode { get; } = EngineCodes.SqlServer; - public bool UseLegacyPagination { get; set; } = false; + public bool UseLegacyPagination { get; init; } - protected override SqlResult CompileSelectQuery(Query query) + protected override void CompileSelectQuery(Query original, Writer writer) { - if (!UseLegacyPagination || !query.HasOffset(EngineCode)) + if (!UseLegacyPagination || !original.HasOffset(EngineCode)) { - return base.CompileSelectQuery(query); + base.CompileSelectQuery(original, writer); + return; } - query = query.Clone(); - - var ctx = new SqlResult - { - Query = query, - }; - - var limit = query.GetLimit(EngineCode); - var offset = query.GetOffset(EngineCode); - - - if (!query.HasComponent("select")) - { - query.Select("*"); - } - - var order = CompileOrders(ctx) ?? "ORDER BY (SELECT 0)"; - - query.SelectRaw($"ROW_NUMBER() OVER ({order}) AS [row_num]", ctx.Bindings.ToArray()); - - query.ClearComponent("order"); - - - var result = base.CompileSelectQuery(query); + var limit = original.GetLimit(EngineCode); + var offset = original.GetOffset(EngineCode); + var modified = ModifyQuery(original.Clone()); + writer.Append("SELECT * FROM ("); + base.CompileSelectQuery(modified, writer); + writer.Append(") AS [results_wrapper] WHERE [row_num] "); if (limit == 0) { - result.RawSql = $"SELECT * FROM ({result.RawSql}) AS [results_wrapper] WHERE [row_num] >= {parameterPlaceholder}"; - result.Bindings.Add(offset + 1); + writer.Append(">= "); + writer.AppendParameter(offset + 1); } else { - result.RawSql = $"SELECT * FROM ({result.RawSql}) AS [results_wrapper] WHERE [row_num] BETWEEN {parameterPlaceholder} AND {parameterPlaceholder}"; - result.Bindings.Add(offset + 1); - result.Bindings.Add(limit + offset); + writer.Append("BETWEEN "); + writer.AppendParameter(offset + 1); + writer.Append(" AND "); + writer.AppendParameter(limit + offset); } - - return result; } - protected override string CompileColumns(SqlResult ctx) + private Query ModifyQuery(Query query) { - var compiled = base.CompileColumns(ctx); + if (!query.HasComponent("select")) query.Select("*"); + + var writer = new Writer(XService); + var order = CompileOrders(query, writer) ?? "ORDER BY (SELECT 0)"; + query.SelectRaw($"ROW_NUMBER() OVER ({order}) AS [row_num]"); + + query.RemoveComponent("order"); + return query; + } + protected override void CompileColumns(Query query, Writer writer) + { if (!UseLegacyPagination) { - return compiled; + base.CompileColumns(query, writer); + return; } // If there is a limit on the query, but not an offset, we will add the top // clause to the query, which serves as a "limit" type clause within the // SQL Server system similar to the limit keywords available in MySQL. - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); if (limit > 0 && offset == 0) { - // top bindings should be inserted first - ctx.Bindings.Insert(0, limit); - - ctx.Query.ClearComponent("limit"); + query.RemoveComponent("limit"); // handle distinct - if (compiled.IndexOf("SELECT DISTINCT") == 0) + if (!query.HasComponent("aggregate", EngineCode) && query.IsDistinct) { - return $"SELECT DISTINCT TOP ({parameterPlaceholder}){compiled.Substring(15)}"; + writer.Append("SELECT DISTINCT TOP ("); + writer.AppendParameter(limit); + writer.Append(") "); + CompileFlatColumns(query, writer); + return; } - return $"SELECT TOP ({parameterPlaceholder}){compiled.Substring(6)}"; + writer.Append("SELECT TOP ("); + writer.AppendParameter(limit); + writer.Append(") "); + CompileColumnsAfterSelect(query, writer); + return; } - return compiled; + base.CompileColumns(query, writer); } - public override string CompileLimit(SqlResult ctx) + protected override string? CompileLimit(Query query, Writer writer) { if (UseLegacyPagination) - { // in legacy versions of Sql Server, limit is handled by TOP // and ROW_NUMBER techniques return null; - } - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); - if (limit == 0 && offset == 0) - { - return null; - } + if (limit == 0 && offset == 0) return null; - var safeOrder = ""; - if (!ctx.Query.HasComponent("order")) - { - safeOrder = "ORDER BY (SELECT 0) "; - } + if (!query.HasComponent("order")) writer.Append("ORDER BY (SELECT 0) "); if (limit == 0) { - ctx.Bindings.Add(offset); - return $"{safeOrder}OFFSET {parameterPlaceholder} ROWS"; + writer.Append("OFFSET "); + writer.AppendParameter(offset); + writer.Append(" ROWS"); + return writer; } - ctx.Bindings.Add(offset); - ctx.Bindings.Add(limit); - - return $"{safeOrder}OFFSET {parameterPlaceholder} ROWS FETCH NEXT {parameterPlaceholder} ROWS ONLY"; - } - - public override string CompileRandom(string seed) - { - return "NEWID()"; + writer.Append("OFFSET "); + writer.AppendParameter(offset); + writer.Append(" ROWS FETCH NEXT "); + writer.AppendParameter(limit); + writer.Append(" ROWS ONLY"); + return writer; } - public override string CompileTrue() + protected override string CompileTrue() { return "cast(1 as bit)"; } - public override string CompileFalse() + protected override string CompileFalse() { return "cast(0 as bit)"; } - protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition condition) + protected override void CompileBasicDateCondition(Query query, + BasicDateCondition condition, Writer writer) { - var column = Wrap(condition.Column); var part = condition.Part.ToUpperInvariant(); - string left; + if (condition.IsNot) + writer.Append("NOT ("); - if (part == "TIME" || part == "DATE") + if (part is "TIME" or "DATE") { - left = $"CAST({column} AS {part.ToUpperInvariant()})"; + writer.Append("CAST("); + writer.AppendName(condition.Column); + writer.Append(" AS "); + writer.Append(part); + writer.Append(")"); } else { - left = $"DATEPART({part.ToUpperInvariant()}, {column})"; + writer.Append("DATEPART("); + writer.Append(part); + writer.Append(", "); + writer.AppendName(condition.Column); + writer.Append(")"); } - var sql = $"{left} {condition.Operator} {Parameter(ctx, condition.Value)}"; - + writer.Append(" "); + writer.Append(condition.Operator); + writer.Append(" "); + writer.AppendParameter(query, condition.Value); if (condition.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; + writer.Append(")"); } - protected override SqlResult CompileAdHocQuery(AdHocTableFromClause adHoc) + protected override void CompileAdHocQuery(AdHocTableFromClause adHoc, Writer writer) { - var ctx = new SqlResult(); - - var colNames = string.Join(", ", adHoc.Columns.Select(Wrap)); - - var valueRow = string.Join(", ", Enumerable.Repeat(parameterPlaceholder, adHoc.Columns.Count)); - var valueRows = string.Join(", ", Enumerable.Repeat($"({valueRow})", adHoc.Values.Count / adHoc.Columns.Count)); - var sql = $"SELECT {colNames} FROM (VALUES {valueRows}) AS tbl ({colNames})"; - - ctx.RawSql = sql; - ctx.Bindings = adHoc.Values; - - return ctx; + Debug.Assert(adHoc.Alias != null, "adHoc.Alias != null"); + writer.AppendValue(adHoc.Alias); + writer.Append(" AS (SELECT "); + writer.WriteInsertColumnsList(adHoc.Columns, false); + writer.Append(" FROM (VALUES "); + writer.List(", ", adHoc.Values.Length / adHoc.Columns.Length, _ => + { + writer.Append("("); + writer.List(", ", adHoc.Columns.Length, _ => + { + writer.Append("?"); + }); + writer.Append(")"); + }); + writer.BindMany(adHoc.Values); + writer.Append(") AS tbl"); + writer.WriteInsertColumnsList(adHoc.Columns); + writer.Append(")"); } } } diff --git a/QueryBuilder/Compilers/SqliteCompiler.cs b/QueryBuilder/Compilers/SqliteCompiler.cs index 1401dd35..ccc46264 100644 --- a/QueryBuilder/Compilers/SqliteCompiler.cs +++ b/QueryBuilder/Compilers/SqliteCompiler.cs @@ -1,67 +1,76 @@ -using System.Collections.Generic; - namespace SqlKata.Compilers { - public class SqliteCompiler : Compiler + public sealed class SqliteCompiler : Compiler { - public override string EngineCode { get; } = EngineCodes.Sqlite; - protected override string OpeningIdentifier { get; set; } = "\""; - protected override string ClosingIdentifier { get; set; } = "\""; - protected override string LastId { get; set; } = "select last_insert_rowid() as id"; - public override bool SupportsFilterClause { get; set; } = true; + private static readonly Dictionary FormatMap = new() + { + { "date", "%Y-%m-%d" }, + { "time", "%H:%M:%S" }, + { "year", "%Y" }, + { "month", "%m" }, + { "day", "%d" }, + { "hour", "%H" }, + { "minute", "%M" } + }; + + public SqliteCompiler() + { + LastId = "select last_insert_rowid() as id"; + EngineCode = EngineCodes.Sqlite; + SupportsFilterClause = true; + } - public override string CompileTrue() + protected override string CompileTrue() { return "1"; } - public override string CompileFalse() + protected override string CompileFalse() { return "0"; } - public override string CompileLimit(SqlResult ctx) + protected override string? CompileLimit(Query query, Writer writer) { - var limit = ctx.Query.GetLimit(EngineCode); - var offset = ctx.Query.GetOffset(EngineCode); + var limit = query.GetLimit(EngineCode); + var offset = query.GetOffset(EngineCode); if (limit == 0 && offset > 0) { - ctx.Bindings.Add(offset); - return $"LIMIT -1 OFFSET {parameterPlaceholder}"; + writer.Append("LIMIT -1 OFFSET "); + writer.AppendParameter(offset); + return writer; } - return base.CompileLimit(ctx); + if (base.CompileLimit(query, writer) == null) return null; + return writer; } - protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCondition condition) + protected override void CompileBasicDateCondition(Query query, BasicDateCondition condition, Writer writer) { - var column = Wrap(condition.Column); - var value = Parameter(ctx, condition.Value); - - var formatMap = new Dictionary { - { "date", "%Y-%m-%d" }, - { "time", "%H:%M:%S" }, - { "year", "%Y" }, - { "month", "%m" }, - { "day", "%d" }, - { "hour", "%H" }, - { "minute", "%M" }, - }; - - if (!formatMap.ContainsKey(condition.Part)) + if (!FormatMap.ContainsKey(condition.Part)) { - return $"{column} {condition.Operator} {value}"; + writer.AppendName(condition.Column); + writer.Append(" "); + writer.Append(condition.Operator); + writer.Append(" "); + writer.AppendParameter(query, condition.Value); + return; } - var sql = $"strftime('{formatMap[condition.Part]}', {column}) {condition.Operator} cast({value} as text)"; - if (condition.IsNot) - { - return $"NOT ({sql})"; - } - - return sql; + writer.Append("NOT ("); + writer.Append("strftime('"); + writer.Append(FormatMap[condition.Part]); + writer.Append("', "); + writer.AppendName(condition.Column); + writer.Append(") "); + writer.Append(condition.Operator); + writer.Append(" cast("); + writer.AppendParameter(query, condition.Value); + writer.Append(" as text)"); + if (condition.IsNot) + writer.Append(")"); } } } diff --git a/QueryBuilder/Compilers/StringExt.cs b/QueryBuilder/Compilers/StringExt.cs new file mode 100644 index 00000000..a71cd4e1 --- /dev/null +++ b/QueryBuilder/Compilers/StringExt.cs @@ -0,0 +1,35 @@ +using System.Collections; + +namespace SqlKata.Compilers +{ + public static class StringExt { + public static int CountMatches(this string source, string substring) + { + int count = 0, n = 0; + + if(substring != "") + { + while ((n = source.IndexOf(substring, n, StringComparison.InvariantCulture)) != -1) + { + n += substring.Length; + ++count; + } + } + + return count; + } + public static string StrJoin(this IEnumerable src, string separator) + { + return string.Join(separator, src.Cast()); + } + public static string Brace(this string value, string opening, string closing) + { + if (value == "*") return value; + + if (string.IsNullOrWhiteSpace(opening) && + string.IsNullOrWhiteSpace(closing)) return value; + + return opening + value.Replace(closing, closing + closing) + closing; + } + } +} diff --git a/QueryBuilder/Compilers/WhiteList.cs b/QueryBuilder/Compilers/WhiteList.cs new file mode 100644 index 00000000..2d770856 --- /dev/null +++ b/QueryBuilder/Compilers/WhiteList.cs @@ -0,0 +1,38 @@ +namespace SqlKata.Compilers +{ + // TODO: Refactor + public sealed class WhiteList + { + private readonly HashSet _operators = new() + { + "=", "<", ">", "<=", ">=", "<>", "!=", "<=>", + "like", "not like", + "ilike", "not ilike", + "like binary", "not like binary", + "rlike", "not rlike", + "regexp", "not regexp", + "similar to", "not similar to" + }; + + private readonly HashSet _userOperators = new(); + public string CheckOperator(string op) + { + op = op.ToLowerInvariant(); + + var valid = _operators.Contains(op) || _userOperators.Contains(op); + + if (!valid) + throw new InvalidOperationException( + $"The operator '{op}' cannot be used. Please consider white listing it before using it."); + + return op; + } + + public void Whitelist(params string[] operators) + { + foreach (var op in operators) + _userOperators.Add(op); + + } + } +} diff --git a/QueryBuilder/Compilers/Writer.cs b/QueryBuilder/Compilers/Writer.cs new file mode 100644 index 00000000..dd7d8ce9 --- /dev/null +++ b/QueryBuilder/Compilers/Writer.cs @@ -0,0 +1,171 @@ +using System.Diagnostics; +using System.Text; +using FluentAssertions; + +namespace SqlKata.Compilers +{ + public sealed class Writer + { + public IReadOnlyList Bindings => _bindings; + + private void BindOne(object? value) + { + BindOneInner(value); + EnsureBindingMatch(); + } + + private void BindOneInner(object? value) + { + if (value?.AsArray() is { } arr) + _bindings.AddRange(arr.Cast()); + else + _bindings.Add(value); + } + + public void BindMany(IEnumerable values) + { + foreach (var binding in values) + BindOneInner(binding); + EnsureBindingMatch(); + } + [Conditional("DEBUG")] + public void EnsureBindingMatch() + { + S.ToString().CountMatches("?").Should() + .Be(_bindings.FlattenOneLevel().Count()); + } + + public X X { get; } + private readonly List _bindings = new(); + private StringBuilder S { get; } = new(); + public static implicit operator string(Writer w) => w.S.ToString(); + + public Writer(X x) + { + X = x; + } + + public void List(string separator, int repeatCount, Action? renderItem = null) + { + renderItem ??= i => S.Append(i); + for (var i = 0; i < repeatCount; i++) + { + renderItem(i); + if (i != repeatCount - 1) + S.Append(separator); + } + } + + public void List(string separator, IEnumerable list, Action? renderItem = null) + { + renderItem ??= i => S.Append(i); + var any = false; + foreach (var item in list) + { + renderItem(item); + S.Append(separator); + any = true; + } + + if (any) S.Length -= separator.Length; + } + + public void List(string separator, IEnumerable list, Action? renderItem) + where T : notnull + { + renderItem ??= (i, _) => S.Append(i); + var counter = 0; + foreach (var item in list) + if (item != null) + { + renderItem(item, counter); + S.Append(separator); + counter++; + } + + if (counter > 0) S.Length -= separator.Length; + } + + public void WhitespaceSeparated(params Action[] list) + { + foreach (var item in list) + { + item(); + Whitespace(); + } + if (S.Length > 0 && S[^1] == ' ') S.Length -= 1; + } + + public void AppendParameter(Query query, object? value) + { + switch (value) + { + case UnsafeLiteral literal: + // if we face a literal value we have to return it directly + Append(literal.Value); + break; + case Variable variable: + { + // if we face a variable we have to lookup the variable from the predefined variables + Append("?"); + BindOne(query.FindVariable(variable.Name)); + break; + } + default: + Append("?"); + BindOne(value); + break; + } + } + public void Append(string? value) => S.Append(value); + public void Append(char value) => S.Append(value); + + /// + /// Wraps objects like table names, columns, etc. + /// + public void AppendName(string userObjectName) + { + X.WrapName(S, userObjectName); + } + + public void AppendKeyword(string sqlKeyword) + { + S.Append(sqlKeyword.ToUpperInvariant()); + } + + public void AppendAsAlias(string? input) + { + X.AsAlias(S, input); + } + + public void AppendRaw(string rawExpression, IEnumerable bindings) + { + var wrapIdentifiers = X.WrapIdentifiers(rawExpression); + var objects = bindings.ToArray(); + var expandParameters = BindingExtensions. + ExpandParameters(wrapIdentifiers, "?", objects); + S.Append(expandParameters); + _bindings.AddRange(objects); + } + + public void AppendValue(string value) + { + X.WrapValue(S, value); + } + public void AppendParameter(object? value) + { + S.Append("?"); + BindOne(value); + } + + public void Whitespace() + { + if (S.Length > 0 && S[^1] != ' ') S.Append(' '); + } + + public void CommaSeparatedParameters(Query query, IEnumerable values) + { + List(", ", values, v => AppendParameter(query, v)); + } + } +} diff --git a/QueryBuilder/Compilers/X.cs b/QueryBuilder/Compilers/X.cs new file mode 100644 index 00000000..b45badf1 --- /dev/null +++ b/QueryBuilder/Compilers/X.cs @@ -0,0 +1,107 @@ +using System.Text; + +namespace SqlKata.Compilers +{ + public sealed class X + { + private readonly bool _capitalize; + private readonly string _openingIdentifier; + private readonly string _closingIdentifier; + private readonly string _columnAsKeyword; + private const string EscapeCharacter = "\\"; + + public X(string openingIdentifier, + string closingIdentifier, + string columnAsKeyword, + bool capitalize = false) + { + _capitalize = capitalize; + _openingIdentifier = openingIdentifier; + _closingIdentifier = closingIdentifier; + _columnAsKeyword = columnAsKeyword; + } + + /// Wrap a single string in a column identifier. + public string WrapName(string value) + { + var sb = new StringBuilder(); + WrapName(sb, value); + return sb.ToString(); + } + public void WrapName(StringBuilder sb, string value) + { + var segments = value.Split(" as "); + if (segments.Length > 1) + { + WrapName(sb, segments[0]); + sb.Append(" "); + sb.Append(_columnAsKeyword); + WrapValue(sb, segments[1]); + } + + else if (value.Contains(".")) + { + sb.RenderList(".", value.Split('.'), n => WrapValue(sb, n)); + } + else + { + // If we reach here then the value does not contain an "AS" alias + // nor dot "." expression, so wrap it as regular value. + WrapValue(sb, value); + } + } + + public (string, string?) SplitAlias(string value) + { + var index = value.LastIndexOf(" as ", StringComparison.OrdinalIgnoreCase); + + if (index > 0) + { + var before = value[..index]; + var after = value[(index + 4)..]; + return (before, $" {_columnAsKeyword}{after}"); + } + + return (value, null); + } + + /// + /// Wrap a single string in keyword identifiers. + /// + public string WrapValue(string value) + { + var result = value.Brace(_openingIdentifier, _closingIdentifier); + return _capitalize ? result.ToUpperInvariant() : result; + } + public void WrapValue(StringBuilder sb, string value) + { + if (value == "*") + { + sb.Append("*"); + return; + } + var val = _capitalize ? value.ToUpperInvariant() : value; + sb.Append(_openingIdentifier); + sb.Append(val.Replace(_closingIdentifier, _closingIdentifier + _closingIdentifier)); + sb.Append(_closingIdentifier); + } + + public string WrapIdentifiers(string input) + { + return input + + // deprecated + .ReplaceIdentifierUnlessEscaped(EscapeCharacter, "{", _openingIdentifier) + .ReplaceIdentifierUnlessEscaped(EscapeCharacter, "}", _closingIdentifier) + .ReplaceIdentifierUnlessEscaped(EscapeCharacter, "[", _openingIdentifier) + .ReplaceIdentifierUnlessEscaped(EscapeCharacter, "]", _closingIdentifier); + } + + public void AsAlias(StringBuilder sb, string? input) + { + if (string.IsNullOrWhiteSpace(input)) return; + sb.Append(_columnAsKeyword); + WrapValue(sb, input); + } + } +} diff --git a/QueryBuilder/DynamicExtensions.cs b/QueryBuilder/DynamicExtensions.cs new file mode 100644 index 00000000..d1ee425c --- /dev/null +++ b/QueryBuilder/DynamicExtensions.cs @@ -0,0 +1,47 @@ +using System.Collections.Concurrent; +using System.Reflection; + +namespace SqlKata +{ + public sealed class DynamicData + { + public required Dictionary Properties { get; init; } + public required Dictionary Keys { get; init; } + } + public static class DynamicExtensions + { + private static readonly ConcurrentDictionary CacheDictionaryProperties = new(); + + /// + /// Gather a list of key-values representing the properties of the object and their values. + /// + /// The plain C# object + /// + public static DynamicData ToDynamicData(this object data) + { + var properties = new Dictionary(); + var keys = new Dictionary(); + var props = CacheDictionaryProperties.GetOrAdd(data.GetType(), + type => type.GetRuntimeProperties().ToArray()); + + foreach (var property in props) + { + if (property.GetCustomAttribute(typeof(IgnoreAttribute)) != null) continue; + + var value = property.GetValue(data); + + var colAttr = property.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute; + + var name = colAttr?.Name ?? property.Name; + + properties.Add(name, value); + + if (colAttr is KeyAttribute) + keys.Add(name, value); + } + + return new DynamicData { Properties = properties, Keys = keys }; + } + + } +} diff --git a/QueryBuilder/Expressions.cs b/QueryBuilder/Expressions.cs index 8a5fdae1..184d695a 100644 --- a/QueryBuilder/Expressions.cs +++ b/QueryBuilder/Expressions.cs @@ -3,8 +3,8 @@ namespace SqlKata public static class Expressions { /// - /// Instruct the compiler to resolve the value from the predefined variables - /// In the current query or parents queries. + /// Instruct the compiler to resolve the value from the predefined variables + /// In the current query or parents queries. /// /// /// @@ -14,11 +14,11 @@ public static Variable Variable(string name) } /// - /// Instruct the compiler to treat this as a literal. - /// WARNING: don't pass user data directly to this method. + /// Instruct the compiler to treat this as a literal. + /// WARNING: don't pass user data directly to this method. /// /// - /// if true it will esacpe single quotes + /// if true it will escape single quotes /// public static UnsafeLiteral UnsafeLiteral(string value, bool replaceQuotes = true) { diff --git a/QueryBuilder/Extensions/QueryForExtensions.cs b/QueryBuilder/Extensions/QueryForExtensions.cs index a785a5f0..04395738 100644 --- a/QueryBuilder/Extensions/QueryForExtensions.cs +++ b/QueryBuilder/Extensions/QueryForExtensions.cs @@ -1,4 +1,3 @@ -using System; using SqlKata.Compilers; namespace SqlKata.Extensions @@ -34,6 +33,5 @@ public static Query ForSqlServer(this Query src, Func fn) { return src.For(EngineCodes.SqlServer, fn); } - } } diff --git a/QueryBuilder/Helper.cs b/QueryBuilder/Helper.cs index 218a95e3..a12f2735 100644 --- a/QueryBuilder/Helper.cs +++ b/QueryBuilder/Helper.cs @@ -1,151 +1,50 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Diagnostics; using System.Text.RegularExpressions; namespace SqlKata { - public static class Helper + public static class D { - public static bool IsArray(object value) - { - if (value is string) - { - return false; - } - - if (value is byte[]) - { - return false; - } - - return value is IEnumerable; - } - - /// - /// Flat IEnumerable one level down - /// - /// - /// - public static IEnumerable Flatten(IEnumerable array) - { - foreach (var item in array) - { - if (IsArray(item)) - { - foreach (var sub in (item as IEnumerable)) - { - yield return sub; - } - } - else - { - yield return item; - } - - } - } - - public static IEnumerable FlattenDeep(IEnumerable array) - { - return array.SelectMany(o => IsArray(o) ? FlattenDeep(o as IEnumerable) : new[] { o }); - } - - public static IEnumerable AllIndexesOf(string str, string value) - { - if (string.IsNullOrEmpty(value)) - { - yield break; - } - - var index = 0; - - do - { - index = str.IndexOf(value, index, StringComparison.Ordinal); - - if (index == -1) - { - yield break; - } - - yield return index; - - } while ((index += value.Length) < str.Length); - } - - public static string ReplaceAll(string subject, string match, Func callback) + private sealed class AssertionException : Exception { - if (string.IsNullOrWhiteSpace(subject) || !subject.Contains(match)) - { - return subject; - } - - var splitted = subject.Split( - new[] { match }, - StringSplitOptions.None - ); - - return splitted.Skip(1) - .Select((item, index) => callback(index) + item) - .Aggregate(new StringBuilder(splitted.First()), (prev, right) => prev.Append(right)) - .ToString(); + internal AssertionException(string msg) : base(msg) { } } - public static string JoinArray(string glue, IEnumerable array) + private static void DoAssert(bool b, string str) { - var result = new List(); - - foreach (var item in array) - { - result.Add(item.ToString()); - } - - return string.Join(glue, result); + if (!b) throw new AssertionException(str); } - public static string ExpandParameters(string sql, string placeholder, object[] bindings) + [Conditional("DEBUG")] + public static void IsTrue(bool b) { - return ReplaceAll(sql, placeholder, i => - { - var parameter = bindings[i]; - - if (IsArray(parameter)) - { - var count = EnumerableCount(parameter as IEnumerable); - return string.Join(",", placeholder.Repeat(count)); - } - - return placeholder.ToString(); - }); + DoAssert(b, "Expression must be true but it is not."); } - public static int EnumerableCount(IEnumerable obj) + [Conditional("DEBUG")] + public static void IsFalse(bool b, string? message = null) { - int count = 0; - - foreach (var item in obj) - { - count++; - } - - return count; + DoAssert(!b, message ?? "Expression must be false but it is true."); } + + } + public static class Helper + { + /// + /// Converts "Users.{Id,Name, Last_Name }" + /// into ["Users.Id", "Users.Name", "Users.Last_Name"] + /// public static List ExpandExpression(string expression) { var regex = @"^(?:\w+\.){1,2}{(.*)}"; var match = Regex.Match(expression, regex); if (!match.Success) - { // we did not found a match return the string as is. return new List { expression }; - } - var table = expression.Substring(0, expression.IndexOf(".{")); + var table = expression.Substring(0, expression.IndexOf(".{", StringComparison.Ordinal)); var captures = match.Groups[1].Value; @@ -161,7 +60,8 @@ public static IEnumerable Repeat(this string str, int count) return Enumerable.Repeat(str, count); } - public static string ReplaceIdentifierUnlessEscaped(this string input, string escapeCharacter, string identifier, string newIdentifier) + public static string ReplaceIdentifierUnlessEscaped(this string input, string escapeCharacter, + string identifier, string newIdentifier) { //Replace standard, non-escaped identifiers first var nonEscapedRegex = new Regex($@"(? - /// This class is used as metadata to ignore a property on insert and update queries + /// This class is used as metadata to ignore a property on insert and update queries /// /// - /// + /// /// public class Person /// { /// public string Name {get ;set;} - /// + /// /// [Ignore] /// public string PhoneNumber {get ;set;} - /// + /// /// } - /// + /// /// new Query("Table").Insert(new Person { Name = "User", PhoneNumber = "70123456" }) - /// + /// /// output: INSERT INTO [Table] ([Name]) VALUES('User') /// /// diff --git a/QueryBuilder/Include.cs b/QueryBuilder/Include.cs deleted file mode 100644 index e0cbfe02..00000000 --- a/QueryBuilder/Include.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SqlKata -{ - public class Include - { - public string Name { get; set; } - public Query Query { get; set; } - public string ForeignKey { get; set; } - public string LocalKey { get; set; } - public bool IsMany { get; set; } - } -} diff --git a/QueryBuilder/Join.cs b/QueryBuilder/Join.cs deleted file mode 100644 index ae0969a6..00000000 --- a/QueryBuilder/Join.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; - -namespace SqlKata -{ - public class Join : BaseQuery - { - protected string _type = "inner join"; - - public string Type - { - get - { - return _type; - } - set - { - _type = value.ToUpperInvariant(); - } - } - - public Join() : base() - { - } - - public override Join Clone() - { - var clone = base.Clone(); - clone._type = _type; - return clone; - } - - public Join AsType(string type) - { - Type = type; - return this; - } - - /// - /// Alias for "from" operator. - /// Since "from" does not sound well with join clauses - /// - /// - /// - public Join JoinWith(string table) => From(table); - public Join JoinWith(Query query) => From(query); - public Join JoinWith(Func callback) => From(callback); - - public Join AsInner() => AsType("inner join"); - public Join AsOuter() => AsType("outer join"); - public Join AsLeft() => AsType("left join"); - public Join AsRight() => AsType("right join"); - public Join AsCross() => AsType("cross join"); - - public Join On(string first, string second, string op = "=") - { - return AddComponent("where", new TwoColumnsCondition - { - First = first, - Second = second, - Operator = op, - IsOr = GetOr(), - IsNot = GetNot() - }); - - } - - public Join OrOn(string first, string second, string op = "=") - { - return Or().On(first, second, op); - } - - public override Join NewQuery() - { - return new Join(); - } - } -} diff --git a/QueryBuilder/Query.Insert.cs b/QueryBuilder/Query.Insert.cs deleted file mode 100644 index dbec60af..00000000 --- a/QueryBuilder/Query.Insert.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SqlKata -{ - public partial class Query - { - public Query AsInsert(object data, bool returnId = false) - { - var propertiesKeyValues = BuildKeyValuePairsFromObject(data); - - return AsInsert(propertiesKeyValues, returnId); - } - - public Query AsInsert(IEnumerable columns, IEnumerable values) - { - var columnsList = columns?.ToList(); - var valuesList = values?.ToList(); - - if ((columnsList?.Count ?? 0) == 0 || (valuesList?.Count ?? 0) == 0) - { - throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty"); - } - - if (columnsList.Count != valuesList.Count) - { - throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty"); - } - - Method = "insert"; - - ClearComponent("insert").AddComponent("insert", new InsertClause - { - Columns = columnsList, - Values = valuesList - }); - - return this; - } - - public Query AsInsert(IEnumerable> values, bool returnId = false) - { - if (values == null || values.Any() == false) - { - throw new InvalidOperationException($"{values} argument cannot be null or empty"); - } - - Method = "insert"; - - ClearComponent("insert").AddComponent("insert", new InsertClause - { - Columns = values.Select(x => x.Key).ToList(), - Values = values.Select(x => x.Value).ToList(), - ReturnId = returnId, - }); - - return this; - } - - /// - /// Produces insert multi records - /// - /// - /// - /// - public Query AsInsert(IEnumerable columns, IEnumerable> rowsValues) - { - var columnsList = columns?.ToList(); - var valuesCollectionList = rowsValues?.ToList(); - - if ((columnsList?.Count ?? 0) == 0 || (valuesCollectionList?.Count ?? 0) == 0) - { - throw new InvalidOperationException($"{nameof(columns)} and {nameof(rowsValues)} cannot be null or empty"); - } - - Method = "insert"; - - ClearComponent("insert"); - - foreach (var values in valuesCollectionList) - { - var valuesList = values.ToList(); - if (columnsList.Count != valuesList.Count) - { - throw new InvalidOperationException($"{nameof(columns)} count should be equal to each {nameof(rowsValues)} entry count"); - } - - AddComponent("insert", new InsertClause - { - Columns = columnsList, - Values = valuesList - }); - } - - return this; - } - - /// - /// Produces insert from subquery - /// - /// - /// - /// - public Query AsInsert(IEnumerable columns, Query query) - { - Method = "insert"; - - ClearComponent("insert").AddComponent("insert", new InsertQueryClause - { - Columns = columns.ToList(), - Query = query.Clone(), - }); - - return this; - } - } -} diff --git a/QueryBuilder/Query.Update.cs b/QueryBuilder/Query.Update.cs deleted file mode 100644 index d88aeb00..00000000 --- a/QueryBuilder/Query.Update.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SqlKata -{ - public partial class Query - { - public Query AsUpdate(object data) - { - var dictionary = BuildKeyValuePairsFromObject(data, considerKeys: true); - - return AsUpdate(dictionary); - } - - public Query AsUpdate(IEnumerable columns, IEnumerable values) - { - if ((columns?.Any() ?? false) == false || (values?.Any() ?? false) == false) - { - throw new InvalidOperationException($"{columns} and {values} cannot be null or empty"); - } - - if (columns.Count() != values.Count()) - { - throw new InvalidOperationException($"{columns} count should be equal to {values} count"); - } - - Method = "update"; - - ClearComponent("update").AddComponent("update", new InsertClause - { - Columns = columns.ToList(), - Values = values.ToList() - }); - - return this; - } - - public Query AsUpdate(IEnumerable> values) - { - if (values == null || values.Any() == false) - { - throw new InvalidOperationException($"{values} cannot be null or empty"); - } - - Method = "update"; - - ClearComponent("update").AddComponent("update", new InsertClause - { - Columns = values.Select(x => x.Key).ToList(), - Values = values.Select(x => x.Value).ToList(), - }); - - return this; - } - - public Query AsIncrement(string column, int value = 1) - { - Method = "update"; - AddOrReplaceComponent("update", new IncrementClause - { - Column = column, - Value = value - }); - - return this; - } - - public Query AsDecrement(string column, int value = 1) - { - return AsIncrement(column, -value); - } - } -} diff --git a/QueryBuilder/Query.cs b/QueryBuilder/Query.cs deleted file mode 100755 index 8435eca6..00000000 --- a/QueryBuilder/Query.cs +++ /dev/null @@ -1,437 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace SqlKata -{ - public partial class Query : BaseQuery - { - private string comment; - - public bool IsDistinct { get; set; } = false; - public string QueryAlias { get; set; } - public string Method { get; set; } = "select"; - public List Includes = new List(); - public Dictionary Variables = new Dictionary(); - - public Query() : base() - { - } - - public Query(string table, string comment = null) : base() - { - From(table); - Comment(comment); - } - - public string GetComment() => comment ?? ""; - - public bool HasOffset(string engineCode = null) => GetOffset(engineCode) > 0; - - public bool HasLimit(string engineCode = null) => GetLimit(engineCode) > 0; - - internal long GetOffset(string engineCode = null) - { - engineCode = engineCode ?? EngineScope; - var offset = this.GetOneComponent("offset", engineCode); - - return offset?.Offset ?? 0; - } - - internal int GetLimit(string engineCode = null) - { - engineCode = engineCode ?? EngineScope; - var limit = this.GetOneComponent("limit", engineCode); - - return limit?.Limit ?? 0; - } - - public override Query Clone() - { - var clone = base.Clone(); - clone.Parent = Parent; - clone.QueryAlias = QueryAlias; - clone.IsDistinct = IsDistinct; - clone.Method = Method; - clone.Includes = Includes; - clone.Variables = Variables; - return clone; - } - - public Query As(string alias) - { - QueryAlias = alias; - return this; - } - - /// - /// Sets a comment for the query. - /// - /// The comment. - /// - public Query Comment(string comment) - { - this.comment = comment; - return this; - } - - public Query For(string engine, Func fn) - { - EngineScope = engine; - - var result = fn.Invoke(this); - - // reset the engine - EngineScope = null; - - return result; - } - - public Query With(Query query) - { - // Clear query alias and add it to the containing clause - if (string.IsNullOrWhiteSpace(query.QueryAlias)) - { - throw new InvalidOperationException("No Alias found for the CTE query"); - } - - query = query.Clone(); - - var alias = query.QueryAlias.Trim(); - - // clear the query alias - query.QueryAlias = null; - - return AddComponent("cte", new QueryFromClause - { - Query = query, - Alias = alias, - }); - } - - public Query With(Func fn) - { - return With(fn.Invoke(new Query())); - } - - public Query With(string alias, Query query) - { - return With(query.As(alias)); - } - - public Query With(string alias, Func fn) - { - return With(alias, fn.Invoke(new Query())); - } - - /// - /// Constructs an ad-hoc table of the given data as a CTE. - /// - public Query With(string alias, IEnumerable columns, IEnumerable> valuesCollection) - { - var columnsList = columns?.ToList(); - var valuesCollectionList = valuesCollection?.ToList(); - - if ((columnsList?.Count ?? 0) == 0 || (valuesCollectionList?.Count ?? 0) == 0) - { - throw new InvalidOperationException("Columns and valuesCollection cannot be null or empty"); - } - - var clause = new AdHocTableFromClause() - { - Alias = alias, - Columns = columnsList, - Values = new List(), - }; - - foreach (var values in valuesCollectionList) - { - var valuesList = values.ToList(); - if (columnsList.Count != valuesList.Count) - { - throw new InvalidOperationException("Columns count should be equal to each Values count"); - } - - clause.Values.AddRange(valuesList); - } - - return AddComponent("cte", clause); - } - - public Query WithRaw(string alias, string sql, params object[] bindings) - { - return AddComponent("cte", new RawFromClause - { - Alias = alias, - Expression = sql, - Bindings = bindings, - }); - } - - public Query Limit(int value) - { - var newClause = new LimitClause - { - Limit = value - }; - - return AddOrReplaceComponent("limit", newClause); - } - - public Query Offset(long value) - { - var newClause = new OffsetClause - { - Offset = value - }; - - return AddOrReplaceComponent("offset", newClause); - } - - public Query Offset(int value) - { - return Offset((long)value); - } - - /// - /// Alias for Limit - /// - /// - /// - public Query Take(int limit) - { - return Limit(limit); - } - - /// - /// Alias for Offset - /// - /// - /// - public Query Skip(int offset) - { - return Offset(offset); - } - - /// - /// Set the limit and offset for a given page. - /// - /// - /// - /// - public Query ForPage(int page, int perPage = 15) - { - return Skip((page - 1) * perPage).Take(perPage); - } - - public Query Distinct() - { - IsDistinct = true; - return this; - } - - /// - /// Apply the callback's query changes if the given "condition" is true. - /// - /// - /// Invoked when the condition is true - /// Optional, invoked when the condition is false - /// - public Query When(bool condition, Func whenTrue, Func whenFalse = null) - { - if (condition && whenTrue != null) - { - return whenTrue.Invoke(this); - } - - if (!condition && whenFalse != null) - { - return whenFalse.Invoke(this); - } - - return this; - } - - /// - /// Apply the callback's query changes if the given "condition" is false. - /// - /// - /// - /// - public Query WhenNot(bool condition, Func callback) - { - if (!condition) - { - return callback.Invoke(this); - } - - return this; - } - - public Query OrderBy(params string[] columns) - { - foreach (var column in columns) - { - AddComponent("order", new OrderBy - { - Column = column, - Ascending = true - }); - } - - return this; - } - - public Query OrderByDesc(params string[] columns) - { - foreach (var column in columns) - { - AddComponent("order", new OrderBy - { - Column = column, - Ascending = false - }); - } - - return this; - } - - public Query OrderByRaw(string expression, params object[] bindings) - { - return AddComponent("order", new RawOrderBy - { - Expression = expression, - Bindings = Helper.Flatten(bindings).ToArray() - }); - } - - public Query OrderByRandom(string seed) - { - return AddComponent("order", new OrderByRandom { }); - } - - public Query GroupBy(params string[] columns) - { - foreach (var column in columns) - { - AddComponent("group", new Column - { - Name = column - }); - } - - return this; - } - - public Query GroupByRaw(string expression, params object[] bindings) - { - AddComponent("group", new RawColumn - { - Expression = expression, - Bindings = bindings, - }); - - return this; - } - - public override Query NewQuery() - { - return new Query(); - } - - public Query Include(string relationName, Query query, string foreignKey = null, string localKey = "Id", bool isMany = false) - { - - Includes.Add(new Include - { - Name = relationName, - LocalKey = localKey, - ForeignKey = foreignKey, - Query = query, - IsMany = isMany, - }); - - return this; - } - - public Query IncludeMany(string relationName, Query query, string foreignKey = null, string localKey = "Id") - { - return Include(relationName, query, foreignKey, localKey, isMany: true); - } - - private static readonly ConcurrentDictionary CacheDictionaryProperties = new ConcurrentDictionary(); - - /// - /// Define a variable to be used within the query - /// - /// - /// - /// - public Query Define(string variable, object value) - { - Variables.Add(variable, value); - - return this; - } - - public object FindVariable(string variable) - { - var found = Variables.ContainsKey(variable); - - if (found) - { - return Variables[variable]; - } - - if (Parent != null) - { - return (Parent as Query).FindVariable(variable); - } - - throw new Exception($"Variable '{variable}' not found"); - } - - /// - /// Gather a list of key-values representing the properties of the object and their values. - /// - /// The plain C# object - /// - /// When true it will search for properties with the [Key] attribute - /// and will add it automatically to the Where clause - /// - /// - private IEnumerable> BuildKeyValuePairsFromObject(object data, bool considerKeys = false) - { - var dictionary = new Dictionary(); - var props = CacheDictionaryProperties.GetOrAdd(data.GetType(), type => type.GetRuntimeProperties().ToArray()); - - foreach (var property in props) - { - if (property.GetCustomAttribute(typeof(IgnoreAttribute)) != null) - { - continue; - } - - var value = property.GetValue(data); - - var colAttr = property.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute; - - var name = colAttr?.Name ?? property.Name; - - dictionary.Add(name, value); - - if (considerKeys && colAttr != null) - { - if ((colAttr as KeyAttribute) != null) - { - this.Where(name, value); - } - } - } - - return dictionary; - } - } -} diff --git a/QueryBuilder/Query/Base.Query.cs b/QueryBuilder/Query/Base.Query.cs new file mode 100644 index 00000000..eebe3d0a --- /dev/null +++ b/QueryBuilder/Query/Base.Query.cs @@ -0,0 +1,243 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public partial class Query + { + public string? EngineScope; + public Query? Parent; + private bool _notFlag; + + private bool _orFlag; + + public ComponentList Components = new(); + private string? _comment; + public List Includes = new(); + public Dictionary Variables = new(); + public bool IsDistinct { get; set; } + // Mandatory for CTE queries + public string? QueryAlias { get; set; } + public string Method { get; set; } = "select"; + + public Query SetEngineScope(string? engine) + { + EngineScope = engine; + + return this; + } + + public Query SetParent(Query? parent) + { + if (this == parent) + throw new ArgumentException($"Cannot set the same {nameof(Query)} as a parent of itself"); + + Parent = parent; + return this; + } + + public Query NewChild() + { + var newQuery = new Query().SetParent(this); + newQuery.EngineScope = EngineScope; + return newQuery; + } + + /// + /// Add a component clause to the query. + /// + public Query AddComponent(AbstractClause clause) + { + Components.AddComponent(clause); + return this; + } + + /// + /// If the query already contains a clause for the given component + /// and engine, replace it with the specified clause. Otherwise, just + /// add the clause. + /// + /// + /// + public Query AddOrReplaceComponent(AbstractClause clause) + { + Components.AddOrReplaceComponent(clause); + return this; + } + + /// + /// Get the list of clauses for a component. + /// + /// + public List GetComponents(string component, string? engineCode = null) where TC : AbstractClause + { + return Components.GetComponents(component, engineCode ?? EngineScope); + } + + /// + /// Get the list of clauses for a component. + /// + /// + /// + /// + public List GetComponents(string component, string? engineCode = null) + { + return Components.GetComponents(component, engineCode ?? EngineScope); + } + + /// + /// Get a single component clause from the query. + /// + /// + public TC? GetOneComponent(string component, string? engineCode = null) where TC : AbstractClause + { + return Components.GetOneComponent(component, engineCode ?? EngineScope); + } + + /// + /// Get a single component clause from the query. + /// + /// + /// + /// + public AbstractClause? GetOneComponent(string component, string? engineCode = null) + { + return Components.GetOneComponent(component, engineCode ?? EngineScope); + } + + /// + /// Return whether the query has clauses for a component. + /// + /// + /// + /// + public bool HasComponent(string component, string? engineCode = null) + { + return Components.HasComponent(component, engineCode ?? EngineScope); + } + + //public T? TryGetOneComponent(string component, string? engineCode = null) + //{ + // engineCode ??= EngineScope; + // + // var all = GetComponents(component, engineCode); + // return all.FirstOrDefault(c => c.Engine == engineCode) ?? + // all.FirstOrDefault(c => c.Engine == null); + //} + /// + /// Remove all clauses for a component. + /// + /// + /// + /// + public Query RemoveComponent(string component, string? engineCode = null) + { + Components.RemoveComponent(component, engineCode ?? EngineScope); + return this; + } + /// + /// Set the next boolean operator to "and" for the "where" clause. + /// + /// + public Query And() + { + _orFlag = false; + return this; + } + + /// + /// Set the next boolean operator to "or" for the "where" clause. + /// + /// + public Query Or() + { + _orFlag = true; + return this; + } + + /// + /// Set the next "not" operator for the "where" clause. + /// + /// + public Query Not(bool flag = true) + { + _notFlag = flag; + return this; + } + + /// + /// Get the boolean operator and reset it to "and" + /// + /// + public bool GetOr() + { + var ret = _orFlag; + + // reset the flag + _orFlag = false; + return ret; + } + + /// + /// Get the "not" operator and clear it + /// + /// + public bool GetNot() + { + var ret = _notFlag; + + // reset the flag + _notFlag = false; + return ret; + } + + public Query From(string table) + { + return AddOrReplaceComponent(new FromClause + { + Engine = EngineScope, + Component = "from", + Table = table, + Alias = table.Split(" as ").Last(), + }); + } + + public Query From(Query query, string? alias = null) + { + query = query.Clone(); + query.SetParent(this); + + if (alias != null) query.As(alias); + + return AddOrReplaceComponent(new QueryFromClause + { + Engine = EngineScope, + Component = "from", + Query = query, + Alias = alias ?? query.QueryAlias + }); + } + + public Query FromRaw(string sql, params object[] bindings) + { + ArgumentNullException.ThrowIfNull(sql); + ArgumentNullException.ThrowIfNull(bindings); + return AddOrReplaceComponent(new RawFromClause + { + Engine = EngineScope, + Component = "from", + Expression = sql, + Bindings = bindings.ToImmutableArray(), + Alias = null + }); + } + + public Query From(Func callback, string? alias = null) + { + var query = new Query(); + + query.SetParent(this); + + return From(callback.Invoke(query), alias); + } + } +} diff --git a/QueryBuilder/Query/Base.Where.cs b/QueryBuilder/Query/Base.Where.cs new file mode 100644 index 00000000..3b55a23b --- /dev/null +++ b/QueryBuilder/Query/Base.Where.cs @@ -0,0 +1,754 @@ +using System.Collections.Immutable; +using System.Reflection; + +namespace SqlKata +{ + public partial class Query + { + public Query Where(string column, string op, object? value) + { + // If the value is "null", we will just assume the developer wants to add a + // where null clause to the query. So, we will allow a short-cut here to + // that method for convenience so the developer doesn't have to check. + if (value == null) return Not(op != "=").WhereNull(column); + + if (value is bool boolValue) + { + if (op != "=") Not(); + + return boolValue ? WhereTrue(column) : WhereFalse(column); + } + + return AddComponent(new BasicCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + Operator = op, + Value = value, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNot(string column, string op, object? value) + { + return Not().Where(column, op, value); + } + + public Query OrWhere(string column, string op, object? value) + { + return Or().Where(column, op, value); + } + + public Query OrWhereNot(string column, string op, object? value) + { + return Or().Not().Where(column, op, value); + } + + public Query Where(string column, object? value) + { + return Where(column, "=", value); + } + + public Query WhereNot(string column, object? value) + { + return WhereNot(column, "=", value); + } + + public Query OrWhere(string column, object? value) + { + return OrWhere(column, "=", value); + } + + public Query OrWhereNot(string column, object? value) + { + return OrWhereNot(column, "=", value); + } + + /// + /// Perform a where constraint + /// + /// + /// + public Query Where(object constraints) + { + var dictionary = new Dictionary(); + + foreach (var item in constraints.GetType().GetRuntimeProperties()) + dictionary.Add(item.Name, item.GetValue(constraints)); + + return Where(dictionary); + } + + public Query Where(IEnumerable> values) + { + var query = this; + var orFlag = GetOr(); + var notFlag = GetNot(); + + foreach (var tuple in values) + { + if (orFlag) + query.Or(); + else + query.And(); + + query = Not(notFlag).Where(tuple.Key, tuple.Value); + } + + return query; + } + + public Query WhereRaw(string sql, params object[] bindings) + { + return AddComponent(new RawCondition + { + Engine = EngineScope, + Component = "where", + Expression = sql, + Bindings = bindings, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query OrWhereRaw(string sql, params object[] bindings) + { + return Or().WhereRaw(sql, bindings); + } + + /// + /// Apply a nested where clause + /// + /// + /// + public Query Where(Func callback) + { + var query = callback.Invoke(NewChild()); + + // omit empty queries + if (!query.Components.Any("where")) return this; + + return AddComponent(new NestedCondition + { + Engine = EngineScope, + Component = "where", + Query = query, + IsNot = GetNot(), + IsOr = GetOr() + }); + } + + public Query WhereNot(Func callback) + { + return Not().Where(callback); + } + + public Query OrWhere(Func callback) + { + return Or().Where(callback); + } + + public Query OrWhereNot(Func callback) + { + return Not().Or().Where(callback); + } + + public Query WhereColumns(string first, string op, string second) + { + return AddComponent(new TwoColumnsCondition + { + Engine = EngineScope, + Component = "where", + First = first, + Second = second, + Operator = op, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query OrWhereColumns(string first, string op, string second) + { + return Or().WhereColumns(first, op, second); + } + + public Query WhereNull(string column) + { + return AddComponent(new NullCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotNull(string column) + { + return Not().WhereNull(column); + } + + public Query OrWhereNull(string column) + { + return Or().WhereNull(column); + } + + public Query OrWhereNotNull(string column) + { + return Or().Not().WhereNull(column); + } + + public Query WhereTrue(string column) + { + return AddComponent(new BooleanCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + Value = true, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query OrWhereTrue(string column) + { + return Or().WhereTrue(column); + } + + public Query WhereFalse(string column) + { + return AddComponent(new BooleanCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + Value = false, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query OrWhereFalse(string column) + { + return Or().WhereFalse(column); + } + + public Query WhereLike(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return AddComponent(new BasicStringCondition + { + Engine = EngineScope, + Component = "where", + Operator = "like", + Column = column, + Value = value, + CaseSensitive = caseSensitive, + EscapeCharacter = escapeCharacter, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotLike(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Not().WhereLike(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereLike(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().WhereLike(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereNotLike(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().Not().WhereLike(column, value, caseSensitive, escapeCharacter); + } + + public Query WhereStarts(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return AddComponent(new BasicStringCondition + { + Engine = EngineScope, + Component = "where", + Operator = "starts", + Column = column, + Value = value, + CaseSensitive = caseSensitive, + EscapeCharacter = escapeCharacter, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotStarts(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Not().WhereStarts(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereStarts(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().WhereStarts(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereNotStarts(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) + { + return Or().Not().WhereStarts(column, value, caseSensitive, escapeCharacter); + } + + public Query WhereEnds(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return AddComponent(new BasicStringCondition + { + Engine = EngineScope, + Component = "where", + Operator = "ends", + Column = column, + Value = value, + CaseSensitive = caseSensitive, + EscapeCharacter = escapeCharacter, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotEnds(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Not().WhereEnds(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereEnds(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().WhereEnds(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereNotEnds(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().Not().WhereEnds(column, value, caseSensitive, escapeCharacter); + } + + public Query WhereContains(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return AddComponent(new BasicStringCondition + { + Engine = EngineScope, + Component = "where", + Operator = "contains", + Column = column, + Value = value, + CaseSensitive = caseSensitive, + EscapeCharacter = escapeCharacter, + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) + { + return Not().WhereContains(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereContains(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) + { + return Or().WhereContains(column, value, caseSensitive, escapeCharacter); + } + + public Query OrWhereNotContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) + { + return Or().Not().WhereContains(column, value, caseSensitive, escapeCharacter); + } + + public Query WhereBetween(string column, T lower, T higher) + where T: notnull + { + return AddComponent(new BetweenCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + IsOr = GetOr(), + IsNot = GetNot(), + Lower = lower, + Higher = higher + }); + } + + public Query OrWhereBetween(string column, T lower, T higher) + where T : notnull + { + return Or().WhereBetween(column, lower, higher); + } + + public Query WhereNotBetween(string column, T lower, T higher) + where T : notnull + { + return Not().WhereBetween(column, lower, higher); + } + + public Query OrWhereNotBetween(string column, T lower, T higher) + where T : notnull + { + return Or().Not().WhereBetween(column, lower, higher); + } + + public Query WhereIn(string column, params T[] values) => + WhereIn(column, (IEnumerable)values); + public Query WhereNotIn(string column, params T[] values) => + WhereNotIn(column, (IEnumerable)values); + public Query OrWhereNotIn(string column, params T[] values) => + OrWhereNotIn(column, (IEnumerable)values); + public Query WhereIn(string column, IEnumerable values) + { + // If the developer has passed a string they most likely want a List + // since string is considered as List + if (values is string val) + { + return AddComponent(new InCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + IsOr = GetOr(), + IsNot = GetNot(), + Values = ImmutableArray.Create(val) + }); + } + + return AddComponent(new InCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + IsOr = GetOr(), + IsNot = GetNot(), + Values = values.Distinct().Cast().ToImmutableArray() + }); + } + + public Query OrWhereIn(string column, IEnumerable values) + { + return Or().WhereIn(column, values); + } + + public Query WhereNotIn(string column, IEnumerable values) + { + return Not().WhereIn(column, values); + } + + public Query OrWhereNotIn(string column, IEnumerable values) + { + return Or().Not().WhereIn(column, values); + } + + + public Query WhereIn(string column, Query query) + { + return AddComponent(new InQueryCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + IsOr = GetOr(), + IsNot = GetNot(), + Query = query + }); + } + + public Query WhereIn(string column, Func callback) + { + var query = callback.Invoke(new Query().SetParent(this)); + + return WhereIn(column, query); + } + + public Query OrWhereIn(string column, Query query) + { + return Or().WhereIn(column, query); + } + + public Query OrWhereIn(string column, Func callback) + { + return Or().WhereIn(column, callback); + } + + public Query WhereNotIn(string column, Query query) + { + return Not().WhereIn(column, query); + } + + public Query WhereNotIn(string column, Func callback) + { + return Not().WhereIn(column, callback); + } + + public Query OrWhereNotIn(string column, Query query) + { + return Or().Not().WhereIn(column, query); + } + + public Query OrWhereNotIn(string column, Func callback) + { + return Or().Not().WhereIn(column, callback); + } + + + /// + /// Perform a sub query where clause + /// + /// + /// + /// + /// + public Query Where(string column, string op, Func callback) + { + var query = callback.Invoke(NewChild()); + + return Where(column, op, query); + } + + public Query Where(string column, string op, Query query) + { + return AddComponent(new QueryCondition + { + Engine = EngineScope, + Component = "where", + Column = column, + Operator = op, + Query = query, + IsNot = GetNot(), + IsOr = GetOr() + }); + } + + public Query WhereSub(Query query, object value) + { + return WhereSub(query, "=", value); + } + + public Query WhereSub(Query query, string op, object value) + { + return AddComponent(new SubQueryCondition + { + Engine = EngineScope, + Component = "where", + Value = value, + Operator = op, + Query = query, + IsNot = GetNot(), + IsOr = GetOr() + }); + } + + public Query OrWhereSub(Query query, object value) + { + return Or().WhereSub(query, value); + } + + public Query OrWhereSub(Query query, string op, object value) + { + return Or().WhereSub(query, op, value); + } + + public Query OrWhere(string column, string op, Query query) + { + return Or().Where(column, op, query); + } + + public Query OrWhere(string column, string op, Func callback) + { + return Or().Where(column, op, callback); + } + + public Query WhereExists(Query query) + { + if (!query.HasComponent("from")) + throw new ArgumentException( + $"'{nameof(FromClause)}' cannot be empty if used inside a '{nameof(WhereExists)}' condition"); + + return AddComponent(new ExistsCondition + { + Engine = EngineScope, + Component = "where", + Query = query, + IsNot = GetNot(), + IsOr = GetOr() + }); + } + + public Query WhereExists(Func callback) + { + var childQuery = new Query().SetParent(this); + return WhereExists(callback.Invoke(childQuery)); + } + + public Query WhereNotExists(Query query) + { + return Not().WhereExists(query); + } + + public Query WhereNotExists(Func callback) + { + return Not().WhereExists(callback); + } + + public Query OrWhereExists(Query query) + { + return Or().WhereExists(query); + } + + public Query OrWhereExists(Func callback) + { + return Or().WhereExists(callback); + } + + public Query OrWhereNotExists(Query query) + { + return Or().Not().WhereExists(query); + } + + public Query OrWhereNotExists(Func callback) + { + return Or().Not().WhereExists(callback); + } + + #region date + + public Query WhereDatePart(string part, string column, string op, object value) + { + return AddComponent(new BasicDateCondition + { + Engine = EngineScope, + Component = "where", + Operator = op, + Column = column, + Value = value, + Part = part.ToLowerInvariant(), + IsOr = GetOr(), + IsNot = GetNot() + }); + } + + public Query WhereNotDatePart(string part, string column, string op, object value) + { + return Not().WhereDatePart(part, column, op, value); + } + + public Query OrWhereDatePart(string part, string column, string op, object value) + { + return Or().WhereDatePart(part, column, op, value); + } + + public Query OrWhereNotDatePart(string part, string column, string op, object value) + { + return Or().Not().WhereDatePart(part, column, op, value); + } + + public Query WhereDate(string column, string op, object value) + { + return WhereDatePart("date", column, op, value); + } + + public Query WhereNotDate(string column, string op, object value) + { + return Not().WhereDate(column, op, value); + } + + public Query OrWhereDate(string column, string op, object value) + { + return Or().WhereDate(column, op, value); + } + + public Query OrWhereNotDate(string column, string op, object value) + { + return Or().Not().WhereDate(column, op, value); + } + + public Query WhereTime(string column, string op, object value) + { + return WhereDatePart("time", column, op, value); + } + + public Query WhereNotTime(string column, string op, object value) + { + return Not().WhereTime(column, op, value); + } + + public Query OrWhereTime(string column, string op, object value) + { + return Or().WhereTime(column, op, value); + } + + public Query OrWhereNotTime(string column, string op, object value) + { + return Or().Not().WhereTime(column, op, value); + } + + public Query WhereDatePart(string part, string column, object value) + { + return WhereDatePart(part, column, "=", value); + } + + public Query WhereNotDatePart(string part, string column, object value) + { + return WhereNotDatePart(part, column, "=", value); + } + + public Query OrWhereDatePart(string part, string column, object value) + { + return OrWhereDatePart(part, column, "=", value); + } + + public Query OrWhereNotDatePart(string part, string column, object value) + { + return OrWhereNotDatePart(part, column, "=", value); + } + + public Query WhereDate(string column, object value) + { + return WhereDate(column, "=", value); + } + + public Query WhereNotDate(string column, object value) + { + return WhereNotDate(column, "=", value); + } + + public Query OrWhereDate(string column, object value) + { + return OrWhereDate(column, "=", value); + } + + public Query OrWhereNotDate(string column, object value) + { + return OrWhereNotDate(column, "=", value); + } + + public Query WhereTime(string column, object value) + { + return WhereTime(column, "=", value); + } + + public Query WhereNotTime(string column, object value) + { + return WhereNotTime(column, "=", value); + } + + public Query OrWhereTime(string column, object value) + { + return OrWhereTime(column, "=", value); + } + + public Query OrWhereNotTime(string column, object value) + { + return OrWhereNotTime(column, "=", value); + } + + #endregion + } +} diff --git a/QueryBuilder/Query/Clauses/AbstractClause.cs b/QueryBuilder/Query/Clauses/AbstractClause.cs new file mode 100644 index 00000000..8cf88ff3 --- /dev/null +++ b/QueryBuilder/Query/Clauses/AbstractClause.cs @@ -0,0 +1,8 @@ +namespace SqlKata +{ + public abstract class AbstractClause + { + public required string? Engine { get; init; } + public required string Component { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/AggregateClause.cs b/QueryBuilder/Query/Clauses/AggregateClause.cs new file mode 100644 index 00000000..805cb646 --- /dev/null +++ b/QueryBuilder/Query/Clauses/AggregateClause.cs @@ -0,0 +1,27 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + /// + /// Represents aggregate clause like "COUNT", "MAX" or etc. + /// + /// + public class AggregateClause : AbstractClause + { + /// + /// Gets or sets columns that used in aggregate clause. + /// + /// + /// The columns to be aggregated. + /// + public required ImmutableArray Columns { get; init; } + + /// + /// Gets or sets the type of aggregate function. + /// + /// + /// The type of aggregate function, e.g. "MAX", "MIN", etc. + /// + public required string Type { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/ColumnClause.cs b/QueryBuilder/Query/Clauses/ColumnClause.cs new file mode 100644 index 00000000..babd0758 --- /dev/null +++ b/QueryBuilder/Query/Clauses/ColumnClause.cs @@ -0,0 +1,86 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public abstract class AbstractColumn : AbstractClause + { + } + + /// + /// Represents "column" or "column as alias" clause. + /// + /// + public sealed class Column : AbstractColumn + { + /// + /// Gets or sets the column name. Can be "columnName" or "columnName as columnAlias". + /// + /// + /// The column name. + /// + public required string Name { get; init; } + } + + /// + /// Represents column clause calculated using query. + /// + /// + public sealed class QueryColumn : AbstractColumn + { + /// + /// Gets or sets the query that will be used for column value calculation. + /// + /// + /// The query for column value calculation. + /// + public required Query Query { get; init; } + } + + public sealed class RawColumn : AbstractColumn + { + /// + /// Gets or sets the RAW expression. + /// + /// + /// The RAW expression. + /// + public required string Expression { get; init; } + + public required ImmutableArray Bindings { get; init; } + } + + /// + /// Represents an aggregated column clause with an optional filter + /// + /// + public sealed class AggregatedColumn : AbstractColumn + { + /// + /// Gets or sets the a query that used to filter the data, + /// the compiler will consider only the `Where` clause. + /// + /// + /// The filter query. + /// + public required Query? Filter { get; init; } + + public required string Aggregate { get; init; } + public required Column Column { get; init; } + + + } + + public static class ClauseExtensions + { + public static List GetFilterConditions(this AggregatedColumn column) + { + return column.Filter == null + ? Empty.List + : column.Filter.GetComponents("where"); + } + } + public static class Empty + { + public static readonly List List = new(); + } +} diff --git a/QueryBuilder/Query/Clauses/Combine.cs b/QueryBuilder/Query/Clauses/Combine.cs new file mode 100644 index 00000000..26325029 --- /dev/null +++ b/QueryBuilder/Query/Clauses/Combine.cs @@ -0,0 +1,42 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public abstract class AbstractCombine : AbstractClause + { + } + + public sealed class Combine : AbstractCombine + { + /// + /// Gets or sets the query to be combined with. + /// + /// + /// The query that will be combined. + /// + public required Query Query { get; init; } + + /// + /// Gets or sets the combine operation, e.g. "UNION", etc. + /// + /// + /// The combine operation. + /// + public required string Operation { get; init; } + + /// + /// Gets or sets a value indicating whether this clause will combine all. + /// + /// + /// true if all; otherwise, false. + /// + public required bool All { get; init; } + } + + public class RawCombine : AbstractCombine + { + public required string Expression { get; init; } + + public required ImmutableArray Bindings { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/ConditionClause.cs b/QueryBuilder/Query/Clauses/ConditionClause.cs new file mode 100644 index 00000000..4ef093cd --- /dev/null +++ b/QueryBuilder/Query/Clauses/ConditionClause.cs @@ -0,0 +1,129 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public abstract class AbstractCondition : AbstractClause + { + public required bool IsOr { get; init; } + public required bool IsNot { get; init; } + } + + /// + /// Represents a comparison between a column and a value. + /// + public class BasicCondition : AbstractCondition + { + public required string Column { get; init; } + public required string Operator { get; init; } + public required object Value { get; init; } + } + + public class BasicStringCondition : BasicCondition + { + public required bool CaseSensitive { get; init; } + public required char? EscapeCharacter { get; init; } + } + + public sealed class BasicDateCondition : BasicCondition + { + public required string Part { get; init; } + } + + /// + /// Represents a comparison between two columns. + /// + public sealed class TwoColumnsCondition : AbstractCondition + { + public required string First { get; init; } + public required string Operator { get; init; } + public required string Second { get; init; } + } + + /// + /// Represents a comparison between a column and a full "subQuery". + /// + public sealed class QueryCondition : AbstractCondition + { + public required string Column { get; init; } + public required string Operator { get; init; } + public required Query Query { get; init; } + } + + /// + /// Represents a comparison between a full "subQuery" and a value. + /// + public class SubQueryCondition : AbstractCondition + { + public required object Value { get; init; } + public required string Operator { get; init; } + public required Query Query { get; init; } + } + + /// + /// Represents a "is in" condition. + /// + public class InCondition : AbstractCondition + { + public required string Column { get; init; } + public required ImmutableArray Values { get; init; } + } + + /// + /// Represents a "is in subQuery" condition. + /// + public class InQueryCondition : AbstractCondition + { + public required Query Query { get; init; } + public required string Column { get; init; } + } + + /// + /// Represents a "is between" condition. + /// + public class BetweenCondition : AbstractCondition + { + public required string Column { get; init; } + public required object Higher { get; init; } + public required object Lower { get; init; } + } + + /// + /// Represents an "is null" condition. + /// + public class NullCondition : AbstractCondition + { + public required string Column { get; init; } + } + + /// + /// Represents a boolean (true/false) condition. + /// + public class BooleanCondition : AbstractCondition + { + public required string Column { get; init; } + public required bool Value { get; init; } + } + + /// + /// Represents a "nested" clause condition. + /// i.e OR (myColumn = "A") + /// + public class NestedCondition : AbstractCondition + { + public required Query Query { get; init; } + } + + /// + /// Represents an "exists sub query" clause condition. + /// + public class ExistsCondition : AbstractCondition + { + public required Query Query { get; init; } + } + + public class RawCondition : AbstractCondition + { + public required string Expression { get; init; } + public required object[] Bindings { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/FromClause.cs b/QueryBuilder/Query/Clauses/FromClause.cs new file mode 100644 index 00000000..e57a3bbf --- /dev/null +++ b/QueryBuilder/Query/Clauses/FromClause.cs @@ -0,0 +1,43 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public abstract class AbstractFrom : AbstractClause + { + } + + /// + /// Represents a "from" clause. + /// + public sealed class FromClause : AbstractFrom + { + public required string Table { get; init; } + public required string Alias { get; init; } + } + + /// + /// Represents a "from subQuery" clause. + /// + public sealed class QueryFromClause : AbstractFrom + { + public required string? Alias { get; init; } + public required Query Query { get; init; } + } + + public sealed class RawFromClause : AbstractFrom + { + public required string? Alias { get; init; } + public required string Expression { get; init; } + public required ImmutableArray Bindings { get; init; } + } + + /// + /// Represents a FROM clause that is an ad-hoc table built with predefined values. + /// + public sealed class AdHocTableFromClause : AbstractFrom + { + public required string Alias { get; init; } + public required ImmutableArray Columns { get; init; } + public required ImmutableArray Values { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/IncrementClause.cs b/QueryBuilder/Query/Clauses/IncrementClause.cs new file mode 100644 index 00000000..8f4d9217 --- /dev/null +++ b/QueryBuilder/Query/Clauses/IncrementClause.cs @@ -0,0 +1,8 @@ +namespace SqlKata +{ + public sealed class IncrementClause : AbstractInsertClause + { + public required string Column { get; init; } + public required int Value { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/InsertClause.cs b/QueryBuilder/Query/Clauses/InsertClause.cs new file mode 100644 index 00000000..00f0aed9 --- /dev/null +++ b/QueryBuilder/Query/Clauses/InsertClause.cs @@ -0,0 +1,32 @@ +using System.Collections.Immutable; +using SqlKata.Compilers; + +namespace SqlKata +{ + public static class InsertColumnsExt + { + public static void WriteInsertColumnsList(this Writer writer, ImmutableArray columns, bool braces = true) + { + if (columns.Length == 0) return; + if (braces) writer.Append(" ("); + writer.List(", ", columns, writer.AppendName); + if (braces) writer.Append(")"); + } + } + public abstract class AbstractInsertClause : AbstractClause + { + } + + public class InsertClause : AbstractInsertClause + { + public required ImmutableArray Columns { get; init; } + public required ImmutableArray Values { get; init; } + public required bool ReturnId { get; init; } + } + + public sealed class InsertQueryClause : AbstractInsertClause + { + public required ImmutableArray Columns { get; init; } + public required Query Query { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/JoinClause.cs b/QueryBuilder/Query/Clauses/JoinClause.cs new file mode 100644 index 00000000..f4549426 --- /dev/null +++ b/QueryBuilder/Query/Clauses/JoinClause.cs @@ -0,0 +1,11 @@ +namespace SqlKata +{ + public abstract class AbstractJoin : AbstractClause + { + } + + public sealed class BaseJoin : AbstractJoin + { + public required Join Join { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/LimitClause.cs b/QueryBuilder/Query/Clauses/LimitClause.cs new file mode 100644 index 00000000..39c1d61a --- /dev/null +++ b/QueryBuilder/Query/Clauses/LimitClause.cs @@ -0,0 +1,7 @@ +namespace SqlKata +{ + public sealed class LimitClause : AbstractClause + { + public required int Limit { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/OffsetClause.cs b/QueryBuilder/Query/Clauses/OffsetClause.cs new file mode 100644 index 00000000..bb234e33 --- /dev/null +++ b/QueryBuilder/Query/Clauses/OffsetClause.cs @@ -0,0 +1,7 @@ +namespace SqlKata +{ + public sealed class OffsetClause : AbstractClause + { + public required long Offset { get; init; } + } +} diff --git a/QueryBuilder/Query/Clauses/OrderClause.cs b/QueryBuilder/Query/Clauses/OrderClause.cs new file mode 100644 index 00000000..c368b816 --- /dev/null +++ b/QueryBuilder/Query/Clauses/OrderClause.cs @@ -0,0 +1,24 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public abstract class AbstractOrderBy : AbstractClause + { + } + + public sealed class OrderBy : AbstractOrderBy + { + public required string Column { get; init; } + public required bool Ascending { get; init; } + } + + public sealed class RawOrderBy : AbstractOrderBy + { + public required string Expression { get; init; } + public required ImmutableArray Bindings { get; init; } + } + + public sealed class OrderByRandom : AbstractOrderBy + { + } +} diff --git a/QueryBuilder/Query/ComponentList.cs b/QueryBuilder/Query/ComponentList.cs new file mode 100644 index 00000000..51639ad3 --- /dev/null +++ b/QueryBuilder/Query/ComponentList.cs @@ -0,0 +1,102 @@ +namespace SqlKata +{ + public interface IComponentList + { + List GetComponents(string component, string? engineCode = null) where TC : AbstractClause; + List GetComponents(string component, string? engineCode = null); + TC? GetOneComponent(string component, string? engineCode = null) where TC : AbstractClause; + AbstractClause? GetOneComponent(string component, string? engineCode = null); + bool HasComponent(string component, string? engineCode = null); + bool Any(string type); + } + + public sealed class ComponentList : IComponentList + { + public ComponentList() + { + Clauses = new List(); + } + + private ComponentList(List clauses) + { + Clauses = clauses; + } + + public List Clauses { get; private set; } + + public void AddComponent(AbstractClause clause) + { + ArgumentNullException.ThrowIfNull(clause); + Clauses.Add(clause); + } + + public void AddOrReplaceComponent(AbstractClause clause) + { + ArgumentNullException.ThrowIfNull(clause); + var countRemoved = Clauses.RemoveAll( + c => c.Component == clause.Component && + c.Engine == clause.Engine); + if (countRemoved > 1) throw + new InvalidOperationException("AddOrReplaceComponent cannot replace a component when there is more than one component to replace!"); + + AddComponent(clause); + } + + public List GetComponents(string component, string? engineCode = null) where TC : AbstractClause + { + return Clauses + .Where(x => x.Component == component) + .Where(x => engineCode == null || x.Engine == null || engineCode == x.Engine) + .Cast() + .ToList(); + } + + public List GetComponents(string component, string? engineCode = null) + { + return GetComponents(component, engineCode); + } + + public TC? GetOneComponent(string component, string? engineCode = null) where TC : AbstractClause + { + var all = GetComponents(component, engineCode); + return all.FirstOrDefault(c => c.Engine == engineCode) ?? + all.FirstOrDefault(c => c.Engine == null); + } + + public AbstractClause? GetOneComponent(string component, string? engineCode = null) + { + return GetOneComponent(component, engineCode); + } + + public bool HasComponent(string component, string? engineCode = null) + { + return GetComponents(component, engineCode).Any(); + } + + public void RemoveComponent(string component, string? engineCode) + { + Clauses = Clauses + .Where(x => !(x.Component == component && + (engineCode == null || x.Engine == null || engineCode == x.Engine))) + .ToList(); + } + + public ComponentList Clone() + { + return new ComponentList(Clauses.ToList()); + } + + public bool Any(string type) + { + return Clauses.Any(x => x.Component == type); + } + } + + public static class EnumerableExt + { + public static List? NullIfEmpty(this List src) + { + return src.Count > 0 ? src : default; + } + } +} diff --git a/QueryBuilder/Query/Extras/Include.cs b/QueryBuilder/Query/Extras/Include.cs new file mode 100644 index 00000000..613cadd8 --- /dev/null +++ b/QueryBuilder/Query/Extras/Include.cs @@ -0,0 +1,12 @@ +namespace SqlKata +{ + public sealed class Include + { + public required string Name { get; init; } + public required Query Query { get; init; } + public required string LocalKey { get; init; } + public required bool IsMany { get; init; } + + public required string? ForeignKey { get; set; } + } +} diff --git a/QueryBuilder/Query/Extras/Join.cs b/QueryBuilder/Query/Extras/Join.cs new file mode 100644 index 00000000..5c53f615 --- /dev/null +++ b/QueryBuilder/Query/Extras/Join.cs @@ -0,0 +1,89 @@ +namespace SqlKata +{ + public sealed class Join + { + public Query BaseQuery { get; } + + public Join(Query baseQuery) + { + BaseQuery = baseQuery; + } + + public string? Type { get; private set; } + + public Join Clone() => new(BaseQuery) { Type = Type }; + + public Join AsType(string type) + { + ArgumentNullException.ThrowIfNull(type); + Type = type.ToUpperInvariant(); + return this; + } + + /// + /// Alias for "from" operator. + /// Since "from" does not sound well with join clauses + /// + /// + /// + public Join JoinWith(string table) + { + return new Join(BaseQuery.From(table)); + } + + public Join JoinWith(Query query) + { + return new Join(BaseQuery.From(query)); + } + + public Join JoinWith(Func callback) + { + return new Join(BaseQuery.From(callback)); + } + + public Join AsInner() + { + return AsType("inner join"); + } + + public Join AsOuter() + { + return AsType("outer join"); + } + + public Join AsLeft() + { + return AsType("left join"); + } + + public Join AsRight() + { + return AsType("right join"); + } + + public Join AsCross() + { + return AsType("cross join"); + } + + public Join On(string first, string second, string op = "=") + { + return new Join(BaseQuery.AddComponent(new TwoColumnsCondition + { + Engine = BaseQuery.EngineScope, + Component = "where", + First = first, + Second = second, + Operator = op, + IsOr = BaseQuery.GetOr(), + IsNot = BaseQuery.GetNot() + })); + } + + public Join OrOn(string first, string second, string op = "=") + { + return new Join(BaseQuery.Or()).On(first, second, op); + } + + } +} diff --git a/QueryBuilder/Query/Extras/UnsafeLiteral.cs b/QueryBuilder/Query/Extras/UnsafeLiteral.cs new file mode 100644 index 00000000..77937bfc --- /dev/null +++ b/QueryBuilder/Query/Extras/UnsafeLiteral.cs @@ -0,0 +1,16 @@ +namespace SqlKata +{ + public sealed class UnsafeLiteral + { + public UnsafeLiteral(string? value, bool replaceQuotes = true) + { + value ??= ""; + + if (replaceQuotes) value = value.Replace("'", "''"); + + Value = value; + } + + public string Value { get; set; } + } +} diff --git a/QueryBuilder/Variable.cs b/QueryBuilder/Query/Extras/Variable.cs similarity index 83% rename from QueryBuilder/Variable.cs rename to QueryBuilder/Query/Extras/Variable.cs index 63b936ea..090964c3 100644 --- a/QueryBuilder/Variable.cs +++ b/QueryBuilder/Query/Extras/Variable.cs @@ -2,12 +2,11 @@ namespace SqlKata { public class Variable { - public string Name { get; set; } - public Variable(string name) { - this.Name = name; + Name = name; } + public string Name { get; set; } } } diff --git a/QueryBuilder/Query.Aggregate.cs b/QueryBuilder/Query/Query.Aggregate.cs similarity index 52% rename from QueryBuilder/Query.Aggregate.cs rename to QueryBuilder/Query/Query.Aggregate.cs index d4fc5057..5083d3d0 100644 --- a/QueryBuilder/Query.Aggregate.cs +++ b/QueryBuilder/Query/Query.Aggregate.cs @@ -1,41 +1,39 @@ -using System.Collections.Generic; -using System.Linq; +using System.Collections.Immutable; namespace SqlKata { public partial class Query { - public Query AsAggregate(string type, string[] columns = null) + public Query AsAggregate(string type, string[]? columns = null) { - Method = "aggregate"; - this.ClearComponent("aggregate") - .AddComponent("aggregate", new AggregateClause - { - Type = type, - Columns = columns?.ToList() ?? new List(), - }); + RemoveComponent("aggregate") + .AddComponent(new AggregateClause + { + Engine = EngineScope, + Component = "aggregate", + Type = type, + Columns = columns?.ToImmutableArray() ?? ImmutableArray.Empty + }); return this; } - public Query AsCount(string[] columns = null) + public Query AsCount(string[]? columns = null) { - var cols = columns?.ToList() ?? new List { }; + var cols = columns?.ToList() ?? new List(); - if (!cols.Any()) - { - cols.Add("*"); - } + if (!cols.Any()) cols.Add("*"); return AsAggregate("count", cols.ToArray()); } public Query AsAvg(string column) { - return AsAggregate("avg", new string[] { column }); + return AsAggregate("avg", new[] { column }); } + public Query AsAverage(string column) { return AsAvg(column); diff --git a/QueryBuilder/Query.Combine.cs b/QueryBuilder/Query/Query.Combine.cs similarity index 75% rename from QueryBuilder/Query.Combine.cs rename to QueryBuilder/Query/Query.Combine.cs index b7238264..6d964265 100644 --- a/QueryBuilder/Query.Combine.cs +++ b/QueryBuilder/Query/Query.Combine.cs @@ -1,37 +1,34 @@ -using System; -using System.Linq; +using System.Collections.Immutable; namespace SqlKata { public partial class Query { - public Query Combine(string operation, bool all, Query query) { - if (this.Method != "select" || query.Method != "select") - { + if (Method != "select" || query.Method != "select") throw new InvalidOperationException("Only select queries can be combined."); - } - return AddComponent("combine", new Combine + return AddComponent(new Combine { + Engine = EngineScope, + Component = "combine", Query = query, Operation = operation, - All = all, + All = all }); } public Query CombineRaw(string sql, params object[] bindings) { - if (this.Method != "select") - { - throw new InvalidOperationException("Only select queries can be combined."); - } + if (Method != "select") throw new InvalidOperationException("Only select queries can be combined."); - return AddComponent("combine", new RawCombine + return AddComponent(new RawCombine { + Engine = EngineScope, + Component = "combine", Expression = sql, - Bindings = bindings, + Bindings = bindings.ToImmutableArray() }); } @@ -56,7 +53,10 @@ public Query UnionAll(Func callback) return Union(callback, true); } - public Query UnionRaw(string sql, params object[] bindings) => CombineRaw(sql, bindings); + public Query UnionRaw(string sql, params object[] bindings) + { + return CombineRaw(sql, bindings); + } public Query Except(Query query, bool all = false) { @@ -78,7 +78,11 @@ public Query ExceptAll(Func callback) { return Except(callback, true); } - public Query ExceptRaw(string sql, params object[] bindings) => CombineRaw(sql, bindings); + + public Query ExceptRaw(string sql, params object[] bindings) + { + return CombineRaw(sql, bindings); + } public Query Intersect(Query query, bool all = false) { @@ -100,7 +104,10 @@ public Query IntersectAll(Func callback) { return Intersect(callback, true); } - public Query IntersectRaw(string sql, params object[] bindings) => CombineRaw(sql, bindings); + public Query IntersectRaw(string sql, params object[] bindings) + { + return CombineRaw(sql, bindings); + } } } diff --git a/QueryBuilder/Query.Delete.cs b/QueryBuilder/Query/Query.Delete.cs similarity index 99% rename from QueryBuilder/Query.Delete.cs rename to QueryBuilder/Query/Query.Delete.cs index bd00cad9..6cda531a 100644 --- a/QueryBuilder/Query.Delete.cs +++ b/QueryBuilder/Query/Query.Delete.cs @@ -7,6 +7,5 @@ public Query AsDelete() Method = "delete"; return this; } - } } diff --git a/QueryBuilder/Query.Having.cs b/QueryBuilder/Query/Query.Having.cs similarity index 76% rename from QueryBuilder/Query.Having.cs rename to QueryBuilder/Query/Query.Having.cs index ee367941..65493670 100644 --- a/QueryBuilder/Query.Having.cs +++ b/QueryBuilder/Query/Query.Having.cs @@ -1,30 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Immutable; using System.Reflection; namespace SqlKata { public partial class Query { - public Query Having(string column, string op, object value) + public Query Having(string column, string op, object? value) { - // If the value is "null", we will just assume the developer wants to add a // Having null clause to the query. So, we will allow a short-cut here to // that method for convenience so the developer doesn't have to check. - if (value == null) - { - return Not(op != "=").HavingNull(column); - } + if (value == null) return Not(op != "=").HavingNull(column); - return AddComponent("having", new BasicCondition + return AddComponent(new BasicCondition { + Engine = EngineScope, + Component = "having", Column = column, Operator = op, Value = value, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } @@ -40,44 +36,45 @@ public Query OrHaving(string column, string op, object value) public Query OrHavingNot(string column, string op, object value) { - return this.Or().Not().Having(column, op, value); + return Or().Not().Having(column, op, value); } - public Query Having(string column, object value) + public Query Having(string column, object? value) { return Having(column, "=", value); } + public Query HavingNot(string column, object value) { return HavingNot(column, "=", value); } + public Query OrHaving(string column, object value) { return OrHaving(column, "=", value); } + public Query OrHavingNot(string column, object value) { return OrHavingNot(column, "=", value); } /// - /// Perform a Having constraint + /// Perform a Having constraint /// /// /// public Query Having(object constraints) { - var dictionary = new Dictionary(); + var dictionary = new Dictionary(); foreach (var item in constraints.GetType().GetRuntimeProperties()) - { dictionary.Add(item.Name, item.GetValue(constraints)); - } return Having(dictionary); } - public Query Having(IEnumerable> values) + public Query Having(IEnumerable> values) { var query = this; var orFlag = GetOr(); @@ -86,15 +83,11 @@ public Query Having(IEnumerable> values) foreach (var tuple in values) { if (orFlag) - { - query = query.Or(); - } + query.Or(); else - { query.And(); - } - query = this.Not(notFlag).Having(tuple.Key, tuple.Value); + query = Not(notFlag).Having(tuple.Key, tuple.Value); } return query; @@ -102,12 +95,14 @@ public Query Having(IEnumerable> values) public Query HavingRaw(string sql, params object[] bindings) { - return AddComponent("having", new RawCondition + return AddComponent(new RawCondition { + Engine = EngineScope, + Component = "having", Expression = sql, Bindings = bindings, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } @@ -117,7 +112,7 @@ public Query OrHavingRaw(string sql, params object[] bindings) } /// - /// Apply a nested Having clause + /// Apply a nested Having clause /// /// /// @@ -125,11 +120,13 @@ public Query Having(Func callback) { var query = callback.Invoke(NewChild()); - return AddComponent("having", new NestedCondition + return AddComponent(new NestedCondition { + Engine = EngineScope, + Component = "having", Query = query, IsNot = GetNot(), - IsOr = GetOr(), + IsOr = GetOr() }); } @@ -150,13 +147,15 @@ public Query OrHavingNot(Func callback) public Query HavingColumns(string first, string op, string second) { - return AddComponent("having", new TwoColumnsCondition + return AddComponent(new TwoColumnsCondition { + Engine = EngineScope, + Component = "having", First = first, Second = second, Operator = op, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } @@ -167,11 +166,13 @@ public Query OrHavingColumns(string first, string op, string second) public Query HavingNull(string column) { - return AddComponent("having", new NullCondition + return AddComponent(new NullCondition { + Engine = EngineScope, + Component = "having", Column = column, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } @@ -182,7 +183,7 @@ public Query HavingNotNull(string column) public Query OrHavingNull(string column) { - return this.Or().HavingNull(column); + return Or().HavingNull(column); } public Query OrHavingNotNull(string column) @@ -192,10 +193,14 @@ public Query OrHavingNotNull(string column) public Query HavingTrue(string column) { - return AddComponent("having", new BooleanCondition + return AddComponent(new BooleanCondition { + IsOr = false, + IsNot = false, + Engine = EngineScope, + Component = "having", Column = column, - Value = true, + Value = true }); } @@ -206,10 +211,14 @@ public Query OrHavingTrue(string column) public Query HavingFalse(string column) { - return AddComponent("having", new BooleanCondition + return AddComponent(new BooleanCondition { + IsOr = false, + IsNot = false, + Engine = EngineScope, + Component = "having", Column = column, - Value = false, + Value = false }); } @@ -218,125 +227,151 @@ public Query OrHavingFalse(string column) return Or().HavingFalse(column); } - public Query HavingLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingLike(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) { - return AddComponent("having", new BasicStringCondition + return AddComponent(new BasicStringCondition { + Engine = EngineScope, + Component = "having", Operator = "like", Column = column, Value = value, CaseSensitive = caseSensitive, EscapeCharacter = escapeCharacter, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } - public Query HavingNotLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingNotLike(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Not().HavingLike(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingLike(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().HavingLike(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingNotLike(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingNotLike(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().Not().HavingLike(column, value, caseSensitive, escapeCharacter); } - public Query HavingStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + + public Query HavingStarts(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { - return AddComponent("having", new BasicStringCondition + return AddComponent(new BasicStringCondition { + Engine = EngineScope, + Component = "having", Operator = "starts", Column = column, Value = value, CaseSensitive = caseSensitive, EscapeCharacter = escapeCharacter, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } - public Query HavingNotStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingNotStarts(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Not().HavingStarts(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingStarts(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().HavingStarts(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingNotStarts(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingNotStarts(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().Not().HavingStarts(column, value, caseSensitive, escapeCharacter); } - public Query HavingEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingEnds(string column, object value, bool caseSensitive = false, char? escapeCharacter = null) { - return AddComponent("having", new BasicStringCondition + return AddComponent(new BasicStringCondition { + Engine = EngineScope, + Component = "having", Operator = "ends", Column = column, Value = value, CaseSensitive = caseSensitive, EscapeCharacter = escapeCharacter, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } - public Query HavingNotEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingNotEnds(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Not().HavingEnds(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingEnds(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().HavingEnds(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingNotEnds(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingNotEnds(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().Not().HavingEnds(column, value, caseSensitive, escapeCharacter); } - public Query HavingContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { - return AddComponent("having", new BasicStringCondition + return AddComponent(new BasicStringCondition { + Engine = EngineScope, + Component = "having", Operator = "contains", Column = column, Value = value, CaseSensitive = caseSensitive, EscapeCharacter = escapeCharacter, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } - public Query HavingNotContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query HavingNotContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Not().HavingContains(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().HavingContains(column, value, caseSensitive, escapeCharacter); } - public Query OrHavingNotContains(string column, object value, bool caseSensitive = false, string escapeCharacter = null) + public Query OrHavingNotContains(string column, object value, bool caseSensitive = false, + char? escapeCharacter = null) { return Or().Not().HavingContains(column, value, caseSensitive, escapeCharacter); } public Query HavingBetween(string column, T lower, T higher) + where T: notnull { - return AddComponent("having", new BetweenCondition + return AddComponent(new BetweenCondition { + Engine = EngineScope, + Component = "having", Column = column, IsOr = GetOr(), IsNot = GetNot(), @@ -346,57 +381,66 @@ public Query HavingBetween(string column, T lower, T higher) } public Query OrHavingBetween(string column, T lower, T higher) + where T : notnull { return Or().HavingBetween(column, lower, higher); } + public Query HavingNotBetween(string column, T lower, T higher) + where T : notnull { return Not().HavingBetween(column, lower, higher); } + public Query OrHavingNotBetween(string column, T lower, T higher) + where T : notnull { return Or().Not().HavingBetween(column, lower, higher); } public Query HavingIn(string column, IEnumerable values) + where T : notnull { // If the developer has passed a string they most likely want a List // since string is considered as List - if (values is string) + if (values is string val) { - string val = values as string; - - return AddComponent("having", new InCondition + return AddComponent(new InCondition { + Engine = EngineScope, + Component = "having", Column = column, IsOr = GetOr(), IsNot = GetNot(), - Values = new List { val } + Values = ImmutableArray.Create(val) }); } - return AddComponent("having", new InCondition + return AddComponent(new InCondition { + Engine = EngineScope, + Component = "having", Column = column, IsOr = GetOr(), IsNot = GetNot(), - Values = values.Distinct().ToList() + Values = values.Distinct().Cast().ToImmutableArray() }); - - } public Query OrHavingIn(string column, IEnumerable values) + where T : notnull { return Or().HavingIn(column, values); } public Query HavingNotIn(string column, IEnumerable values) + where T : notnull { return Not().HavingIn(column, values); } public Query OrHavingNotIn(string column, IEnumerable values) + where T : notnull { return Or().Not().HavingIn(column, values); } @@ -404,14 +448,17 @@ public Query OrHavingNotIn(string column, IEnumerable values) public Query HavingIn(string column, Query query) { - return AddComponent("having", new InQueryCondition + return AddComponent(new InQueryCondition { + Engine = EngineScope, + Component = "having", Column = column, IsOr = GetOr(), IsNot = GetNot(), - Query = query, + Query = query }); } + public Query HavingIn(string column, Func callback) { var query = callback.Invoke(new Query()); @@ -428,6 +475,7 @@ public Query OrHavingIn(string column, Func callback) { return Or().HavingIn(column, callback); } + public Query HavingNotIn(string column, Query query) { return Not().HavingIn(column, query); @@ -450,7 +498,7 @@ public Query OrHavingNotIn(string column, Func callback) /// - /// Perform a sub query Having clause + /// Perform a sub query Having clause /// /// /// @@ -465,13 +513,15 @@ public Query Having(string column, string op, Func callback) public Query Having(string column, string op, Query query) { - return AddComponent("having", new QueryCondition + return AddComponent(new QueryCondition { + Engine = EngineScope, + Component = "having", Column = column, Operator = op, Query = query, IsNot = GetNot(), - IsOr = GetOr(), + IsOr = GetOr() }); } @@ -479,6 +529,7 @@ public Query OrHaving(string column, string op, Query query) { return Or().Having(column, op, query); } + public Query OrHaving(string column, string op, Func callback) { return Or().Having(column, op, callback); @@ -487,22 +538,24 @@ public Query OrHaving(string column, string op, Func callback) public Query HavingExists(Query query) { if (!query.HasComponent("from")) - { - throw new ArgumentException($"{nameof(FromClause)} cannot be empty if used inside a {nameof(HavingExists)} condition"); - } + throw new ArgumentException( + $"{nameof(FromClause)} cannot be empty if used inside a {nameof(HavingExists)} condition"); // simplify the query as much as possible - query = query.Clone().ClearComponent("select") + query = query.Clone().RemoveComponent("select") .SelectRaw("1") .Limit(1); - return AddComponent("having", new ExistsCondition + return AddComponent(new ExistsCondition { + Engine = EngineScope, + Component = "having", Query = query, IsNot = GetNot(), - IsOr = GetOr(), + IsOr = GetOr() }); } + public Query HavingExists(Func callback) { var childQuery = new Query().SetParent(this); @@ -523,32 +576,39 @@ public Query OrHavingExists(Query query) { return Or().HavingExists(query); } + public Query OrHavingExists(Func callback) { return Or().HavingExists(callback); } + public Query OrHavingNotExists(Query query) { return Or().Not().HavingExists(query); } + public Query OrHavingNotExists(Func callback) { return Or().Not().HavingExists(callback); } #region date + public Query HavingDatePart(string part, string column, string op, object value) { - return AddComponent("having", new BasicDateCondition + return AddComponent(new BasicDateCondition { + Engine = EngineScope, + Component = "having", Operator = op, Column = column, Value = value, Part = part, IsOr = GetOr(), - IsNot = GetNot(), + IsNot = GetNot() }); } + public Query HavingNotDatePart(string part, string column, string op, object value) { return Not().HavingDatePart(part, column, op, value); @@ -568,14 +628,17 @@ public Query HavingDate(string column, string op, object value) { return HavingDatePart("date", column, op, value); } + public Query HavingNotDate(string column, string op, object value) { return Not().HavingDate(column, op, value); } + public Query OrHavingDate(string column, string op, object value) { return Or().HavingDate(column, op, value); } + public Query OrHavingNotDate(string column, string op, object value) { return Or().Not().HavingDate(column, op, value); @@ -585,14 +648,17 @@ public Query HavingTime(string column, string op, object value) { return HavingDatePart("time", column, op, value); } + public Query HavingNotTime(string column, string op, object value) { return Not().HavingTime(column, op, value); } + public Query OrHavingTime(string column, string op, object value) { return Or().HavingTime(column, op, value); } + public Query OrHavingNotTime(string column, string op, object value) { return Or().Not().HavingTime(column, op, value); @@ -602,6 +668,7 @@ public Query HavingDatePart(string part, string column, object value) { return HavingDatePart(part, column, "=", value); } + public Query HavingNotDatePart(string part, string column, object value) { return HavingNotDatePart(part, column, "=", value); @@ -621,14 +688,17 @@ public Query HavingDate(string column, object value) { return HavingDate(column, "=", value); } + public Query HavingNotDate(string column, object value) { return HavingNotDate(column, "=", value); } + public Query OrHavingDate(string column, object value) { return OrHavingDate(column, "=", value); } + public Query OrHavingNotDate(string column, object value) { return OrHavingNotDate(column, "=", value); @@ -638,14 +708,17 @@ public Query HavingTime(string column, object value) { return HavingTime(column, "=", value); } + public Query HavingNotTime(string column, object value) { return HavingNotTime(column, "=", value); } + public Query OrHavingTime(string column, object value) { return OrHavingTime(column, "=", value); } + public Query OrHavingNotTime(string column, object value) { return OrHavingNotTime(column, "=", value); diff --git a/QueryBuilder/Query/Query.Insert.cs b/QueryBuilder/Query/Query.Insert.cs new file mode 100644 index 00000000..f36ace58 --- /dev/null +++ b/QueryBuilder/Query/Query.Insert.cs @@ -0,0 +1,126 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public partial class Query + { + public Query AsInsert(object data, bool returnId = false) + { + return AsInsert(BuildKeyValuePairsFromObject(data), returnId); + } + + public Query AsInsert(IEnumerable columns, IEnumerable values) + { + ArgumentNullException.ThrowIfNull(columns); + ArgumentNullException.ThrowIfNull(values); + + var columnsList = columns.ToImmutableArray(); + var valuesList = values.ToImmutableArray(); + + if (columnsList.Length == 0 || valuesList.Length == 0) + throw new InvalidOperationException($"{nameof(columns)} and {nameof(values)} cannot be null or empty"); + + if (columnsList.Length != valuesList.Length) + throw new InvalidOperationException($"The number of {nameof(columns)} and {nameof(values)} must match"); + + Method = "insert"; + + RemoveComponent("insert").AddComponent(new InsertClause + { + Engine = EngineScope, + Component = "insert", + Columns = columnsList, + Values = valuesList, + ReturnId = false + }); + + return this; + } + + public Query AsInsert(IEnumerable> values, bool returnId = false) + { + var valuesCached = values is IReadOnlyDictionary d + ? d + : values.ToDictionary(x => x.Key, x => x.Value); + if (valuesCached == null || valuesCached.Count == 0) + throw new InvalidOperationException($"{valuesCached} argument cannot be null or empty"); + + Method = "insert"; + + RemoveComponent("insert").AddComponent(new InsertClause + { + Engine = EngineScope, + Component = "insert", + + Columns = valuesCached.Select(x => x.Key).ToImmutableArray(), + Values = valuesCached.Select(x => x.Value).ToImmutableArray(), + ReturnId = returnId + }); + + return this; + } + + /// + /// Produces insert multi records + /// + /// + /// + /// + public Query AsInsert(IEnumerable columns, IEnumerable> rowsValues) + { + var columnsList = columns is ImmutableArray l ? l : columns.ToImmutableArray(); + var valuesCollectionList = rowsValues is IReadOnlyList> r + ? r + : rowsValues.Select(v => v.ToImmutableArray()).ToImmutableArray(); + + if (columnsList.Length == 0 || valuesCollectionList.Count == 0) + throw new InvalidOperationException( + $"{nameof(columns)} and {nameof(rowsValues)} cannot be null or empty"); + + Method = "insert"; + + RemoveComponent("insert"); + + foreach (var values in valuesCollectionList) + { + var valuesList = values.ToImmutableArray(); + if (columnsList.Length != valuesList.Length) + throw new InvalidOperationException( + $"{nameof(columns)} count should be equal to each {nameof(rowsValues)} entry count"); + + AddComponent(new InsertClause + { + Engine = EngineScope, + Component = "insert", + + Columns = columnsList, + Values = valuesList, + ReturnId = false + }); + } + + return this; + } + + /// + /// Produces insert from subQuery + /// + /// + /// + /// + public Query AsInsert(IEnumerable columns, Query query) + { + Method = "insert"; + + RemoveComponent("insert").AddComponent(new InsertQueryClause + { + Engine = EngineScope, + Component = "insert", + Columns = columns.ToImmutableArray(), + Query = query.Clone() + }); + + return this; + } + } +} diff --git a/QueryBuilder/Query.Join.cs b/QueryBuilder/Query/Query.Join.cs similarity index 65% rename from QueryBuilder/Query.Join.cs rename to QueryBuilder/Query/Query.Join.cs index 3fe3bbb1..8dae52fc 100644 --- a/QueryBuilder/Query.Join.cs +++ b/QueryBuilder/Query/Query.Join.cs @@ -1,16 +1,15 @@ -using System; - namespace SqlKata { public partial class Query { - private Query Join(Func callback) { - var join = callback.Invoke(new Join().AsInner()); + var join = callback.Invoke(new Join(new Query()).AsInner()); - return AddComponent("join", new BaseJoin + return AddComponent(new BaseJoin { + Engine = EngineScope, + Component = "join", Join = join }); } @@ -23,17 +22,32 @@ public Query Join( string type = "inner join" ) { - return Join(j => j.JoinWith(table).WhereColumns(first, op, second).AsType(type)); + return Join(j => + { + var join = new Join(j.JoinWith(table).BaseQuery); + join.BaseQuery.WhereColumns(first, op, second); + return join.AsType(type); + }); } public Query Join(string table, Func callback, string type = "inner join") { - return Join(j => j.JoinWith(table).Where(callback).AsType(type)); + return Join(j => + { + var join = new Join(j.JoinWith(table).BaseQuery); + join.BaseQuery.Where(q => callback(new Join(q)).BaseQuery); + return join.AsType(type); + }); } public Query Join(Query query, Func onCallback, string type = "inner join") { - return Join(j => j.JoinWith(query).Where(onCallback).AsType(type)); + return Join(j => + { + var join = new Join(j.JoinWith(query).BaseQuery); + join.BaseQuery.Where(q => onCallback(new Join(q)).BaseQuery); + return join.AsType(type); + }); } public Query LeftJoin(string table, string first, string second, string op = "=") @@ -70,6 +84,5 @@ public Query CrossJoin(string table) { return Join(j => j.JoinWith(table).AsCross()); } - } } diff --git a/QueryBuilder/Query.Select.cs b/QueryBuilder/Query/Query.Select.cs similarity index 65% rename from QueryBuilder/Query.Select.cs rename to QueryBuilder/Query/Query.Select.cs index 9502c024..572c938d 100644 --- a/QueryBuilder/Query.Select.cs +++ b/QueryBuilder/Query/Query.Select.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Immutable; namespace SqlKata { public partial class Query { - public Query Select(params string[] columns) { return Select(columns.AsEnumerable()); @@ -23,28 +20,30 @@ public Query Select(IEnumerable columns) foreach (var column in columns) - { - AddComponent("select", new Column + AddComponent(new Column { + Engine = EngineScope, + Component = "select", Name = column }); - } return this; } /// - /// Add a new "raw" select expression to the query. + /// Add a new "raw" select expression to the query. /// /// - public Query SelectRaw(string sql, params object[] bindings) + public Query SelectRaw(string sql, params object?[] bindings) { Method = "select"; - AddComponent("select", new RawColumn + AddComponent(new RawColumn { + Engine = EngineScope, + Component = "select", Expression = sql, - Bindings = bindings, + Bindings = bindings.ToImmutableArray() }); return this; @@ -56,9 +55,11 @@ public Query Select(Query query, string alias) query = query.Clone(); - AddComponent("select", new QueryColumn + AddComponent(new QueryColumn { - Query = query.As(alias), + Engine = EngineScope, + Component = "select", + Query = query.As(alias) }); return this; @@ -69,51 +70,55 @@ public Query Select(Func callback, string alias) return Select(callback.Invoke(NewChild()), alias); } - public Query SelectAggregate(string aggregate, string column, Query filter = null) + public Query SelectAggregate(string aggregate, string column, Query? filter = null) { Method = "select"; - AddComponent("select", new AggregatedColumn + AddComponent(new AggregatedColumn { - Column = new Column { Name = column }, + Engine = EngineScope, + Component = "select", + Column = new Column + { + Engine = EngineScope, + Component = "select", + Name = column + }, Aggregate = aggregate, - Filter = filter, + Filter = filter }); return this; } - public Query SelectAggregate(string aggregate, string column, Func filter) + public Query SelectAggregate(string aggregate, string column, Func? filter) { - if (filter == null) - { - return SelectAggregate(aggregate, column); - } + if (filter == null) return SelectAggregate(aggregate, column); return SelectAggregate(aggregate, column, filter.Invoke(NewChild())); } - public Query SelectSum(string column, Func filter = null) + public Query SelectSum(string column, Func? filter = null) { return SelectAggregate("sum", column, filter); } - public Query SelectCount(string column, Func filter = null) + public Query SelectCount(string column, Func? filter = null) { return SelectAggregate("count", column, filter); } - public Query SelectAvg(string column, Func filter = null) + public Query SelectAvg(string column, Func? filter = null) { return SelectAggregate("avg", column, filter); } - public Query SelectMin(string column, Func filter = null) + public Query SelectMin(string column, Func? filter = null) { return SelectAggregate("min", column, filter); } - public Query SelectMax(string column, Func filter = null) + public Query SelectMax(string column, Func? filter = null) { return SelectAggregate("max", column, filter); } diff --git a/QueryBuilder/Query/Query.Update.cs b/QueryBuilder/Query/Query.Update.cs new file mode 100644 index 00000000..f069d072 --- /dev/null +++ b/QueryBuilder/Query/Query.Update.cs @@ -0,0 +1,77 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public partial class Query + { + public Query AsUpdate(object data) + { + return AsUpdate(BuildKeyValuePairsFromObject(data, true)); + } + + public Query AsUpdate(IEnumerable columns, IEnumerable values) + { + var columnsCache = columns is ImmutableArray c ? c : columns.ToImmutableArray(); + var valuesCache = values is ImmutableArray v ? v : values.ToImmutableArray(); + if (!columnsCache.Any() || !valuesCache.Any()) + throw new InvalidOperationException($"{columnsCache} and {valuesCache} cannot be null or empty"); + + if (columnsCache.Length != valuesCache.Length) + throw new InvalidOperationException($"{columnsCache} count should be equal to {valuesCache} count"); + + Method = "update"; + + RemoveComponent("update").AddComponent(new InsertClause + { + Engine = EngineScope, + Component = "update", + Columns = columnsCache, + Values = valuesCache, + ReturnId = false + }); + + return this; + } + + public Query AsUpdate(IEnumerable> values) + { + var valuesCached = values is IReadOnlyDictionary d + ? d + : values.ToDictionary(x => x.Key, x => x.Value); + if (valuesCached == null || valuesCached.Any() == false) + throw new InvalidOperationException($"{valuesCached} cannot be null or empty"); + + Method = "update"; + + RemoveComponent("update").AddComponent(new InsertClause + { + Engine = EngineScope, + Component = "update", + Columns = valuesCached.Select(x => x.Key).ToImmutableArray(), + Values = valuesCached.Select(x => x.Value).ToImmutableArray(), + ReturnId = false + }); + + return this; + } + + public Query AsIncrement(string column, int value = 1) + { + Method = "update"; + AddOrReplaceComponent(new IncrementClause + { + Engine = EngineScope, + Component = "update", + Column = column, + Value = value, + }); + + return this; + } + + public Query AsDecrement(string column, int value = 1) + { + return AsIncrement(column, -value); + } + } +} diff --git a/QueryBuilder/Query/Query.cs b/QueryBuilder/Query/Query.cs new file mode 100644 index 00000000..bd4695af --- /dev/null +++ b/QueryBuilder/Query/Query.cs @@ -0,0 +1,404 @@ +using System.Collections.Immutable; + +namespace SqlKata +{ + public partial class Query + { + public Query() + { + } + + public Query(string table, string? comment = null) + { + From(table); + Comment(comment); + } + + public string GetComment() + { + return _comment ?? ""; + } + + public bool HasOffset(string? engineCode = null) + { + return GetOffset(engineCode) > 0; + } + + public bool HasLimit(string? engineCode = null) + { + return GetLimit(engineCode) > 0; + } + + // TODO: Refactor: inline and remove + internal long GetOffset(string? engineCode = null) + { + engineCode ??= EngineScope; + var offset = GetOneComponent("offset", engineCode); + + return offset?.Offset ?? 0; + } + // TODO: Refactor: inline and remove + internal int GetLimit(string? engineCode = null) + { + engineCode ??= EngineScope; + var limit = GetOneComponent("limit", engineCode); + + return limit?.Limit ?? 0; + } + + public virtual Query Clone() + { + return new Query + { + _comment = _comment, + Components = Components.Clone(), + Parent = Parent, + QueryAlias = QueryAlias, + IsDistinct = IsDistinct, + Method = Method, + Includes = Includes, + Variables = Variables + }; + } + + public Query As(string alias) + { + QueryAlias = alias; + return this; + } + + /// + /// Sets a comment for the query. + /// + /// The comment. + /// + public Query Comment(string? comment) + { + _comment = comment; + return this; + } + + public Query For(string engine, Func fn) + { + EngineScope = engine; + + var result = fn.Invoke(this); + + // reset the engine + EngineScope = null; + + return result; + } + + public Query With(Query query) + { + // Clear query alias and add it to the containing clause + if (string.IsNullOrWhiteSpace(query.QueryAlias)) + throw new InvalidOperationException("No Alias found for the CTE query"); + + query = query.Clone(); + + var alias = query.QueryAlias?.Trim(); + + // clear the query alias + query.QueryAlias = null; + + return AddComponent(new QueryFromClause + { + Engine = EngineScope, + Component = "cte", + Query = query, + Alias = alias + }); + } + + public Query With(Func fn) + { + return With(fn.Invoke(new Query())); + } + + public Query With(string alias, Query query) + { + return With(query.As(alias)); + } + + public Query With(string alias, Func fn) + { + return With(alias, fn.Invoke(new Query())); + } + + /// + /// Constructs an ad-hoc table of the given data as a CTE. + /// + public Query With(string alias, IEnumerable columns, IEnumerable> valuesCollection) + { + ArgumentNullException.ThrowIfNull(alias); + ArgumentNullException.ThrowIfNull(columns); + ArgumentNullException.ThrowIfNull(valuesCollection); + var col = columns is ImmutableArray l ? l : columns.ToImmutableArray(); + var values = valuesCollection is IReadOnlyList> r + ? r + : valuesCollection.Select(v => v.ToList()).ToList(); + + if (col.Length == 0 || values.Count == 0) + throw new InvalidOperationException("Columns and valuesCollection cannot be null or empty"); + + if (values.Any(row => row.Count != col.Length)) + throw new InvalidOperationException("Columns count should be equal to each Values count"); + + return AddComponent(new AdHocTableFromClause + { + Engine = EngineScope, + Component = "cte", + Alias = alias, + Columns = col, + Values = values.SelectMany(x => x).ToImmutableArray() + }); + } + + public Query WithRaw(string alias, string sql, params object[] bindings) + { + ArgumentNullException.ThrowIfNull(alias); + ArgumentNullException.ThrowIfNull(sql); + ArgumentNullException.ThrowIfNull(bindings); + return AddComponent(new RawFromClause + { + Engine = EngineScope, + Component = "cte", + Alias = alias, + Expression = sql, + Bindings = bindings.ToImmutableArray() + }); + } + + public Query Limit(int value) + { + return AddOrReplaceComponent(new LimitClause + { + Engine = EngineScope, + Component = "limit", + Limit = value < 0 ? 0 : value + }); + } + + public Query Offset(long value) + { + return AddOrReplaceComponent(new OffsetClause + { + Engine = EngineScope, + Component = "offset", + Offset = value < 0 ? 0 : value + }); + } + + public Query Offset(int value) + { + return Offset((long)value); + } + + /// + /// Alias for Limit + /// + /// + /// + public Query Take(int limit) + { + return Limit(limit); + } + + /// + /// Alias for Offset + /// + /// + /// + public Query Skip(int offset) + { + return Offset(offset); + } + + /// + /// Set the limit and offset for a given page. + /// + /// + /// + /// + public Query ForPage(int page, int perPage = 15) + { + return Skip((page - 1) * perPage).Take(perPage); + } + + public Query Distinct() + { + IsDistinct = true; + return this; + } + + /// + /// Apply the callback's query changes if the given "condition" is true. + /// + /// + /// Invoked when the condition is true + /// Optional, invoked when the condition is false + /// + public Query When(bool condition, Func? whenTrue, Func? whenFalse = null) + { + if (condition && whenTrue != null) return whenTrue.Invoke(this); + + if (!condition && whenFalse != null) return whenFalse.Invoke(this); + + return this; + } + + /// + /// Apply the callback's query changes if the given "condition" is false. + /// + /// + /// + /// + public Query WhenNot(bool condition, Func callback) + { + if (!condition) return callback.Invoke(this); + + return this; + } + + public Query OrderBy(params string[] columns) + { + foreach (var column in columns) + AddComponent(new OrderBy + { + Engine = EngineScope, + Component = "order", + Column = column, + Ascending = true + }); + + return this; + } + + public Query OrderByDesc(params string[] columns) + { + foreach (var column in columns) + AddComponent(new OrderBy + { + Engine = EngineScope, + Component = "order", + Column = column, + Ascending = false + }); + + return this; + } + + public Query OrderByRaw(string expression, params object[] bindings) + { + return AddComponent(new RawOrderBy + { + Engine = EngineScope, + Component = "order", + Expression = expression, + Bindings = bindings.FlattenOneLevel().ToImmutableArray() + }); + } + + public Query OrderByRandom(string seed) + { + return AddComponent(new OrderByRandom() + { + Engine = EngineScope, + Component = "order", + }); + } + + public Query GroupBy(params string[] columns) + { + foreach (var column in columns) + AddComponent(new Column + { + Engine = EngineScope, + Component = "group", + Name = column + }); + + return this; + } + + public Query GroupByRaw(string expression, params object?[] bindings) + { + AddComponent(new RawColumn + { + Engine = EngineScope, + Component = "group", + Expression = expression, + Bindings = bindings.ToImmutableArray() + }); + + return this; + } + + public Query Include(string relationName, Query query, + string? foreignKey = null, string localKey = "Id", + bool isMany = false) + { + Includes.Add(new Include + { + Name = relationName, + LocalKey = localKey, + ForeignKey = foreignKey, + Query = query, + IsMany = isMany + }); + + return this; + } + + public Query IncludeMany(string relationName, Query query, + string? foreignKey = null, string localKey = "Id") + { + return Include(relationName, query, foreignKey, localKey, true); + } + + /// + /// Define a variable to be used within the query + /// + /// + /// + /// + public Query Define(string variable, object? value) + { + Variables.Add(variable, value); + + return this; + } + + public object? FindVariable(string variable) + { + var found = Variables.ContainsKey(variable); + + if (found) return Variables[variable]; + + if (Parent != null) return Parent.FindVariable(variable); + + throw new Exception($"Variable '{variable}' not found"); + } + + /// + /// Gather a list of key-values representing the properties of the object and their values. + /// + /// The plain C# object + /// + /// When true it will search for properties with the [Key] attribute + /// and will add it automatically to the Where clause + /// + /// + private IReadOnlyDictionary BuildKeyValuePairsFromObject(object data, + bool considerKeys = false) + { + var dynamicData = data.ToDynamicData(); + if (considerKeys) + foreach (var (name, value) in dynamicData.Keys) + Where(name, value); + return dynamicData.Properties; + } + } +} diff --git a/QueryBuilder/QueryBuilder.csproj b/QueryBuilder/QueryBuilder.csproj old mode 100755 new mode 100644 index 5ce65d65..7588d40e --- a/QueryBuilder/QueryBuilder.csproj +++ b/QueryBuilder/QueryBuilder.csproj @@ -1,36 +1,41 @@ - - SqlKata The C# Sql Query Builder - A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql, Oracle and Firebird - Ahmad Moussawi - Copyright (c) 2017 Ahmad Moussawi - netstandard2.0 - SqlKata - SqlKata + + SqlKata The C# Sql Query Builder + A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql, Oracle and Firebird + Ahmad Moussawi + Copyright (c) 2017 Ahmad Moussawi + net7.0 + SqlKata + SqlKata + enable + enable - - SqlKata - sql;query-builder;dynamic-query - https://github.com/sqlkata/querybuilder - https://github.com/sqlkata/querybuilder - true - MIT - git - https://github.com/sqlkata/querybuilder + + SqlKata + sql;query-builder;dynamic-query + https://github.com/sqlkata/querybuilder + https://github.com/sqlkata/querybuilder + true + MIT + git + https://github.com/sqlkata/querybuilder - - true - true - CS1591 - - - bin\Debug\netstandard2.0\SqlKata.xml - - - bin\Release\netstandard2.0\SqlKata.xml - - - - + + true + true + CS1591 + 11 + + + bin\Debug\netstandard2.0\SqlKata.xml + + + bin\Release\netstandard2.0\SqlKata.xml + + + + + + diff --git a/QueryBuilder/QueryBuilder.csproj.DotSettings b/QueryBuilder/QueryBuilder.csproj.DotSettings new file mode 100644 index 00000000..0cc5c86e --- /dev/null +++ b/QueryBuilder/QueryBuilder.csproj.DotSettings @@ -0,0 +1,6 @@ + + True + True + True + True + True \ No newline at end of file diff --git a/QueryBuilder/QueryBuilder/StringBuilderExtensions.cs b/QueryBuilder/QueryBuilder/StringBuilderExtensions.cs new file mode 100644 index 00000000..fb64fe92 --- /dev/null +++ b/QueryBuilder/QueryBuilder/StringBuilderExtensions.cs @@ -0,0 +1,22 @@ +using System.Text; + +namespace SqlKata +{ + public static class StringBuilderExtensions{ + + public static void RenderList(this StringBuilder sb, + string separator, IEnumerable list, Action? renderItem = null) + { + renderItem ??= x => sb.Append(x); + var any = false; + foreach (var item in list) + { + renderItem(item); + sb.Append(separator); + any = true; + } + + if (any) sb.Remove(sb.Length - separator.Length, separator.Length); + } + } +} diff --git a/QueryBuilder/SqlResult.cs b/QueryBuilder/SqlResult.cs index 58a7b722..526357b0 100644 --- a/QueryBuilder/SqlResult.cs +++ b/QueryBuilder/SqlResult.cs @@ -1,87 +1,21 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; - namespace SqlKata { public class SqlResult { - public Query Query { get; set; } - public string RawSql { get; set; } = ""; - public List Bindings { get; set; } = new List(); - public string Sql { get; set; } = ""; - public Dictionary NamedBindings = new Dictionary(); - - private static readonly Type[] NumberTypes = - { - typeof(int), - typeof(long), - typeof(decimal), - typeof(double), - typeof(float), - typeof(short), - typeof(ushort), - typeof(ulong), - }; + public Dictionary NamedBindings = new(); + private List _bindings = new(); - public override string ToString() - { - var deepParameters = Helper.Flatten(Bindings).ToList(); - - return Helper.ReplaceAll(RawSql, "?", i => - { - if (i >= deepParameters.Count) - { - throw new Exception( - $"Failed to retrieve a binding at index {i}, the total bindings count is {Bindings.Count}"); - } + public string? RawSql { get; private set; } + public IReadOnlyList Bindings => _bindings; + public string Sql { get; set; } = ""; - var value = deepParameters[i]; - return ChangeToSqlValue(value); - }); - } + public void ReplaceRaw(string value) => RawSql = value; + public override string? ToString() => + RawSql == null ? null : Bindings.BindArgs(RawSql); - private string ChangeToSqlValue(object value) + public void ReplaceBindings(IReadOnlyList writerBindings) { - if (value == null) - { - return "NULL"; - } - - if (Helper.IsArray(value)) - { - return Helper.JoinArray(",", value as IEnumerable); - } - - if (NumberTypes.Contains(value.GetType())) - { - return Convert.ToString(value, CultureInfo.InvariantCulture); - } - - if (value is DateTime date) - { - if (date.Date == date) - { - return "'" + date.ToString("yyyy-MM-dd") + "'"; - } - - return "'" + date.ToString("yyyy-MM-dd HH:mm:ss") + "'"; - } - - if (value is bool vBool) - { - return vBool ? "true" : "false"; - } - - if (value is Enum vEnum) - { - return Convert.ToInt32(vEnum) + $" /* {vEnum} */"; - } - - // fallback to string - return "'" + value.ToString().Replace("'","''") + "'"; + _bindings = writerBindings.ToList(); } } } diff --git a/QueryBuilder/UnsafeLiteral.cs b/QueryBuilder/UnsafeLiteral.cs deleted file mode 100644 index 23d81e2d..00000000 --- a/QueryBuilder/UnsafeLiteral.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace SqlKata -{ - public class UnsafeLiteral - { - public string Value { get; set; } - - public UnsafeLiteral(string value, bool replaceQuotes = true) - { - if (value == null) - { - value = ""; - } - - if (replaceQuotes) - { - value = value.Replace("'", "''"); - } - - this.Value = value; - } - - } -} diff --git a/SqlKata.Execution/PaginationIterator.cs b/SqlKata.Execution/PaginationIterator.cs index 9af8d036..3584cc14 100644 --- a/SqlKata.Execution/PaginationIterator.cs +++ b/SqlKata.Execution/PaginationIterator.cs @@ -8,7 +8,7 @@ public class PaginationIterator : IEnumerable> public PaginationResult FirstPage { get; set; } public PaginationResult CurrentPage { get; set; } - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { CurrentPage = FirstPage; diff --git a/SqlKata.Execution/PaginationResult.cs b/SqlKata.Execution/PaginationResult.cs index 85277503..88abca9c 100644 --- a/SqlKata.Execution/PaginationResult.cs +++ b/SqlKata.Execution/PaginationResult.cs @@ -64,32 +64,32 @@ public bool HasPrevious public Query NextQuery() { - return this.Query.ForPage(Page + 1, PerPage); + return Query.ForPage(Page + 1, PerPage); } public PaginationResult Next(IDbTransaction transaction = null, int? timeout = null) { - return this.Query.Paginate(Page + 1, PerPage, transaction, timeout); + return Query.Paginate(Page + 1, PerPage, transaction, timeout); } public async Task> NextAsync(IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - return await this.Query.PaginateAsync(Page + 1, PerPage, transaction, timeout, cancellationToken); + return await Query.PaginateAsync(Page + 1, PerPage, transaction, timeout, cancellationToken); } public Query PreviousQuery() { - return this.Query.ForPage(Page - 1, PerPage); + return Query.ForPage(Page - 1, PerPage); } public PaginationResult Previous(IDbTransaction transaction = null, int? timeout = null) { - return this.Query.Paginate(Page - 1, PerPage, transaction, timeout); + return Query.Paginate(Page - 1, PerPage, transaction, timeout); } public async Task> PreviousAsync(IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - return await this.Query.PaginateAsync(Page - 1, PerPage, transaction, timeout, cancellationToken); + return await Query.PaginateAsync(Page - 1, PerPage, transaction, timeout, cancellationToken); } public PaginationIterator Each diff --git a/SqlKata.Execution/Query.Extensions.cs b/SqlKata.Execution/Query.Extensions.cs index 4a19d608..8f1cd7b7 100644 --- a/SqlKata.Execution/Query.Extensions.cs +++ b/SqlKata.Execution/Query.Extensions.cs @@ -116,11 +116,11 @@ public static void Chunk(this Query query, int chunkSize, Func { var db = CreateQueryFactory(query); - db.Chunk(query, chunkSize, func, transaction, timeout); + db.Chunk(query, chunkSize, func, transaction, timeout); } public static async Task ChunkAsync(this Query query, int chunkSize, Func, int, bool> func, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - await CreateQueryFactory(query).ChunkAsync(query, chunkSize, func, transaction, timeout, cancellationToken); + await CreateQueryFactory(query).ChunkAsync(query, chunkSize, func, transaction, timeout, cancellationToken); } public static void Chunk(this Query query, int chunkSize, Func, int, bool> func, IDbTransaction transaction = null, int? timeout = null) @@ -141,7 +141,7 @@ public static void Chunk(this Query query, int chunkSize, Action(this Query query, int chunkSize, Action, int> action, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - await CreateQueryFactory(query).ChunkAsync(query, chunkSize, action, transaction, timeout, cancellationToken); + await CreateQueryFactory(query).ChunkAsync(query, chunkSize, action, transaction, timeout, cancellationToken); } public static void Chunk(this Query query, int chunkSize, Action, int> action, IDbTransaction transaction = null, int? timeout = null) diff --git a/SqlKata.Execution/QueryFactory.cs b/SqlKata.Execution/QueryFactory.cs index 5ff399aa..93f14d77 100644 --- a/SqlKata.Execution/QueryFactory.cs +++ b/SqlKata.Execution/QueryFactory.cs @@ -15,8 +15,8 @@ public class QueryFactory : IDisposable { public IDbConnection Connection { get; set; } public Compiler Compiler { get; set; } - public Action Logger = result => { }; - private bool disposedValue; + public Action Logger = _ => { }; + private bool _disposedValue; public int QueryTimeout { get; set; } = 30; @@ -31,7 +31,7 @@ public QueryFactory(IDbConnection connection, Compiler compiler, int timeout = 3 public Query Query() { - var query = new XQuery(this.Connection, this.Compiler); + var query = new XQuery(Connection, Compiler); query.QueryFactory = this; @@ -52,11 +52,11 @@ public Query Query(string table) /// public Query FromQuery(Query query) { - var xQuery = new XQuery(this.Connection, this.Compiler); - - xQuery.QueryFactory = this; - - xQuery.Clauses = query.Clauses.Select(x => x.Clone()).ToList(); + var xQuery = new XQuery(Connection, Compiler) + { + QueryFactory = this, + Components = query.Components.Clone() + }; xQuery.SetParent(query.Parent); xQuery.QueryAlias = query.QueryAlias; @@ -76,14 +76,14 @@ public IEnumerable Get(Query query, IDbTransaction transaction = null, int { var compiled = CompileAndLog(query); - var result = this.Connection.Query( + var result = Connection.Query( compiled.Sql, compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout + commandTimeout: timeout ?? QueryTimeout ).ToList(); - result = handleIncludes(query, result).ToList(); + result = HandleIncludes(query, result).ToList(); return result; } @@ -95,12 +95,12 @@ public async Task> GetAsync(Query query, IDbTransaction transa commandText: compiled.Sql, parameters: compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - var result = (await this.Connection.QueryAsync(commandDefinition)).ToList(); + var result = (await Connection.QueryAsync(commandDefinition)).ToList(); - result = (await handleIncludesAsync(query, result, cancellationToken)).ToList(); + result = (await HandleIncludesAsync(query, result, cancellationToken)).ToList(); return result; } @@ -109,11 +109,11 @@ public IEnumerable> GetDictionary(Query query, IDbTr { var compiled = CompileAndLog(query); - var result = this.Connection.Query( + var result = Connection.Query( compiled.Sql, compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout + commandTimeout: timeout ?? QueryTimeout ); return result.Cast>(); @@ -126,10 +126,10 @@ public async Task>> GetDictionaryAsync(Q commandText: compiled.Sql, parameters: compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - var result = await this.Connection.QueryAsync(commandDefinition); + var result = await Connection.QueryAsync(commandDefinition); return result.Cast>(); } @@ -210,11 +210,11 @@ public int Execute( { var compiled = CompileAndLog(query); - return this.Connection.Execute( + return Connection.Execute( compiled.Sql, compiled.NamedBindings, transaction, - timeout ?? this.QueryTimeout + timeout ?? QueryTimeout ); } @@ -230,21 +230,21 @@ public async Task ExecuteAsync( commandText: compiled.Sql, parameters: compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - return await this.Connection.ExecuteAsync(commandDefinition); + return await Connection.ExecuteAsync(commandDefinition); } public T ExecuteScalar(Query query, IDbTransaction transaction = null, int? timeout = null) { var compiled = CompileAndLog(query.Limit(1)); - return this.Connection.ExecuteScalar( + return Connection.ExecuteScalar( compiled.Sql, compiled.NamedBindings, transaction, - timeout ?? this.QueryTimeout + timeout ?? QueryTimeout ); } @@ -260,43 +260,43 @@ public async Task ExecuteScalarAsync( commandText: compiled.Sql, parameters: compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - return await this.Connection.ExecuteScalarAsync(commandDefinition); + return await Connection.ExecuteScalarAsync(commandDefinition); } - public SqlMapper.GridReader GetMultiple( + public SqlMapper.GridReader GetMultiple( Query[] queries, IDbTransaction transaction = null, int? timeout = null ) { - var compiled = this.Compiler.Compile(queries); + var compiled = Compiler.Compile(queries); - return this.Connection.QueryMultiple( + return Connection.QueryMultiple( compiled.Sql, compiled.NamedBindings, transaction, - timeout ?? this.QueryTimeout + timeout ?? QueryTimeout ); } - public async Task GetMultipleAsync( + public async Task GetMultipleAsync( Query[] queries, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - var compiled = this.Compiler.Compile(queries); + var compiled = Compiler.Compile(queries); var commandDefinition = new CommandDefinition( commandText: compiled.Sql, parameters: compiled.NamedBindings, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - return await this.Connection.QueryMultipleAsync(commandDefinition); + return await Connection.QueryMultipleAsync(commandDefinition); } public IEnumerable> Get( @@ -306,7 +306,7 @@ public IEnumerable> Get( ) { - var multi = this.GetMultiple( + var multi = GetMultiple( queries, transaction, timeout @@ -328,7 +328,7 @@ public async Task>> GetAsync( CancellationToken cancellationToken = default ) { - var multi = await this.GetMultipleAsync( + var multi = await GetMultipleAsync( queries, transaction, timeout, @@ -351,7 +351,7 @@ public async Task>> GetAsync( public bool Exists(Query query, IDbTransaction transaction = null, int? timeout = null) { var clone = query.Clone() - .ClearComponent("select") + .RemoveComponent("select") .SelectRaw("1 as [Exists]") .Limit(1); @@ -363,7 +363,7 @@ public bool Exists(Query query, IDbTransaction transaction = null, int? timeout public async Task ExistsAsync(Query query, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { var clone = query.Clone() - .ClearComponent("select") + .RemoveComponent("select") .SelectRaw("1 as [Exists]") .Limit(1); @@ -380,7 +380,7 @@ public T Aggregate( int? timeout = null ) { - return this.ExecuteScalar(query.AsAggregate(aggregateOperation, columns), transaction, timeout ?? this.QueryTimeout); + return ExecuteScalar(query.AsAggregate(aggregateOperation, columns), transaction, timeout ?? QueryTimeout); } public async Task AggregateAsync( @@ -392,7 +392,7 @@ public async Task AggregateAsync( CancellationToken cancellationToken = default ) { - return await this.ExecuteScalarAsync( + return await ExecuteScalarAsync( query.AsAggregate(aggregateOperation, columns), transaction, timeout, @@ -402,7 +402,7 @@ public async Task AggregateAsync( public T Count(Query query, string[] columns = null, IDbTransaction transaction = null, int? timeout = null) { - return this.ExecuteScalar( + return ExecuteScalar( query.AsCount(columns), transaction, timeout @@ -411,47 +411,47 @@ public T Count(Query query, string[] columns = null, IDbTransaction transacti public async Task CountAsync(Query query, string[] columns = null, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - return await this.ExecuteScalarAsync(query.AsCount(columns), transaction, timeout, cancellationToken); + return await ExecuteScalarAsync(query.AsCount(columns), transaction, timeout, cancellationToken); } public T Average(Query query, string column, IDbTransaction transaction = null, int? timeout = null) { - return this.Aggregate(query, "avg", new[] { column }); + return Aggregate(query, "avg", new[] { column }); } public async Task AverageAsync(Query query, string column, CancellationToken cancellationToken = default) { - return await this.AggregateAsync(query, "avg", new[] { column }, cancellationToken: cancellationToken); + return await AggregateAsync(query, "avg", new[] { column }, cancellationToken: cancellationToken); } public T Sum(Query query, string column) { - return this.Aggregate(query, "sum", new[] { column }); + return Aggregate(query, "sum", new[] { column }); } public async Task SumAsync(Query query, string column, CancellationToken cancellationToken = default) { - return await this.AggregateAsync(query, "sum", new[] { column }, cancellationToken: cancellationToken); + return await AggregateAsync(query, "sum", new[] { column }, cancellationToken: cancellationToken); } public T Min(Query query, string column) { - return this.Aggregate(query, "min", new[] { column }); + return Aggregate(query, "min", new[] { column }); } public async Task MinAsync(Query query, string column, CancellationToken cancellationToken = default) { - return await this.AggregateAsync(query, "min", new[] { column }, cancellationToken: cancellationToken); + return await AggregateAsync(query, "min", new[] { column }, cancellationToken: cancellationToken); } public T Max(Query query, string column) { - return this.Aggregate(query, "max", new[] { column }); + return Aggregate(query, "max", new[] { column }); } public async Task MaxAsync(Query query, string column, CancellationToken cancellationToken = default) { - return await this.AggregateAsync(query, "max", new[] { column }, cancellationToken: cancellationToken); + return await AggregateAsync(query, "max", new[] { column }, cancellationToken: cancellationToken); } public PaginationResult Paginate(Query query, int page, int perPage = 25, IDbTransaction transaction = null, int? timeout = null) @@ -531,7 +531,7 @@ public void Chunk( IDbTransaction transaction = null, int? timeout = null) { - var result = this.Paginate(query, 1, chunkSize, transaction, timeout); + var result = Paginate(query, 1, chunkSize, transaction, timeout); if (!func(result.List, 1)) { @@ -557,7 +557,7 @@ public async Task ChunkAsync( CancellationToken cancellationToken = default ) { - var result = await this.PaginateAsync(query, 1, chunkSize, transaction, cancellationToken: cancellationToken); + var result = await PaginateAsync(query, 1, chunkSize, transaction, cancellationToken: cancellationToken); if (!func(result.List, 1)) { @@ -576,7 +576,7 @@ public async Task ChunkAsync( public void Chunk(Query query, int chunkSize, Action, int> action, IDbTransaction transaction = null, int? timeout = null) { - var result = this.Paginate(query, 1, chunkSize, transaction, timeout); + var result = Paginate(query, 1, chunkSize, transaction, timeout); action(result.List, 1); @@ -596,7 +596,7 @@ public async Task ChunkAsync( CancellationToken cancellationToken = default ) { - var result = await this.PaginateAsync(query, 1, chunkSize, transaction, timeout, cancellationToken); + var result = await PaginateAsync(query, 1, chunkSize, transaction, timeout, cancellationToken); action(result.List, 1); @@ -609,11 +609,11 @@ public async Task ChunkAsync( public IEnumerable Select(string sql, object param = null, IDbTransaction transaction = null, int? timeout = null) { - return this.Connection.Query( + return Connection.Query( sql, param, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout + commandTimeout: timeout ?? QueryTimeout ); } @@ -623,25 +623,25 @@ public async Task> SelectAsync(string sql, object param = null commandText: sql, parameters: param, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - return await this.Connection.QueryAsync(commandDefinition); + return await Connection.QueryAsync(commandDefinition); } public IEnumerable Select(string sql, object param = null, IDbTransaction transaction = null, int? timeout = null) { - return this.Select(sql, param, transaction, timeout); + return Select(sql, param, transaction, timeout); } public async Task> SelectAsync(string sql, object param = null, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) { - return await this.SelectAsync(sql, param, transaction, timeout, cancellationToken); + return await SelectAsync(sql, param, transaction, timeout, cancellationToken); } public int Statement(string sql, object param = null, IDbTransaction transaction = null, int? timeout = null) { - return this.Connection.Execute(sql, param, transaction: transaction, commandTimeout: timeout ?? this.QueryTimeout); + return Connection.Execute(sql, param, transaction: transaction, commandTimeout: timeout ?? QueryTimeout); } public async Task StatementAsync(string sql, object param = null, IDbTransaction transaction = null, int? timeout = null, CancellationToken cancellationToken = default) @@ -650,12 +650,12 @@ public async Task StatementAsync(string sql, object param = null, IDbTransa commandText: sql, parameters: param, transaction: transaction, - commandTimeout: timeout ?? this.QueryTimeout, + commandTimeout: timeout ?? QueryTimeout, cancellationToken: cancellationToken); - return await this.Connection.ExecuteAsync(commandDefinition); + return await Connection.ExecuteAsync(commandDefinition); } - private static IEnumerable handleIncludes(Query query, IEnumerable result) + private static IEnumerable HandleIncludes(Query query, List result) { if (!result.Any()) { @@ -692,7 +692,7 @@ private static IEnumerable handleIncludes(Query query, IEnumerable resu throw new InvalidOperationException($"Cannot guess the foreign key for the included relation '{include.Name}'"); } - var table = fromTable.Alias ?? fromTable.Table; + var table = fromTable.Alias; include.ForeignKey = table.Singularize(false) + "Id"; } @@ -717,17 +717,14 @@ private static IEnumerable handleIncludes(Query query, IEnumerable resu foreach (var item in dynamicResult) { - var localValue = item[include.LocalKey].ToString(); - item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : new List>(); + var localValue = item[include.LocalKey].ToString()!; + item[include.Name] = children.TryGetValue(localValue, out var child) ? child : new List>(); } continue; } - if (include.ForeignKey == null) - { - include.ForeignKey = include.Name + "Id"; - } + include.ForeignKey ??= include.Name + "Id"; var foreignIds = dynamicResult .Where(x => x[include.ForeignKey] != null) @@ -750,14 +747,14 @@ private static IEnumerable handleIncludes(Query query, IEnumerable resu foreach (var item in dynamicResult) { var foreignValue = item[include.ForeignKey]?.ToString(); - item[include.Name] = foreignValue != null && related.ContainsKey(foreignValue) ? related[foreignValue] : null; + item[include.Name] = foreignValue != null && related.TryGetValue(foreignValue, out var value) ? value : null; } } return dynamicResult.Cast(); } - private static async Task> handleIncludesAsync(Query query, IEnumerable result, CancellationToken cancellationToken = default) + private static async Task> HandleIncludesAsync(Query query, List result, CancellationToken cancellationToken = default) { if (!result.Any()) { @@ -793,7 +790,7 @@ private static async Task> handleIncludesAsync(Query query, IE throw new InvalidOperationException($"Cannot guess the foreign key for the included relation '{include.Name}'"); } - var table = fromTable.Alias ?? fromTable.Table; + var table = fromTable.Alias; include.ForeignKey = table.Singularize(false) + "Id"; } @@ -815,8 +812,8 @@ private static async Task> handleIncludesAsync(Query query, IE foreach (var item in dynamicResult) { - var localValue = item[include.LocalKey].ToString(); - item[include.Name] = children.ContainsKey(localValue) ? children[localValue] : new List>(); + var localValue = item[include.LocalKey].ToString()!; + item[include.Name] = children.TryGetValue(localValue, out var child) ? child : new List>(); } continue; @@ -844,7 +841,7 @@ private static async Task> handleIncludesAsync(Query query, IE foreach (var item in dynamicResult) { var foreignValue = item[include.ForeignKey]?.ToString(); - item[include.Name] = foreignValue != null && related.ContainsKey(foreignValue) ? related[foreignValue] : null; + item[include.Name] = foreignValue != null && related.TryGetValue(foreignValue, out var value) ? value : null; } } @@ -858,16 +855,16 @@ private static async Task> handleIncludesAsync(Query query, IE /// internal SqlResult CompileAndLog(Query query) { - var compiled = this.Compiler.Compile(query); + var compiled = Compiler.Compile(query); - this.Logger(compiled); + Logger(compiled); return compiled; } protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) { @@ -878,7 +875,7 @@ protected virtual void Dispose(bool disposing) // TODO: set large fields to null Connection = null; Compiler = null; - disposedValue = true; + _disposedValue = true; } } diff --git a/SqlKata.Execution/SqlKata.Execution.csproj b/SqlKata.Execution/SqlKata.Execution.csproj index f6a7ff1e..ac2fefe0 100644 --- a/SqlKata.Execution/SqlKata.Execution.csproj +++ b/SqlKata.Execution/SqlKata.Execution.csproj @@ -4,8 +4,7 @@ Adds the execution capabilities for SqlKata Ahmad Moussawi Copyright (c) 2017 Ahmad Moussawi - netstandard2.0 - SqlKata + net7.0 SqlKata.Execution @@ -32,7 +31,7 @@ - - + + diff --git a/SqlKata.Execution/XQuery.cs b/SqlKata.Execution/XQuery.cs index 3cb5f14f..d18711d2 100644 --- a/SqlKata.Execution/XQuery.cs +++ b/SqlKata.Execution/XQuery.cs @@ -1,6 +1,5 @@ using System; using System.Data; -using System.Linq; using SqlKata.Compilers; namespace SqlKata.Execution @@ -9,28 +8,27 @@ public class XQuery : Query { public IDbConnection Connection { get; set; } public Compiler Compiler { get; set; } - public Action Logger = result => { }; + public Action Logger = _ => { }; public QueryFactory QueryFactory { get; set; } public XQuery(IDbConnection connection, Compiler compiler) { - this.QueryFactory = new QueryFactory(connection, compiler); - this.Connection = connection; - this.Compiler = compiler; + QueryFactory = new QueryFactory(connection, compiler); + Connection = connection; + Compiler = compiler; } public override Query Clone() { + var query = new XQuery(QueryFactory.Connection, QueryFactory.Compiler); - var query = new XQuery(this.QueryFactory.Connection, this.QueryFactory.Compiler); - - if (this.QueryFactory?.QueryTimeout != null) + if (QueryFactory?.QueryTimeout != null) { - query.QueryFactory.QueryTimeout = this.QueryFactory?.QueryTimeout ?? 30; + query.QueryFactory.QueryTimeout = QueryFactory?.QueryTimeout ?? 30; } - query.Clauses = this.Clauses.Select(x => x.Clone()).ToList(); - query.Logger = this.Logger; + query.Components = Components.Clone(); + query.Logger = Logger; query.QueryAlias = QueryAlias; query.IsDistinct = IsDistinct; diff --git a/sqlkata.sln.DotSettings b/sqlkata.sln.DotSettings new file mode 100644 index 00000000..20a0596b --- /dev/null +++ b/sqlkata.sln.DotSettings @@ -0,0 +1,11 @@ + + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/sqlkata.v3.ncrunchsolution b/sqlkata.v3.ncrunchsolution new file mode 100644 index 00000000..10420ac9 --- /dev/null +++ b/sqlkata.v3.ncrunchsolution @@ -0,0 +1,6 @@ + + + True + True + + \ No newline at end of file