static inline void _ResolveProperty(
    WQLOperand& op,
    const WQLPropertySource* source)
{
    //
    // Resolve the operand: if it's a property name, look up its value:
    //

    if (op.getType() == WQLOperand::PROPERTY_NAME)
    {
        const CIMName& propertyName = op.getPropertyName();

        if (!source->getValue(propertyName, op))
            op = WQLOperand();
    }
}
예제 #2
0
static bool _Evaluate(
const WQLOperand& lhs, 
const WQLOperand& rhs, 
WQLOperation op)
{
	switch (lhs.getType())
	{
		case WQLOperand::NULL_VALUE:
		{
			// return true if the op is WQL_EQ and the rhs is NULL
			// also if op is WQL_NE and rhs is not NULL
			return !(op == WQL_EQ) ^ (rhs.getType() == WQLOperand::NULL_VALUE);
			break;
		}
		case WQLOperand::INTEGER_VALUE:
		{
			return _Compare(
			lhs.getIntegerValue(),
			rhs.getIntegerValue(),
			op);
		}
		case WQLOperand::DOUBLE_VALUE:
		{
			return _Compare(
			lhs.getDoubleValue(),
			rhs.getDoubleValue(),
			op);
		}
		case WQLOperand::BOOLEAN_VALUE:
		{
			return _Compare(
			lhs.getBooleanValue(),
			rhs.getBooleanValue(),
			op);
		}
		case WQLOperand::STRING_VALUE:
		{
			return _Compare(
			lhs.getStringValue(),
			rhs.getStringValue(),
			op);
		}
		default:
		OW_ASSERT(0);
	}
	return false;
}
예제 #3
0
String WQL2String(const WQLOperand &o)
{
    switch( o.getType() )
    {
        case WQLOperand::PROPERTY_NAME:
            return o.getPropertyName();
        case WQLOperand::STRING_VALUE:
            return o.getStringValue();
        case WQLOperand::INTEGER_VALUE:
            return Formatter::format("$0",o.getIntegerValue());
        case WQLOperand::DOUBLE_VALUE:
            return Formatter::format("$0",o.getDoubleValue());
        case WQLOperand::BOOLEAN_VALUE:
            return Formatter::format("$0",o.getBooleanValue());
        default: ;
    }
    return "NULL_VALUE";
}
예제 #4
0
static bool operator==(const WQLOperand& x, const WQLOperand& y)
{
    if( x.getType()==y.getType() )
    {
        switch( x.getType() )
        {
            case WQLOperand::PROPERTY_NAME:
                return x.getPropertyName()==y.getPropertyName();
            case WQLOperand::INTEGER_VALUE:
                return x.getIntegerValue()==y.getIntegerValue();
            case WQLOperand::DOUBLE_VALUE:
                return x.getDoubleValue()==y.getDoubleValue();
            case WQLOperand::BOOLEAN_VALUE:
                return x.getBooleanValue()==y.getBooleanValue();
            case WQLOperand::STRING_VALUE:
                return x.getStringValue()==y.getStringValue();
            case WQLOperand::NULL_VALUE: 
                return true;
        }
    }
    return false;
}
예제 #5
0
void CMPI_Wql2Dnf::_buildEvalHeap(const WQLSelectStatement * wqs)
{
    PEG_METHOD_ENTER(
        TRC_CMPIPROVIDERINTERFACE,
        "CMPI_Wql2Dnf::_buildEvalHeap()");
    //WQLSelectStatement* that = (WQLSelectStatement*)wqs;

    WQLSelectStatementRep* wqsrep = wqs->_rep;

    WQLOperand dummy;
    dummy.clear();
    Stack<CMPI_stack_el> stack;

    // Counter for Operands

    Uint32 j = 0;

    //cerr << "Build eval heap\n";

    for( Uint32 i = 0, n = wqsrep->_operations.size(); i < n; i++ )
    {
        WQLOperation op = wqsrep->_operations[i];

        switch( op )
        {
            case WQL_OR:
            case WQL_AND:
                {
                    PEGASUS_ASSERT(stack.size() >= 2);

                    CMPI_stack_el op1 = stack.top();
                    stack.pop();

                    CMPI_stack_el op2 = stack.top();

                    // generate Eval expression
                    eval_heap.append(CMPI_eval_el(
                                         0, op , op1.opn,
                                         op1.is_terminal,op2.opn ,
                                         op2.is_terminal));

                    stack.top() = CMPI_stack_el(eval_heap.size()-1, false);

                    break;
                }

            case WQL_NOT:
            case WQL_IS_FALSE:
            case WQL_IS_NOT_TRUE:
                {
                    PEGASUS_ASSERT(stack.size() >= 1);

                    CMPI_stack_el op1 = stack.top();

                    // generate Eval expression
                    eval_heap.append(CMPI_eval_el(
                                         0, op , op1.opn, 
                                         op1.is_terminal,-1, true));

                    stack.top() = CMPI_stack_el(eval_heap.size()-1, false);

                    break;
                }

            case WQL_EQ:
            case WQL_NE:
            case WQL_LT:
            case WQL_LE:
            case WQL_GT:
            case WQL_GE:
                {
                    PEGASUS_ASSERT(wqsrep->_operands.size() >= 2);

                    WQLOperand lhs = wqsrep->_operands[j++];

                    WQLOperand rhs = wqsrep->_operands[j++];

                    terminal_heap.push(term_el_WQL(false, op, lhs, rhs));

                    stack.push(CMPI_stack_el(terminal_heap.size()-1, true));

                    break;
                }

            case WQL_IS_TRUE:
            case WQL_IS_NOT_FALSE:
                {
                    PEGASUS_ASSERT(stack.size() >= 1);
                    break;
                }

            case WQL_IS_NULL:
                {
                    PEGASUS_ASSERT(wqsrep->_operands.size() >= 1);
                    WQLOperand operand = wqsrep->_operands[j++];

                    terminal_heap.push(
                        term_el_WQL(false, WQL_EQ, operand, dummy));

                    stack.push(CMPI_stack_el(terminal_heap.size()-1, true));

                    break;
                }

            case WQL_IS_NOT_NULL:
                {
                    PEGASUS_ASSERT(wqsrep->_operands.size() >= 1);
                    WQLOperand operand = wqsrep->_operands[j++];

                    terminal_heap.push(
                        term_el_WQL(false, WQL_NE, operand, dummy));

                    stack.push(CMPI_stack_el(terminal_heap.size()-1, true));

                    break;
                }
        }
    }

    PEGASUS_ASSERT(stack.size() == 1);
    PEG_METHOD_EXIT();
}
static Boolean _Evaluate(
    const WQLOperand& lhs,
    const WQLOperand& rhs,
    WQLOperation op)
{
    switch (lhs.getType())
    {
        case WQLOperand::NULL_VALUE:
        {
#ifdef PEGASUS_SNIA_EXTENSIONS
            return (rhs.getType() == WQLOperand::NULL_VALUE);
#else
            // This cannot happen since expressions of the form
            // OPERAND OPERATOR NULL are converted to unary form.
            // For example: "count IS NULL" is treated as a unary
            // operation in which IS_NULL is the unary operation
            // and count is the the unary operand.

            PEGASUS_ASSERT(0);
            break;
#endif
        }

        case WQLOperand::INTEGER_VALUE:
        {
            return _Compare(
            lhs.getIntegerValue(),
            rhs.getIntegerValue(),
            op);
        }

        case WQLOperand::DOUBLE_VALUE:
        {
            return _Compare(
            lhs.getDoubleValue(),
            rhs.getDoubleValue(),
            op);
        }

        case WQLOperand::BOOLEAN_VALUE:
        {
            return _Compare(
            lhs.getBooleanValue(),
            rhs.getBooleanValue(),
            op);
        }

        case WQLOperand::STRING_VALUE:
        {
            if(op != WQL_LIKE) {
                return _Compare(
                lhs.getStringValue(),
                rhs.getStringValue(),
                op);
            }
            else {
                CString lhsstr = lhs.getStringValue().getCString();
                CString rhsstr = rhs.getStringValue().getCString();
                const char* lhscs = (const char *)lhsstr;
                const char* rhscs = (const char *)rhsstr;
                return _LikeEvaluate((const char *)lhsstr, (const char *)rhsstr);
            }
        }

        default:
            PEGASUS_ASSERT(0);
    }

    return false;
}