Don't panic on invalid where conditions, e.g. where 1

pull/215/head
John Shahid 2014-01-28 16:09:22 -05:00
parent 4abec25949
commit 982873cf3d
2 changed files with 17 additions and 0 deletions

View File

@ -178,6 +178,14 @@ func (self *QueryParserSuite) TestParseDeleteQuery(c *C) {
c.Assert(q.GetEndTime(), Equals, endTime)
}
func (self *QueryParserSuite) TestInvalidWhereClause(c *C) {
_, err := ParseQuery("delete from foo where 1;")
c.Assert(err, NotNil)
_, err = ParseQuery("select * from foo where is_uppercase(name);")
c.Assert(err, IsNil)
}
func (self *QueryParserSuite) TestParseWithUnderscore(c *C) {
queryString := "select _value, time, sequence_number from foo"
query, err := ParseSelectQuery(queryString)

View File

@ -375,6 +375,15 @@ func getTime(condition *WhereCondition, isParsingStartTime bool) (*WhereConditio
}
if expr, ok := condition.GetBoolExpression(); ok {
switch expr.Type {
case ValueDuration, ValueFloat, ValueInt, ValueString, ValueWildcard:
return nil, ZERO_TIME, fmt.Errorf("Invalid where expression: %v", expr)
}
if expr.Type == ValueFunctionCall {
return condition, ZERO_TIME, nil
}
leftValue := expr.Elems[0]
isTimeOnLeft := leftValue.Type != ValueExpression && leftValue.Type != ValueFunctionCall
rightValue := expr.Elems[1]