Example #1
0
func (v *RuntimeVisitor) VisitSelect(n *parser.NodeSelect) error {
	if builder.isProxyTable(n.Tables[0]) {
		proxyTableName := n.Tables[0]
		// refactor tree
		proxy := builder.proxyTables[proxyTableName]
		if !n.WildCard {
			err := testAllFieldsFromTable(n.Fields, proxyTableName)
			if err != nil {
				return err
			}

		} else {
			n.Fields = builder.possibleTables[proxyTableName]
			n.WildCard = false
		}

		n.Tables[0] = proxy.table
		var from, to string
		for from, to = range proxy.fields {
			break
		}

		oldWhere := n.Where
		where := new(parser.NodeAnd)
		condition := new(parser.NodeEqual)
		conditionL := new(parser.NodeId)
		conditionL.SetValue(from)
		conditionR := new(parser.NodeLiteral)
		conditionR.SetValue(to)
		condition.SetLeftValue(conditionL)
		condition.SetRightValue(conditionR)

		where.SetLeftValue(condition)
		where.SetRightValue(oldWhere)

		n.Where = where
	}

	table := n.Tables[0]

	var err error
	err = builder.WithTable(table, table)
	if err != nil {
		return err
	}
	return testAllFieldsFromTable(n.Fields, table)
	// Why not visit expression right now ?
	// Because we will, at first, discover the current object
}
Example #2
0
func (v *RuntimeVisitor) VisitEqual(n *parser.NodeEqual) error {
	lvalue := n.LeftValue().(*parser.NodeId).Value()
	rvalue := n.RightValue().(*parser.NodeLiteral).Value()
	boolRegister = n.Assertion(metadata(lvalue), rvalue)

	return nil
}