Simplify API.

pull/17/head
Todd Persen 2013-10-08 12:56:59 -04:00
parent 6005989c27
commit 10f571263c
2 changed files with 21 additions and 5 deletions

View File

@ -53,6 +53,12 @@ type Query struct {
groupByClause GroupByClause
Limit int
}
func (self *WhereCondition) GetBoolExpression() (*BoolExpression, bool) {
if self.isBooleanExpression {
return self.Left.(*BoolExpression), true
}
return nil, false
}
func (self *Query) GetColumnNames() []*Value {
if self.ColumnNames != nil {
@ -67,6 +73,13 @@ func (self *Query) GetFromClause() *Value {
return GetValue(self.q.f)
}
func (self *Expression) GetSimpleValue() (*Value, bool) {
if self.Operation == '\000' {
return self.Left, true
}
return nil, false
}
func GetValueArray(array *C.value_array) []*Value {
if array == nil {
return nil

View File

@ -32,15 +32,18 @@ func (self *QueryParserSuite) TestParseBasicSelectQuery(c *C) {
w := q.GetWhereCondition()
c.Assert(q.GetFromClause().Name, Equals, "t")
boolExpression := w.Left.(*BoolExpression)
boolExpression, ok := w.GetBoolExpression()
c.Assert(ok, Equals, true)
leftExpression := boolExpression.Left
rightExpression := boolExpression.Right
leftValue := leftExpression.Left.Name
rightValue := rightExpression.Left.Name
c.Assert(leftValue, Equals, "c")
leftValue, ok := leftExpression.GetSimpleValue() // simple value is an expression with one value, e.g. it doesn't combine value using arithmetic operations
rightValue, ok := rightExpression.GetSimpleValue()
c.Assert(leftValue.Name, Equals, "c")
c.Assert(boolExpression.Operation, Equals, "==")
c.Assert(rightValue, Equals, "5")
c.Assert(rightValue.Name, Equals, "5")
}
func (self *QueryParserSuite) TestParseSelectWithoutWhereClause(c *C) {