1 mike 1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 mike 1.1.2.1 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #ifndef Pegasus_WQLParser_h
31 #define Pegasus_WQLParser_h
32
33 #include <Pegasus/Common/Config.h>
|
34 mike 1.1.2.2 #include <Pegasus/Common/Array.h>
|
35 mike 1.1.2.1 #include <Pegasus/WQL/Linkage.h>
|
36 mike 1.1.2.3 #include <Pegasus/WQL/WQLSelectStatement.h>
|
37 mike 1.1.2.1
38 PEGASUS_NAMESPACE_BEGIN
39
|
40 mike 1.1.2.7 /** This class is the main interface to the WQL parser used for parsing WQL1
41 compliant SQL statements.
|
42 mike 1.1.2.4
|
43 mike 1.1.2.7 Here's an example which parses a SELECT statement:
|
44 mike 1.1.2.4
45 <pre>
|
46 mike 1.1.2.7 const char TEXT[] = "SELECT X,Y FROM MyClass WHERE X > 10 AND Y < 3";
47
48 // Note that this array must be null-terminated (sizeof(TEXT) includes
49 // the null-terminator in the count).
50
|
51 mike 1.1.2.4 Array<Sint8> text(TEXT, sizeof(TEXT));
|
52 mike 1.1.2.7
|
53 mike 1.1.2.4 WQLSelectStatement selectStatement;
54
55 WQLParser parser;
56
57 try
58 {
59 parser.parse(text, selectStatement);
60 }
61 catch (ParseError&)
62 {
63 ...
64 }
65 catch (MissingNullTerminator&)
66 {
67 ...
68 }
69 </pre>
70
|
71 mike 1.1.2.7 Note that the text must be NULL terminated or else the MissingNullTerminator
|
72 mike 1.1.2.4 exception is thrown.
|
73 mike 1.1.2.7
74 The text is read and the result is left in the selectStatement output
75 argument.
76
77 At this point you might wish to peek at the contents of the selectStatement.
78 This may be done by calling WQLSelectStatement::print() like this:
79
80 <pre>
81 WQLSelectStatement selectStatement;
82 ...
83 selectStatement.print();
84 </pre>
85
86 For the above query text, the following is printed:
87
88 <pre>
89 WQLSelectStatement
90 {
91 _className: "MyClass"
92
93 _propertyNames[0]: "X"
94 mike 1.1.2.7 _propertyNames[1]: "Y"
95
96 _operations[0]: "WQL_GT"
97 _operations[1]: "WQL_LT"
98 _operations[2]: "WQL_AND"
99
100 _operands[0]: "PROPERTY_NAME: X"
101 _operands[1]: "INTEGER_VALUE: 10"
102 _operands[2]: "PROPERTY_NAME: Y"
103 _operands[3]: "INTEGER_VALUE: 3"
104 }
105 </pre>
106
107 The WQLSelectStatement::evaluateWhereClause() method may be called to
108 determine whether a particular instance (whose properties are made
109 available to he evaluateWhereClause() by a user implementation of the
110 WQLPropertySource class). This method returns true, if the where clause
111 matches this instance. Here is an example:
112
113 <pre>
114 WQLSelectStatement selectStatement;
115 mike 1.1.2.7 ...
116 WQLPropertySource* propertySource = new MyPropertySource(...);
117
118 if (selectStatement.evaluateWhereClause(propertySource))
119 {
120 // It's a match!
121 }
122 </pre>
123
124 The evaluateWhereClause() method calls propertySource->getValue() to
125 obtain values for each of the properties referred to in where clause (X
126 and Y in the above query example).
127
128 The implementer of the WQLPropertySource interface must provide the
129 implementation of getValue() to produce values for the target data
130 types. The WQL library makes no assumptions about the nature of the
131 target data representation. This was done so that this libary could be
132 adapted to multiple data representations.
133
134 For use with Pegasus CIMInstance objects, a CIMInstancePropertySource
135 class could be developed whose getValue() method fetches values from
136 mike 1.1.2.7 a CIMInstance. Here is an example of how it might be used.
137
138 <pre>
139 CIMInstancePropertySource* propertySource
140 = new CIMInstancePropertySource(...);
141
142 CIMInstance instance;
143
144 while (instance = GetNextInstance(...))
145 {
146 propertySource->setInstance(currentInstance);
147
148 if (selectStatement.evaluateWhereClause(propertySource))
149 {
150 // It's a match!
151 }
152 }
153 </pre>
154
155 Of course the numeration of instances is left to the user of WQL.
|
156 mike 1.1.2.4 */
|
157 mike 1.1.2.1 class PEGASUS_WQL_LINKAGE WQLParser
158 {
159 public:
160
|
161 mike 1.1.2.4 /** Parse the SELECT statement given by the text parameter and initialize
162 the statement parameter accordingly.
163
|
164 mike 1.1.2.6 Please note that this method is not thread safe. It must be guarded
165 with mutexes by the caller.
166
|
167 mike 1.1.2.4 @param text null terminated array of characters containing a SELECT
168 statement.
169 @param statement object which holds the compiled version of the SELECT
170 statement upon return.
|
171 mike 1.1.2.7 @exception ParseError if text is not a valid SELECT statement.
172 @exception MissingNullTerminator if text argument is not
|
173 mike 1.1.2.4 terminated with a null.
174 */
|
175 mike 1.1.2.3 static void parse(
176 const Array<Sint8>& text,
177 WQLSelectStatement& statement);
|
178 mike 1.1.2.2
179 private:
180
|
181 mike 1.1.2.5 /** This method cleans up all the strings which were created by LEX and
182 passed to YACC. These strings cannot be cleaned up by YACC actions
183 since the actions that clean up certain strings are not always reached
184 when errors occur.
185 */
186 static void cleanup();
187
188 /** Private constructor to avoid user from creating instance of this class.
189 */
|
190 mike 1.1.2.2 WQLParser() { }
|
191 mike 1.1.2.1 };
192
193 PEGASUS_NAMESPACE_END
194
195 #endif /* Pegasus_WQLParser_h */
|