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