-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from mk3008/551-unparsable-table-alias-for-ex…
…tracted-columns-year-month Handle Extract function units (e.g., YEAR, MONTH) as reserved keywords.
- Loading branch information
Showing
5 changed files
with
89 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Xunit.Abstractions; | ||
|
||
namespace Carbunql.Fluent.Test; | ||
|
||
public class FluentWhereTest | ||
{ | ||
private readonly QueryCommandMonitor Monitor; | ||
|
||
public FluentWhereTest(ITestOutputHelper output) | ||
{ | ||
Monitor = new QueryCommandMonitor(output); | ||
} | ||
|
||
[Fact] | ||
public void EqualTest() | ||
{ | ||
var sq = new SelectQuery(""" | ||
select | ||
a.id | ||
, a.value | ||
from | ||
table_a a | ||
""") | ||
.Equal("id", 1); | ||
; | ||
|
||
Monitor.Log(sq); | ||
|
||
var expect = """ | ||
SELECT | ||
a.id, | ||
a.value | ||
FROM | ||
table_a AS a | ||
WHERE | ||
a.id = 1 | ||
"""; | ||
|
||
Assert.Equal(expect, sq.ToText()); | ||
} | ||
|
||
[Fact] | ||
public void EqualTest_ExtractYear() | ||
{ | ||
var sq = new SelectQuery(""" | ||
SELECT | ||
o.order_id, | ||
c.customer_name, | ||
o.order_date, | ||
EXTRACT(YEAR FROM o.order_date) AS order_year, | ||
EXTRACT(MONTH FROM o.order_date) AS order_month, | ||
o.amount | ||
FROM | ||
orders o | ||
JOIN | ||
customers c ON o.customer_id = c.customer_id | ||
""") | ||
.Equal("order_year", 1); | ||
; | ||
|
||
Monitor.Log(sq); | ||
|
||
var expect = """ | ||
SELECT | ||
o.order_id, | ||
c.customer_name, | ||
o.order_date, | ||
EXTRACT(YEAR FROM o.order_date) AS order_year, | ||
EXTRACT(MONTH FROM o.order_date) AS order_month, | ||
o.amount | ||
FROM | ||
orders AS o | ||
JOIN customers AS c ON o.customer_id = c.customer_id | ||
WHERE | ||
EXTRACT(YEAR FROM o.order_date) = 1 | ||
"""; | ||
|
||
Assert.Equal(expect, sq.ToText()); | ||
} | ||
} |