Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public FirebirdLimitTests()
public void NoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -26,7 +26,7 @@ public void NoLimitNorOffset()
public void LimitOnly()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -35,7 +35,7 @@ public void LimitOnly()
public void OffsetOnly()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -44,7 +44,7 @@ public void OffsetOnly()
public void LimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("ROWS ? TO ?", compiler.CompileLimit(ctx));
Assert.Equal(21, ctx.Bindings[0]);
Expand Down
12 changes: 7 additions & 5 deletions QueryBuilder.Tests/HelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HelperTests
[InlineData(" ")]
public void ItShouldKeepItAsIs(string input)
{
var output = Helper.ReplaceAll(input, "any", x => x + "");
var output = Helper.ReplaceAll(input, "any", "\\", x => x + "");

Assert.Equal(input, output);
}
Expand All @@ -28,7 +28,7 @@ public void ItShouldKeepItAsIs(string input)
[InlineData(" ? ? hello", " @ @ hello")]
public void ReplaceOnTheBegining(string input, string expected)
{
var output = Helper.ReplaceAll(input, "?", x => "@");
var output = Helper.ReplaceAll(input, "?", "\\", x => "@");
Assert.Equal(expected, output);
}

Expand All @@ -39,19 +39,21 @@ public void ReplaceOnTheBegining(string input, string expected)
[InlineData("hello ? ?? ? ", "hello @ @@ @ ")]
public void ReplaceOnTheEnd(string input, string expected)
{
var output = Helper.ReplaceAll(input, "?", x => "@");
var output = Helper.ReplaceAll(input, "?", "\\", x => "@");
Assert.Equal(expected, output);
}

[Theory]
[InlineData("hel\\?o ??? ", "hel\\?o 012 ")]
[InlineData("hel\\?o ?? \\?", "hel\\?o 01 \\?")]
[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 + "");
var output = Helper.ReplaceAll(input, "?", "\\", x => x + "");
Assert.Equal(expected, output);
}

Expand Down Expand Up @@ -220,7 +222,7 @@ public void ExpandExpression(string input, string expected)
[Fact]
public void ExpandParameters()
{
var expanded = Helper.ExpandParameters("where id = ? or id in (?) or id in (?)", "?", new object[] { 1, new[] { 1, 2 }, new object[] { } });
var expanded = Helper.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);
}
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/MySql/MySqlLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public MySqlLimitTests()
public void WithNoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -26,7 +26,7 @@ public void WithNoLimitNorOffset()
public void WithNoOffset()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx));
Assert.Equal(10, ctx.Bindings[0]);
Expand All @@ -36,7 +36,7 @@ public void WithNoOffset()
public void WithNoLimit()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("LIMIT 18446744073709551615 OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(20, ctx.Bindings[0]);
Expand All @@ -47,7 +47,7 @@ public void WithNoLimit()
public void WithLimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(5, ctx.Bindings[0]);
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/Oracle/OracleLegacyLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void WithNoLimitNorOffset()
{
// Arrange:
var query = new Query(TableName);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act:
compiler.ApplyLegacyLimit(ctx);
Expand All @@ -35,7 +35,7 @@ public void WithNoOffset()
{
// Arrange:
var query = new Query(TableName).Limit(10);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act:
compiler.ApplyLegacyLimit(ctx);
Expand All @@ -51,7 +51,7 @@ public void WithNoLimit()
{
// Arrange:
var query = new Query(TableName).Offset(20);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act:
compiler.ApplyLegacyLimit(ctx);
Expand All @@ -67,7 +67,7 @@ public void WithLimitAndOffset()
{
// Arrange:
var query = new Query(TableName).Limit(5).Offset(20);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act:
compiler.ApplyLegacyLimit(ctx);
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/Oracle/OracleLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void NoLimitNorOffset()
{
// Arrange:
var query = new Query(TableName);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act & Assert:
Assert.Null(compiler.CompileLimit(ctx));
Expand All @@ -32,7 +32,7 @@ public void LimitOnly()
{
// Arrange:
var query = new Query(TableName).Limit(10);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act & Assert:
Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx));
Expand All @@ -46,7 +46,7 @@ public void OffsetOnly()
{
// Arrange:
var query = new Query(TableName).Offset(20);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act & Assert:
Assert.EndsWith("OFFSET ? ROWS", compiler.CompileLimit(ctx));
Expand All @@ -60,7 +60,7 @@ public void LimitAndOffset()
{
// Arrange:
var query = new Query(TableName).Limit(5).Offset(20);
var ctx = new SqlResult { Query = query, RawSql = SqlPlaceholder };
var ctx = new SqlResult("?", "\\") { Query = query, RawSql = SqlPlaceholder };

// Act & Assert:
Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx));
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/PostgreSql/PostgreSqlLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public PostgreSqlLimitTests()
public void WithNoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -26,7 +26,7 @@ public void WithNoLimitNorOffset()
public void WithNoOffset()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx));
Assert.Equal(10, ctx.Bindings[0]);
Expand All @@ -36,7 +36,7 @@ public void WithNoOffset()
public void WithNoLimit()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(20, ctx.Bindings[0]);
Expand All @@ -47,7 +47,7 @@ public void WithNoLimit()
public void WithLimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(5, ctx.Bindings[0]);
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/SqlServer/SqlServerLegacyLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SqlServerLegacyLimitTests()
public void NoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -27,7 +27,7 @@ public void NoLimitNorOffset()
public void LimitOnly()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -36,7 +36,7 @@ public void LimitOnly()
public void OffsetOnly()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -45,7 +45,7 @@ public void OffsetOnly()
public void LimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/SqlServer/SqlServerLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SqlServerLimitTests()
public void NoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -27,7 +27,7 @@ public void NoLimitNorOffset()
public void LimitOnly()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx));
Assert.Equal(2, ctx.Bindings.Count);
Expand All @@ -39,7 +39,7 @@ public void LimitOnly()
public void OffsetOnly()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.EndsWith("OFFSET ? ROWS", compiler.CompileLimit(ctx));

Expand All @@ -51,7 +51,7 @@ public void OffsetOnly()
public void LimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult("?", "\\") {Query = query};

Assert.EndsWith("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", compiler.CompileLimit(ctx));

Expand Down
16 changes: 16 additions & 0 deletions QueryBuilder.Tests/SqlServer/SqlServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public void SqlServerTop()
Assert.Equal("SELECT TOP (@p0) * FROM [table]", result.Sql);
}


[Fact]
public void SqlServerSelectWithParameterPlaceHolder()
{
var query = new Query("table").Select("Column\\?");
var result = compiler.Compile(query);
Assert.Equal("SELECT [Column\\?] FROM [table]", result.Sql);
}

[Fact]
public void SqlServerTopWithDistinct()
{
Expand All @@ -42,6 +51,13 @@ public void OffsetSqlServer_Should_Be_Ignored_If_Zero_Or_Negative(int offset)
Assert.Equal("SELECT * FROM [users]", c.ToString());
}

[Fact]
public void SqlServerSelectWithParameterPlaceHolderEscaped()
{
var query = new Query("table").Select("Column\\?");
var result = compiler.Compile(query);
Assert.Equal("SELECT [Column?] FROM [table]", result.ToString());
}

[Theory()]
[InlineData(1)]
Expand Down
8 changes: 4 additions & 4 deletions QueryBuilder.Tests/Sqlite/SqliteLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SqliteLimitTests()
public void WithNoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult { Query = query };
var ctx = new SqlResult("?", "\\") { Query = query };

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -26,7 +26,7 @@ public void WithNoLimitNorOffset()
public void WithNoOffset()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult { Query = query };
var ctx = new SqlResult("?", "\\") { Query = query };

Assert.Equal("LIMIT ?", compiler.CompileLimit(ctx));
Assert.Equal(10, ctx.Bindings[0]);
Expand All @@ -36,7 +36,7 @@ public void WithNoOffset()
public void WithNoLimit()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult { Query = query };
var ctx = new SqlResult("?", "\\") { Query = query };

Assert.Equal("LIMIT -1 OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(20, ctx.Bindings[0]);
Expand All @@ -47,7 +47,7 @@ public void WithNoLimit()
public void WithLimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult { Query = query };
var ctx = new SqlResult("?", "\\") { Query = query };

Assert.Equal("LIMIT ? OFFSET ?", compiler.CompileLimit(ctx));
Assert.Equal(5, ctx.Bindings[0]);
Expand Down
Loading