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();
    }
}
PEGASUS_NAMESPACE_BEGIN

Boolean WQLInstancePropertySource::getValue(
	const CIMName& propertyName, 
	WQLOperand& value) const
{
   unsigned int pos=ci.findProperty(propertyName);
   if (pos==PEG_NOT_FOUND) return false;
    
   CIMValue val=ci.getProperty(pos).getValue();
   CIMType type=val.getType();
   
   if (val.isNull()) {
      value=WQLOperand();
      return true;
   }
   if (val.isArray()) return false;
   
   switch (type) {
   case CIMTYPE_UINT8:
      Uint8 propertyValueUint8;
      val.get(propertyValueUint8);
      value=WQLOperand(propertyValueUint8,WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_UINT16:
      Uint16 propertyValueUint16;
      val.get(propertyValueUint16);
      value=WQLOperand(propertyValueUint16, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_UINT32:
      Uint32 propertyValueUint32;
      val.get(propertyValueUint32);
      value=WQLOperand(propertyValueUint32, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_UINT64:
      Uint64 propertyValueUint64;
      val.get(propertyValueUint64);
      value=WQLOperand(propertyValueUint64, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_SINT8:
      Sint8 propertyValueSint8;
      val.get(propertyValueSint8);
      value=WQLOperand(propertyValueSint8, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_SINT16:
      Sint16 propertyValueSint16;
      val.get(propertyValueSint16);
      value=WQLOperand(propertyValueSint16, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_SINT32:
      Sint32 propertyValueSint32;
      val.get(propertyValueSint32);
      value=WQLOperand(propertyValueSint32, WQL_INTEGER_VALUE_TAG);
      break;

   case CIMTYPE_SINT64:
      Sint64 propertyValueSint64;
       val.get(propertyValueSint64);
       value=WQLOperand(propertyValueSint64, WQL_INTEGER_VALUE_TAG);
       break;

   case CIMTYPE_REAL32:
      Real32 propertyValueReal32;
      val.get(propertyValueReal32);
      value=WQLOperand(propertyValueReal32, WQL_DOUBLE_VALUE_TAG);
      break;

   case CIMTYPE_REAL64:
      Real64 propertyValueReal64;
      val.get(propertyValueReal64);
      value=WQLOperand(propertyValueReal64, WQL_DOUBLE_VALUE_TAG);
      break;

   case CIMTYPE_BOOLEAN :
      Boolean booleanValue;
      val.get(booleanValue);
      value=WQLOperand(booleanValue, WQL_BOOLEAN_VALUE_TAG);
      break;

   case CIMTYPE_CHAR16:
   case CIMTYPE_DATETIME :
   case CIMTYPE_STRING : {
         String strValue;
         val.get(strValue);
         value=WQLOperand(strValue,WQL_STRING_VALUE_TAG);
         break;
      }
   default: return false;   
   }
   return true;
 }	
Esempio n. 3
0
void test01()
{
    //
    // Create a property source (a place for the evaluate to get the
    // values of properties from):
    //

    WQLSimplePropertySource source;
    assert(source.addValue("x", WQLOperand(10, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("y", WQLOperand(20, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("z", WQLOperand(1.5, WQL_DOUBLE_VALUE_TAG)));

    //
    // Define query:
    //
    
    const char TEXT[] = 
	"SELECT x,y,z\n"
	"FROM MyClass\n"
	"WHERE x > 5 AND y < 25 AND z > 1.2";

    //
    //  Will test WQLParser::parse(const Array<Sint8>&, WQLSelectStatement&)
    //  and WQLParser::parse(const char*, WQLSelectStatement&) forms
    //
    Array<char> text;
    text.append(TEXT, sizeof(TEXT));
    if (verbose)
    {
        cout << text.getData() << endl;
    }

    // 
    // Parse the text:
    //

    WQLSelectStatement statement;

    try
    {
	WQLParser::parse(text, statement);
        if (verbose)
        {
	    statement.print();
        }

        //
        //  Test WQLSelectStatement functions
        //
        assert (statement.getClassName().equal ("MyClass"));
        assert (!statement.getAllProperties());
        assert (statement.getSelectPropertyNameCount() == 3);
        CIMName propName = statement.getSelectPropertyName (0);
        assert ((propName.equal ("x")) || (propName.equal ("y")) || 
                (propName.equal ("z")));
        CIMPropertyList propList = statement.getSelectPropertyList();
        assert (!propList.isNull());
        assert (propList.size() == 3);
        assert ((propList[0].equal ("x")) || (propList[0].equal ("y")) || 
                (propList[0].equal ("z")));
        assert (statement.hasWhereClause());
        assert (statement.getWherePropertyNameCount() == 3);
        CIMName wherePropName = statement.getWherePropertyName (0);
        assert ((wherePropName.equal ("x")) || (wherePropName.equal ("y")) || 
                (wherePropName.equal ("z")));
        CIMPropertyList wherePropList = statement.getWherePropertyList();
        assert (!wherePropList.isNull());
        assert (wherePropList.size() == 3);
        assert ((wherePropList[0].equal ("x")) || 
                (wherePropList[0].equal ("y")) || 
                (wherePropList[0].equal ("z")));
        assert (statement.evaluateWhereClause(&source));
    }
    catch (Exception& e)
    {
	cerr << "Exception: " << e.getMessage() << endl;
	exit(1);
    }
}
Esempio n. 4
0
void test02()
{
    //
    // Create a property source (a place for the evaluate to get the
    // values of properties from):
    //

    WQLSimplePropertySource source;
    assert(source.addValue("a", WQLOperand(5, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("b", WQLOperand(25, WQL_INTEGER_VALUE_TAG)));
    assert(source.addValue("c", WQLOperand(0.9, WQL_DOUBLE_VALUE_TAG)));
    assert(source.addValue("d", WQLOperand("Test", WQL_STRING_VALUE_TAG)));

    //
    // Define query:
    //
    
    const char TEXT[] = 
	"SELECT a,c,d\n"
	"FROM YourClass\n"
	"WHERE a > 5 AND b < 25 AND c > 1.2 AND d = \"Pass\"";

    //
    //  Will test WQLParser::parse(const String&, WQLSelectStatement&)
    //  and WQLParser::parse(const char*, WQLSelectStatement&) forms
    //
    String text (TEXT);
    if (verbose)
    {
        cout << text << endl;
    }

    // 
    // Parse the text:
    //

    WQLSelectStatement statement;

    try
    {
	WQLParser::parse(text, statement);
        if (verbose)
        {
	    statement.print();
        }

        //
        //  Test WQLSelectStatement functions
        //
        assert (statement.getClassName().equal ("YourClass"));
        assert (!statement.getAllProperties());
        assert (statement.getSelectPropertyNameCount() == 3);
        CIMName propName = statement.getSelectPropertyName (2);
        assert ((propName.equal ("a")) || (propName.equal ("c")) || 
                (propName.equal ("d")));
        CIMPropertyList propList = statement.getSelectPropertyList();
        assert (!propList.isNull());
        assert (propList.size() == 3);
        assert ((propList[2].equal ("a")) || (propList[2].equal ("c")) || 
                (propList[2].equal ("d")));
        assert (statement.hasWhereClause());
        assert (statement.getWherePropertyNameCount() == 4);
        CIMName wherePropName = statement.getWherePropertyName (3);
        assert ((wherePropName.equal ("a")) || (wherePropName.equal ("b")) || 
                (wherePropName.equal ("c")) || (wherePropName.equal ("d")));
        CIMPropertyList wherePropList = statement.getWherePropertyList();
        assert (!wherePropList.isNull());
        assert (wherePropList.size() == 4);
        assert ((wherePropList[3].equal ("a")) || 
                (wherePropList[3].equal ("b")) || 
                (wherePropList[3].equal ("c")) || 
                (wherePropList[3].equal ("d")));
        assert (!statement.evaluateWhereClause(&source));
    }
    catch (Exception& e)
    {
	cerr << "Exception: " << e.getMessage() << endl;
	exit(1);
    }
}