Skip to content

Commit

Permalink
Removed sql output ternary tests, made sure it was clear that sql doe…
Browse files Browse the repository at this point in the history
…s not yet support them. Fixed membership operator test expectations to be less mysqlley
  • Loading branch information
Knetic committed Aug 17, 2016
1 parent c2f8b59 commit 4f9cbb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
29 changes: 3 additions & 26 deletions EvaluableExpression_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,9 @@ func (this EvaluableExpression) findNextSQLString(stream *tokenStream, transacti

ret = fmt.Sprintf("COALESCE(%v, %v)", left, right)
case TERNARY_TRUE:

left := transactions.rollback()
right, err := this.findNextSQLString(stream, transactions)
if err != nil {
return "", err
}

// ternaries are weird, in that we handle the else case slightly differently than the half case.

if !stream.hasNext() {
break
}

nextToken := stream.next()
if nextToken.Kind == TERNARY {

last, err := this.findNextSQLString(stream, transactions)
if err != nil {
return "", err
}

ret = fmt.Sprintf("IF(%s, %s, %s)", left, right, last)
break
}

ret = fmt.Sprintf("IF(%s, %s)", left, right)
fallthrough
case TERNARY_FALSE:
return "", errors.New("Ternary operators are unsupported in SQL output")
}
case PREFIX:
switch PREFIX_SYMBOLS[token.Value.(string)] {
Expand Down
6 changes: 4 additions & 2 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,16 @@ func TestSQLSerialization(test *testing.T) {

Name: "Membership operator",
Input: "foo IN (1, 2, 3)",
Expected: "FIND_IN_SET([foo], '1,2,3') > 0 ",
Expected: "[foo] in ( 1 , 2 , 3 )",
},
QueryTest{

Name: "Null coalescence",
Input: "foo ?? bar",
Expected: "COALESCE([foo], [bar])",
},
/*
// Ternaries don't work yet, because the outputter is not yet sophisticated enough to produce them.
QueryTest{
Name: "Full ternary",
Expand All @@ -185,7 +187,7 @@ func TestSQLSerialization(test *testing.T) {
Name: "Half ternary with implicit bool",
Input: "[foo] ? 1",
Expected: "IF([foo] = 0, 1)",
},
},*/
QueryTest{

Name: "Regex equals",
Expand Down

0 comments on commit 4f9cbb7

Please sign in to comment.