1 //%2003////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //==============================================================================
26 // Author: Mike Brasher (mbrasher@bmc.com)
30 //%/////////////////////////////////////////////////////////////////////////////
32 #ifndef Pegasus_WQLParser_h
33 #define Pegasus_WQLParser_h
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/ArrayInternal.h>
37 #include <Pegasus/WQL/Linkage.h>
38 #include <Pegasus/WQL/WQLSelectStatement.h>
40 PEGASUS_NAMESPACE_BEGIN
42 /** This class is the main interface to the WQL parser used for parsing WQL1
43 compliant SQL statements.
45 Here's an example which parses a SELECT statement:
48 const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
50 // Note that this array must be null-terminated (sizeof(TEXT) includes
51 // the null-terminator in the count).
53 Array<Sint8> text(TEXT, sizeof(TEXT));
55 WQLSelectStatement selectStatement;
61 parser.parse(text, selectStatement);
67 catch (MissingNullTerminator&)
73 Note that the text must be NULL terminated or else the MissingNullTerminator
76 The text is read and the result is left in the selectStatement output
79 At this point you might wish to peek at the contents of the selectStatement.
80 This may be done by calling WQLSelectStatement::print() like this:
83 WQLSelectStatement selectStatement;
85 selectStatement.print();
88 For the above query text, the following is printed:
95 _propertyNames[0]: "X"
96 _propertyNames[1]: "Y"
98 _operations[0]: "WQL_GT"
99 _operations[1]: "WQL_LT"
100 _operations[2]: "WQL_AND"
102 _operands[0]: "PROPERTY_NAME: X"
103 _operands[1]: "INTEGER_VALUE: 10"
104 _operands[2]: "PROPERTY_NAME: Y"
105 _operands[3]: "INTEGER_VALUE: 3"
109 The WQLSelectStatement::evaluateWhereClause() method may be called to
110 determine whether a particular instance (whose properties are made
111 available to he evaluateWhereClause() by a user implementation of the
112 WQLPropertySource class). This method returns true, if the where clause
113 matches this instance. Here is an example:
116 WQLSelectStatement selectStatement;
118 WQLPropertySource* propertySource = new MyPropertySource(...);
120 if (selectStatement.evaluateWhereClause(propertySource))
126 The evaluateWhereClause() method calls propertySource->getValue() to
127 obtain values for each of the properties referred to in where clause (X
128 and Y in the above query example).
130 The implementer of the WQLPropertySource interface must provide the
131 implementation of getValue() to produce values for the target data
132 types. The WQL library makes no assumptions about the nature of the
133 target data representation. This was done so that this libary could be
134 adapted to multiple data representations.
136 For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
137 class could be developed whose getValue() method fetches values from
138 a CIMInstance. Here is an example of how it might be used.
141 CIMInstancePropertySource* propertySource
142 = new CIMInstancePropertySource(...);
144 CIMInstance instance;
146 while (instance = GetNextInstance(...))
148 propertySource->setInstance(currentInstance);
150 if (selectStatement.evaluateWhereClause(propertySource))
157 Of course the numeration of instances is left to the user of WQL.
159 class PEGASUS_WQL_LINKAGE WQLParser
163 /** Parse the SELECT statement given by the text parameter and initialize
164 the statement parameter accordingly.
166 Please note that this method is not thread safe. It must be guarded
167 with mutexes by the caller.
169 @param text null-terminated C-string which points to SQL statement.
170 @param statement object which holds the compiled version of the SELECT
171 statement upon return.
172 @exception ParseError if text is not a valid SELECT statement.
173 @exception MissingNullTerminator if text argument is not
174 terminated with a null.
178 WQLSelectStatement& statement);
180 /** Version of parse() taking an array of characters.
183 const Array<Sint8>& text,
184 WQLSelectStatement& statement);
186 /** Version of parse() taking a string.
190 WQLSelectStatement& statement);
194 /** This method cleans up all the strings which were created by LEX and
195 passed to YACC. These strings cannot be cleaned up by YACC actions
196 since the actions that clean up certain strings are not always reached
199 static void cleanup();
201 /** Private constructor to avoid user from creating instance of this class.
206 PEGASUS_NAMESPACE_END
208 #endif /* Pegasus_WQLParser_h */