Sun WBEM SDK Developer's Guide

Making a Data Query

Data queries are statements that request instances of classes. To issue a data query, applications use the execQuery method to pass a WBEM Query Language string to the CIM Object Manager.

The SELECT Statement

The SELECT statement is the SQL statement for retrieving information, with a few restrictions and extensions specific to WQL. Although the SQL SELECT statement is typically used in the database environment to retrieve particular columns from tables, the WQL SELECT statement is used to retrieve instances of a single class. WQL does not support queries across multiple classes.

The SELECT statement specifies the properties to query in an object specified in the FROM clause.

The basic syntax for the SELECT statement is:

SELECT instance FROM class

The following tables shows examples of using arguments in the SELECT clause to refine a search.

Table 4–5 SELECT Statement

Example Query 

Description 

SELECT * FROM class

Selects all instances of the specified class and any of its subclasses. 

SELECT PropertyA FROM class 

Selects only instances of the specified class and any of its subclasses that contain PropertyA.

SELECT PropertyA, PropertyB FROM class

Selects only instances of the specified class and any of its subclasses that contain PropertyA or PropertyB.

The WHERE Clause

You can use the WHERE clause to narrow the scope of a query. The WHERE clause can contain a property or key word, an operator, and a constant. All WHERE clauses must specify one of the predefined WQL operators.

The basic syntax for appending the WHERE clause to the SELECT statement is:

SELECT instance FROM class WHERE expression

The expression is composed of a property or key word, an operator, and a constant. You can append the WHERE clause to the SELECT statement using one of the following forms:

SELECT instance FROM class [[WHERE property operator constant]]

SELECT instance FROM class [[WHERE constant operator property]]

Valid WHERE clauses follow these rules:

Multiple groups of properties, operators, and constants can be combined in a WHERE clause using logical operators and parenthetical expressions. Each group must be joined with the AND, OR, or NOT operators as shown in the following table.

Table 4–6 Queries Using Logical Operators

Example Query 

Description 

SELECT * FROM Solaris_FileSystem WHERE Name= "home" OR Name= "files" 

Retrieves all instances of the Solaris_FileSystem class with the Name property set to either home or files.

SELECT * FROM Solaris_FileSystem WHERE (Name = “home” OR Name = “files”) AND AvailableSpace > 2000000 AND FileSystem = “Solaris” 

Retrieves disks named home and files only if they have a certain amount of available space remaining and have Solaris file systems.