test: added test for parsing multiple joins and different join type
This commit is contained in:
parent
2f7d996485
commit
bc644c3640
@ -433,8 +433,6 @@ func parseJoins(p *parser) error {
|
||||
return t.Type == sqllexer.KEYWORD && strings.ToUpper(t.Value) == "ON"
|
||||
})
|
||||
|
||||
fmt.Printf("Found ON at '%d'\n", foundOnTokenIndex)
|
||||
|
||||
if foundOnTokenIndex < 0 {
|
||||
selectQuery.Joins = append(selectQuery.Joins, workingJoin)
|
||||
continue
|
||||
@ -447,8 +445,6 @@ func parseJoins(p *parser) error {
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("Currently at '%d', reading '%s'\n", i, t.Value)
|
||||
|
||||
if t.Type == sqllexer.IDENT {
|
||||
if workingOn.Key == "" {
|
||||
workingOn.Key = t.Value
|
||||
@ -467,8 +463,6 @@ func parseJoins(p *parser) error {
|
||||
|
||||
if workingOn.Key != "" && workingOn.Operator != "" && workingOn.Value != "" {
|
||||
workingJoin.Ons = append(workingJoin.Ons, workingOn)
|
||||
fmt.Println("Adding ON to workingJoin")
|
||||
fmt.Println(workingOn)
|
||||
workingOn = Conditional{}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func TestParseSelectStatement_StateMachine(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "SELECT ProductID, ProductName, CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID; ",
|
||||
input: "SELECT ProductID, ProductName, CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID AND Products.SupplierID = Categories.SupplierID LEFT JOIN Stores ON Products.StoreID = Stores.ID ;",
|
||||
expected: &Select{
|
||||
Type: SELECT,
|
||||
Table: Table{Name: "Products"},
|
||||
@ -175,6 +175,28 @@ func TestParseSelectStatement_StateMachine(t *testing.T) {
|
||||
Operator: "=",
|
||||
Value: "Categories.CategoryID",
|
||||
},
|
||||
{
|
||||
Key: "Products.SupplierID",
|
||||
Operator: "=",
|
||||
Value: "Categories.SupplierID",
|
||||
Extension: "AND",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: LEFT,
|
||||
MainTable: Table{
|
||||
Name: "Products",
|
||||
},
|
||||
JoiningTable: Table{
|
||||
Name: "Stores",
|
||||
},
|
||||
Ons: []Conditional{
|
||||
{
|
||||
Key: "Products.StoreID",
|
||||
Operator: "=",
|
||||
Value: "Stores.ID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user