Beispiel #1
0
func shouldBeNumericOrDate(val parser.NodeExpr) bool {
	// if reflect.TypeOf(val) == reflect.TypeOf(new(parser.NodeNumber)) {
	if val.Operator() == lexical.T_NUMERIC {
		return true
	}

	if val.Operator() == lexical.T_LITERAL {
		date := parser.ExtractDate(val.(*parser.NodeLiteral).Value())
		if date != nil {
			return true
		}
	}

	return false
}
Beispiel #2
0
func (v *SemanticalVisitor) VisitExpr(n parser.NodeExpr) error {
	if n == nil {
		return nil
	}

	switch n.Operator() {
	case lexical.T_GREATER:
		g := n.(*parser.NodeGreater)
		return v.VisitGreater(g)
	case lexical.T_SMALLER:
		g := n.(*parser.NodeSmaller)
		return v.VisitSmaller(g)
	case lexical.T_IN:
		g := n.(*parser.NodeIn)
		return v.VisitIn(g)
	}

	return nil
}
Beispiel #3
0
func orderTable(rows []tableRow, order *parser.NodeOrder) []tableRow {
	if order == nil {
		return rows
	}
	// We will use parser.NodeGreater.Assertion(A, B) to know if
	// A > B and then switch their positions.
	// Unfortunaly, we will use bubble sort, that is O(n²)
	// @todo change to quick or other better sort.
	var orderer parser.NodeExpr
	if order.Asc {
		orderer = new(parser.NodeGreater)
	} else {
		orderer = new(parser.NodeSmaller)
	}

	field := order.Field
	key := ""
	for key, _ = range builder.tables {
		break
	}
	table := key
	err := builder.UseFieldFromTable(field, table)
	if err != nil {
		panic(err)
	}

	for i, row := range rows {
		for j, rowWalk := range rows {
			if orderer.Assertion(fmt.Sprintf("%v", rowWalk[field]), fmt.Sprintf("%v", row[field])) {
				aux := rows[j]
				rows[j] = rows[i]
				rows[i] = aux
			}
		}
	}

	return rows
}