Void WbemServices::ExecQuery(const TChar* query, EnumCallback callback)
	{
		Com::Ptr<IEnumWbemClassObject> enumerator;

		auto hr = m_services->ExecQuery(L"WQL", _bstr_t(query), WBEM_FLAG_FORWARD_ONLY, nullptr, &enumerator);
		if (FAILED(hr))
		{
			StringW wql(query);
			TRACE_ERROR(L"Exception while executing WQL query: %s", wql.GetBuffer());
			THROW_WIN32_EXCEPTION(hr);
		}

		while (nullptr != enumerator)
		{
			ULONG returned = 0;
			Com::Ptr<IWbemClassObject> object;

			auto hr = enumerator->Next(WBEM_INFINITE, 1, &object, &returned);
			if (0 == returned || nullptr == object)
			{
				break;
			}

			auto next = callback(WbemClassObject(std::move(object)));
			if (!next)
			{
				break;
			}
		}
	}
Example #2
0
QueryExpression QueryExpression::operator=(const QueryExpression& rhs)
{
  if (this == &rhs)
    return *this;

  if (_ss != NULL)
    delete _ss;
  _ss = NULL;

  if (rhs._ss != NULL)
  {
    String cql("CIM:CQL");
    String wql("WQL");

#ifndef PEGASUS_DISABLE_CQL
    if (rhs._queryLang == cql)
    {
      CQLSelectStatement* tempSS = dynamic_cast<CQLSelectStatement*>(rhs._ss);
      if (tempSS != NULL)
        _ss = new CQLSelectStatement(*tempSS);
    }
    else 
#endif
    if (rhs._queryLang == wql)
    {
      WQLSelectStatement* tempSS = dynamic_cast<WQLSelectStatement*>(rhs._ss);
      if (tempSS != NULL)
        _ss = new WQLSelectStatement(*tempSS);
    }
  }

  _queryLang = rhs._queryLang;

  return *this;
}
Example #3
0
QueryExpression::QueryExpression(const QueryExpression& expr):
  _queryLang(expr._queryLang)
{
  if (expr._ss == NULL)
  {
    _ss = NULL;
  }
  else
  {
    _ss = NULL;

    String cql("CIM:CQL");
    String wql("WQL");

#ifndef PEGASUS_DISABLE_CQL
    if (expr._queryLang == cql)
    {
      CQLSelectStatement* tempSS = dynamic_cast<CQLSelectStatement*>(expr._ss);
      if (tempSS != NULL)
        _ss = new CQLSelectStatement(*tempSS);
    }
    else 
#endif
    if (expr._queryLang == wql)
    {
      WQLSelectStatement* tempSS = dynamic_cast<WQLSelectStatement*>(expr._ss);
      if (tempSS != NULL)
        _ss = new WQLSelectStatement(*tempSS);
    }
  }
}
Example #4
0
int main()
{
    CIMClient client;
    try
    {
      client.connectLocal();
    }
    catch (Exception& e)
    {
      PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                         << PEGASUS_STD (endl);
      PEGASUS_STD (cerr) << "connectLocal failed"
                         << PEGASUS_STD (endl);
      return -1;
    }

    String query1="SELECT MethodName FROM Test_IndicationProviderClass";

    // Note that CQL expects single quote around string literals,
    // while WQL expects double quote.
    // Note that CQL use <> for the inequality operator.
    String query2wql =
        "SELECT MethodName FROM Test_IndicationProviderClass "
            "WHERE IndicationIdentifier != \"x\"";
    String query2cql =
        "SELECT MethodName FROM Test_IndicationProviderClass "
            "WHERE IndicationIdentifier <> 'x'";

    String wql("WQL");
    String cql("DMTF:CQL");

    PEGASUS_STD (cout) << "+++++ start wql test" << PEGASUS_STD (endl);
    int rc;
    rc = _test(client, wql, query1, query2wql);
    if (rc != 0)
      return rc;
    PEGASUS_STD (cout) << "+++++ start dupliacte subscription test"
                       << PEGASUS_STD (endl);
    _testDuplicate(client);
    PEGASUS_STD (cout) << "+++++ duplicate subscription test completed"
                       << PEGASUS_STD (endl);

    PEGASUS_STD (cout) << "+++++ start concurrent subscription test"
                       << PEGASUS_STD (endl);
    _testConcurrent(client);
    PEGASUS_STD (cout) << "+++++ concurrent subscription test completed"
                       << PEGASUS_STD (endl);
#ifdef PEGASUS_ENABLE_CQL
    PEGASUS_STD (cout) << "+++++ start cql test" << PEGASUS_STD (endl);
    return _test(client, cql, query1, query2cql);
#else
    PEGASUS_STD (cout) << "+++++ cql test disabled" << PEGASUS_STD (endl);
    return 0;
#endif
}
Example #5
0
QueryExpression::QueryExpression(String queryLang, String query, QueryContext& ctx):
  _queryLang(queryLang)
{
   String cql("CIM:CQL");
   String wql("WQL");

#ifndef PEGASUS_DISABLE_CQL
   if (queryLang == cql)
   {
     CQLSelectStatement* cqlss = new CQLSelectStatement(queryLang, query, ctx);

     // Compile the statement
     CQLParser::parse(query, *cqlss);

     // Finish checking the statement for CQL by applying the class contexts to
     // the chained identifiers.
     cqlss->applyContext();

     _ss = cqlss;
   }
   else 
#endif
   if (queryLang == wql)
   {
     WQLSelectStatement* wqlss = new WQLSelectStatement(queryLang, query, ctx);

     // Compile the statement
     WQLParser::parse(query, *wqlss);

     _ss = wqlss;
   }
   else
   {
     throw QueryLanguageInvalidException(
				MessageLoaderParms(String("Query.QueryExpression.INVALID_QUERY_LANGUAGE"),
						   String("The query language specified is invalid: $0."),
						   queryLang));
   }
}
Example #6
0
QueryExpression::QueryExpression(String queryLang, String query):
  _queryLang(queryLang)
{
   String cql("CIM:CQL");
   String wql("WQL");

#ifndef PEGASUS_DISABLE_CQL
   if (queryLang == cql)
   {
     CQLSelectStatement* cqlss = new CQLSelectStatement(queryLang, query);

     // Note: cannot call parse the CQLSelectStatement
     // because there is no QueryContext.
     // The parse will happen when setQueryContext is called.

     _ss = cqlss;
   }
   else 
#endif
   if (queryLang == wql)
   {
     WQLSelectStatement* wqlss = new WQLSelectStatement(queryLang, query);

     // Compile the statement
     WQLParser::parse(query, *wqlss);

     _ss = wqlss;
   }
   else
   {
     throw QueryLanguageInvalidException(
            MessageLoaderParms(String("Query.QueryExpression.INVALID_QUERY_LANGUAGE"),
            String("The query language specified is invalid: $0."),
            queryLang));
   }
}