1 martin 1.29 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.30 //
|
3 martin 1.29 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.30 //
|
10 martin 1.29 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.30 //
|
17 martin 1.29 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.30 //
|
20 martin 1.29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.30 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.30 //
|
28 martin 1.29 //////////////////////////////////////////////////////////////////////////
|
29 chuck 1.3 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
|
32 humberto 1.1 #include <Pegasus/CQL/CQLFunctionRep.h>
|
33 lucier 1.4
34 // CQL includes
|
35 humberto 1.1 #include <Pegasus/CQL/CQLFactory.h>
|
36 chuck 1.3 #include <Pegasus/CQL/CQLUtilities.h>
|
37 lucier 1.4 #include <Pegasus/CQL/CQLValue.h>
|
38 david.dillard 1.20 #include <Pegasus/CQL/CQLValueRep.h>
|
39 lucier 1.4
40 // Common Query includes
41 #include <Pegasus/Query/QueryCommon/QueryContext.h>
42
43 // Common Pegasus includes
44 #include <Pegasus/Common/CIMName.h>
45 #include <Pegasus/Common/CIMObjectPath.h>
|
46 lucier 1.5 #include <Pegasus/Common/Tracer.h>
|
47 lucier 1.4
|
48 humberto 1.1 PEGASUS_NAMESPACE_BEGIN
|
49 lucier 1.5
|
50 humberto 1.16 CQLFunctionRep::CQLFunctionRep(): _funcOpType(UNKNOWN), _parms() {}
51
|
52 kumpf 1.27 CQLFunctionRep::CQLFunctionRep(
53 CQLIdentifier inOpType,
54 Array<CQLPredicate> inParms)
|
55 karl 1.24 : _funcOpType(UNKNOWN), _parms(inParms)
56 {
57 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::CQLFunctionRep()");
|
58 kumpf 1.31
|
59 karl 1.24 String opType(inOpType.getName().getString());
|
60 kumpf 1.31
|
61 kumpf 1.27 if (String::compareNoCase(opType,String("DATETIMETOMICROSECOND")) == 0)
62 {
|
63 karl 1.24 _funcOpType = DATETIMETOMICROSECOND;
64 }
|
65 kumpf 1.27 else if (String::compareNoCase(opType, String("STRINGTOUINT")) == 0)
66 {
|
67 karl 1.24 _funcOpType = STRINGTOUINT;
68 }
|
69 kumpf 1.27 else if (String::compareNoCase(opType, String("STRINGTOSINT")) == 0)
70 {
|
71 karl 1.24 _funcOpType = STRINGTOSINT;
72 }
|
73 kumpf 1.27 else if (String::compareNoCase(opType, String("STRINGTOREAL")) == 0)
74 {
|
75 karl 1.24 _funcOpType = STRINGTOREAL;
76 }
|
77 kumpf 1.27 else if (String::compareNoCase(opType, String("STRINGTONUMERIC")) == 0)
78 {
|
79 karl 1.24 _funcOpType = STRINGTONUMERIC;
80 }
|
81 kumpf 1.27 else if (String::compareNoCase(opType, String("UPPERCASE")) == 0)
82 {
|
83 karl 1.24 _funcOpType = UPPERCASE;
84 }
|
85 kumpf 1.27 else if (String::compareNoCase(opType, String("NUMERICTOSTRING")) == 0)
86 {
|
87 karl 1.24 _funcOpType = NUMERICTOSTRING;
88 }
|
89 kumpf 1.27 else if (String::compareNoCase(opType, String("REFERENCETOSTRING")) == 0)
90 {
|
91 karl 1.24 _funcOpType = REFERENCETOSTRING;
92 }
|
93 kumpf 1.27 else if (String::compareNoCase(opType, String("CLASSNAME")) == 0)
94 {
|
95 karl 1.24 _funcOpType = CLASSNAME;
96 }
|
97 kumpf 1.27 else if (String::compareNoCase(opType, String("NAMESPACENAME")) == 0)
98 {
|
99 karl 1.24 _funcOpType = NAMESPACENAME;
100 }
|
101 kumpf 1.27 else if (String::compareNoCase(opType, String("NAMESPACETYPE")) == 0)
102 {
|
103 karl 1.24 _funcOpType = NAMESPACETYPE;
104 }
|
105 kumpf 1.27 else if (String::compareNoCase(opType, String("HOSTPORT")) == 0)
106 {
|
107 karl 1.24 _funcOpType = HOSTPORT;
108 }
|
109 kumpf 1.27 else if (String::compareNoCase(opType, String("MODELPATH")) == 0)
110 {
|
111 karl 1.24 _funcOpType = MODELPATH;
112 }
|
113 kumpf 1.27 else if (String::compareNoCase(opType, String("CLASSPATH")) == 0)
114 {
|
115 karl 1.24 _funcOpType = CLASSPATH;
116 }
|
117 kumpf 1.27 else if (String::compareNoCase(opType, String("OBJECTPATH")) == 0)
118 {
|
119 karl 1.24 _funcOpType = OBJECTPATH;
120 }
|
121 kumpf 1.27 else if (String::compareNoCase(opType, String("INSTANCETOREFERENCE")) == 0)
122 {
|
123 karl 1.24 _funcOpType = INSTANCETOREFERENCE;
124 }
|
125 kumpf 1.27 else if (String::compareNoCase(opType, String("CURRENTDATETIME")) == 0)
126 {
|
127 karl 1.24 _funcOpType = CURRENTDATETIME;
128 }
|
129 kumpf 1.27 else if (String::compareNoCase(opType, String("DATETIME")) == 0)
130 {
|
131 karl 1.24 _funcOpType = DATETIME;
132 }
|
133 kumpf 1.27 else if (String::compareNoCase(
134 opType, String("MICROSECONDTOTIMESTAMP")) == 0)
135 {
|
136 karl 1.24 _funcOpType = MICROSECONDTOTIMESTAMP;
137 }
|
138 kumpf 1.27 else if (String::compareNoCase(
139 opType, String("MICROSECONDTOINTERVAL")) == 0)
140 {
141 _funcOpType = MICROSECONDTOINTERVAL;
|
142 karl 1.24 }
143 else
144 {
145 // Unknown function
146 MessageLoaderParms mload(
|
147 kumpf 1.27 "CQL.CQLFunctionRep.INVALID_FUNCTION",
148 "Function: $0 is not a supported function.",
|
149 karl 1.24 opType);
150 throw CQLSyntaxErrorException(mload);
151 }
152 PEG_METHOD_EXIT();
|
153 chuck 1.3 }
|
154 kumpf 1.27
|
155 kumpf 1.31 CQLFunctionRep::CQLFunctionRep(const CQLFunctionRep* rep)
|
156 karl 1.24 : _funcOpType(rep->_funcOpType), _parms(rep->_parms)
|
157 humberto 1.1 {
158 }
159
|
160 lucier 1.5 CQLFunctionRep::~CQLFunctionRep()
161 {
|
162 chuck 1.3 }
|
163 humberto 1.1
|
164 kumpf 1.27 CQLValue CQLFunctionRep::resolveValue(
165 const CIMInstance& CI,
166 const QueryContext& queryCtx)
|
167 chuck 1.3 {
|
168 karl 1.24 switch(_funcOpType)
169 {
170 case DATETIMETOMICROSECOND:
|
171 lucier 1.5 return dateTimeToMicrosecond(CI, queryCtx);
|
172 karl 1.24 case STRINGTOUINT:
|
173 lucier 1.5 return stringToUint(CI, queryCtx);
|
174 karl 1.24 case STRINGTOSINT:
|
175 lucier 1.5 return stringToSint(CI, queryCtx);
|
176 karl 1.24 case STRINGTOREAL:
|
177 lucier 1.5 return stringToReal(CI, queryCtx);
|
178 karl 1.24 case STRINGTONUMERIC:
|
179 lucier 1.5 return stringToNumeric(CI, queryCtx);
|
180 karl 1.24 case UPPERCASE:
|
181 lucier 1.5 return upperCase(CI, queryCtx);
|
182 karl 1.24 case NUMERICTOSTRING:
|
183 lucier 1.5 return numericToString(CI, queryCtx);
|
184 karl 1.24 case REFERENCETOSTRING:
|
185 lucier 1.5 return referenceToString(CI, queryCtx);
|
186 karl 1.24 case CLASSNAME:
|
187 lucier 1.5 return className(CI, queryCtx);
|
188 karl 1.24 case NAMESPACENAME:
|
189 lucier 1.5 return nameSpaceName(CI, queryCtx);
|
190 karl 1.24 case NAMESPACETYPE:
|
191 lucier 1.5 return nameSpaceType(CI, queryCtx);
|
192 karl 1.24 case HOSTPORT:
|
193 lucier 1.5 return hostPort(CI, queryCtx);
|
194 karl 1.24 case MODELPATH:
|
195 lucier 1.5 return modelPath(CI, queryCtx);
|
196 karl 1.24 case CLASSPATH:
|
197 lucier 1.5 return classPath(CI, queryCtx);
|
198 karl 1.24 case OBJECTPATH:
|
199 lucier 1.5 return objectPath(CI, queryCtx);
|
200 karl 1.24 case INSTANCETOREFERENCE:
|
201 lucier 1.5 return instanceToReference(CI, queryCtx);
|
202 karl 1.24 case CURRENTDATETIME:
|
203 lucier 1.5 return currentDateTime();
|
204 karl 1.24 case DATETIME:
|
205 lucier 1.5 return dateTime(CI, queryCtx);
|
206 karl 1.24 case MICROSECONDTOTIMESTAMP:
|
207 lucier 1.5 return microsecondToTimestamp(CI, queryCtx);
|
208 karl 1.24 case MICROSECONDTOINTERVAL:
|
209 lucier 1.5 return microsecondToInterval(CI, queryCtx);
|
210 karl 1.24 case UNKNOWN:
|
211 kumpf 1.27 // Unknown function; this case is handled below
212 break;
|
213 karl 1.24 }
|
214 kumpf 1.27
|
215 karl 1.24 // Unknown function
216 MessageLoaderParms mload(
|
217 kumpf 1.27 "CQL.CQLFunctionRep.INVALID_FUNCTION_ID",
218 "Function ID: $0 is not a supported function ID.",
|
219 marek 1.28 Formatter::Arg(Uint32(_funcOpType)));
|
220 karl 1.24 throw CQLSyntaxErrorException(mload);
|
221 humberto 1.1 }
222
|
223 lucier 1.5 String CQLFunctionRep::toString() const
|
224 humberto 1.1 {
|
225 karl 1.24 String returnStr = functionTypeToString();
|
226 kumpf 1.31
|
227 karl 1.24 returnStr.append("(");
228 Uint32 parmSize = _parms.size();
229 for(Uint32 i = 0; i < parmSize; ++i)
230 {
231 returnStr.append(_parms[i].toString());
232 if (i+1 < parmSize)
233 returnStr.append(", ");
234 }
235 returnStr.append(")");
236 return returnStr;
|
237 lucier 1.6 }
238
239 String CQLFunctionRep::functionTypeToString() const
240 {
|
241 karl 1.24 String returnStr;
|
242 kumpf 1.31
|
243 karl 1.24 switch(_funcOpType)
244 {
245 case DATETIMETOMICROSECOND:
246 returnStr.append("DATETIMETOMICROSECOND");
247 break;
248 case STRINGTOUINT:
249 returnStr.append("STRINGTOUINT");
250 break;
251 case STRINGTOSINT:
252 returnStr.append("STRINGTOSINT");
253 break;
254 case STRINGTOREAL:
255 returnStr.append("STRINGTOREAL");
256 break;
257 case STRINGTONUMERIC:
258 returnStr.append("STRINGTONUMERIC");
259 break;
260 case UPPERCASE:
261 returnStr.append("UPPERCASE");
262 break;
263 case NUMERICTOSTRING:
264 karl 1.24 returnStr.append("NUMERICTOSTRING");
265 break;
266 case REFERENCETOSTRING:
267 returnStr.append("REFERENCETOSTRING");
268 break;
269 case CLASSNAME:
270 returnStr.append("CLASSNAME");
271 break;
272 case NAMESPACENAME:
273 returnStr.append("NAMESPACENAME");
274 break;
275 case NAMESPACETYPE:
276 returnStr.append("NAMESPACETYPE");
277 break;
278 case HOSTPORT:
279 returnStr.append("HOSTPORT");
280 break;
281 case MODELPATH:
282 returnStr.append("MODELPATH");
283 break;
284 case CLASSPATH:
285 karl 1.24 returnStr.append("CLASSPATH");
286 break;
287 case OBJECTPATH:
288 returnStr.append("OBJECTPATH");
289 break;
290 case INSTANCETOREFERENCE:
291 returnStr.append("INSTANCETOREFERENCE");
292 break;
293 case CURRENTDATETIME:
294 returnStr.append("CURRENTDATETIME");
295 break;
296 case DATETIME:
297 returnStr.append("DATETIME");
298 break;
299 case MICROSECONDTOTIMESTAMP:
300 returnStr.append("MICROSECONDTOTIMESTAMP");
301 break;
302 case MICROSECONDTOINTERVAL:
303 returnStr.append("MICROSECONDTOINTERVAL");
304 break;
305 case UNKNOWN:
306 karl 1.24 returnStr.append("UNKNOWN");
307 default:
308 returnStr.append("UNKNOWN");
309 break;
310 }
311 return returnStr;
|
312 humberto 1.1 }
313
|
314 chuck 1.3 Array<CQLPredicate> CQLFunctionRep::getParms()const
|
315 humberto 1.1 {
|
316 karl 1.24 return _parms;
|
317 humberto 1.1 }
318
|
319 chuck 1.3 FunctionOpType CQLFunctionRep::getFunctionType()const
|
320 humberto 1.1 {
|
321 karl 1.24 return _funcOpType;
|
322 humberto 1.1 }
|
323 kumpf 1.31
|
324 vijay.eli 1.22 void CQLFunctionRep::applyContext(const QueryContext& inContext)
|
325 humberto 1.1 {
|
326 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::applyContext()");
|
327 kumpf 1.31
|
328 karl 1.24 for(Uint32 i = 0; i < _parms.size(); ++i)
329 {
330 _parms[i].applyContext(inContext);
331 }
332 PEG_METHOD_EXIT();
|
333 humberto 1.1 }
|
334 humberto 1.16 /*
|
335 chuck 1.3 Boolean CQLFunctionRep::operator==(const CQLFunctionRep& func)const
336 {
337 if(_funcOpType != func._funcOpType || _parms.size() != func._parms.size())
|
338 lucier 1.5 {
339 return false;
340 }
|
341 chuck 1.3
|
342 lucier 1.5 // for(Uint32 i = 0; i < _parms.size(); ++i)
343 // {
344 // if(!(_parms[i] == func._parms[i]))
345 // {
346 // return false;
347 // }
348 // }
|
349 chuck 1.3
350 return true;
|
351 humberto 1.1 }
|
352 humberto 1.16
|
353 chuck 1.3 Boolean CQLFunctionRep::operator!=(const CQLFunctionRep& func)const{
|
354 karl 1.24 return (!operator==(func));
|
355 humberto 1.1 }
|
356 humberto 1.16 */
|
357 lucier 1.6
|
358 kumpf 1.27 CQLValue CQLFunctionRep::dateTimeToMicrosecond(
359 const CIMInstance& CI,
360 const QueryContext& queryCtx) const
|
361 chuck 1.3 {
|
362 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::dateTimeToMicrosecond()");
|
363 kumpf 1.31
|
364 kumpf 1.27 if (_parms.size() != 1)
|
365 karl 1.24 {
|
366 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
367 "Function $0 has $1 parameters. It must have between"
368 " $2 and $3.",
|
369 karl 1.24 functionTypeToString(),
|
370 kumpf 1.27 _parms.size(),
|
371 karl 1.25 "1", "1");
|
372 karl 1.24 throw CQLRuntimeException(mload);
373 }
|
374 kumpf 1.31
|
375 karl 1.24 // resolve the parameter
376 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
377 resolveValue(CI,queryCtx);
|
378 kumpf 1.31
|
379 karl 1.24 if(cqlVal.getValueType() != CQLValue::CIMDateTime_type)
380 {
|
381 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
382 "Parameter $0 for function $1 has type $2."
383 " It must be type $3.",
384 "1",
|
385 karl 1.24 functionTypeToString(),
386 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
387 CQLValueRep::valueTypeToString(CQLValue::CIMDateTime_type));
388 throw CQLRuntimeException(mload);
|
389 dave.sudlik 1.26 }
|
390 lucier 1.4
|
391 dave.sudlik 1.26 if (cqlVal.isNull())
392 {
393 return CQLValue(CIMValue(CIMTYPE_UINT64, false));
|
394 kumpf 1.31 }
|
395 dave.sudlik 1.26
396 PEG_METHOD_EXIT();
|
397 kumpf 1.31 return CQLValue(cqlVal.getDateTime().toMicroSeconds());
|
398 chuck 1.3 }
399
|
400 kumpf 1.27 CQLValue CQLFunctionRep::stringToUint(
401 const CIMInstance& CI,
402 const QueryContext& queryCtx) const
|
403 chuck 1.3 {
|
404 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToUint()");
|
405 kumpf 1.27 if (_parms.size() != 1)
|
406 karl 1.24 {
|
407 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
408 "Function $0 has $1 parameters."
409 " It must have between $2 and $3.",
|
410 karl 1.24 functionTypeToString(),
|
411 kumpf 1.27 _parms.size(),
|
412 karl 1.25 "1", "1");
|
413 karl 1.24 throw CQLRuntimeException(mload);
414 }
|
415 kumpf 1.31
|
416 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
417 resolveValue(CI,queryCtx);
|
418 dave.sudlik 1.26
|
419 karl 1.24 if(cqlVal.getValueType() != CQLValue::String_type)
420 {
|
421 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
422 "Parameter $0 for function $1 has type $2."
423 " It must be type $3.",
424 "1",
|
425 karl 1.24 functionTypeToString(),
426 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
427 CQLValueRep::valueTypeToString(CQLValue::String_type));
428 throw CQLRuntimeException(mload);
|
429 dave.sudlik 1.26 }
430
431 if (cqlVal.isNull())
432 {
433 return CQLValue(CIMValue(CIMTYPE_UINT64, false));
434 }
|
435 chuck 1.3
|
436 dave.sudlik 1.26 PEG_METHOD_EXIT();
437 return CQLValue(CQLUtilities::stringToUint64(cqlVal.getString()));
|
438 chuck 1.3 }
439
|
440 kumpf 1.27 CQLValue CQLFunctionRep::stringToSint(
441 const CIMInstance& CI,
442 const QueryContext& queryCtx) const
|
443 chuck 1.3 {
|
444 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToSint()");
|
445 kumpf 1.27 if (_parms.size() != 1)
|
446 karl 1.24 {
|
447 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
448 "Function $0 has $1 parameters."
449 " It must have between $2 and $3.",
|
450 karl 1.24 functionTypeToString(),
|
451 kumpf 1.27 _parms.size(),
|
452 karl 1.25 "1", "1");
|
453 karl 1.24 throw CQLRuntimeException(mload);
454 }
|
455 kumpf 1.31
|
456 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
457 resolveValue(CI,queryCtx);
|
458 kumpf 1.31
|
459 karl 1.24 if(cqlVal.getValueType() != CQLValue::String_type)
460 {
|
461 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
462 "Parameter $0 for function $1 has type $2."
463 " It must be type $3.",
464 "1",
|
465 karl 1.24 functionTypeToString(),
466 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
467 CQLValueRep::valueTypeToString(CQLValue::String_type));
468 throw CQLRuntimeException(mload);
469 }
|
470 kumpf 1.31
|
471 dave.sudlik 1.26 if (cqlVal.isNull())
472 {
473 return CQLValue(CIMValue(CIMTYPE_SINT64, false));
474 }
475
|
476 karl 1.24 PEG_METHOD_EXIT();
477 return CQLValue(CQLUtilities::stringToSint64(cqlVal.getString()));
|
478 chuck 1.3 }
479
|
480 kumpf 1.27 CQLValue CQLFunctionRep::stringToReal(
481 const CIMInstance& CI,
482 const QueryContext& queryCtx) const
|
483 chuck 1.3 {
|
484 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::stringToReal()");
|
485 kumpf 1.27 if (_parms.size() != 1)
|
486 karl 1.24 {
|
487 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
488 "Function $0 has $1 parameters."
489 " It must have between $2 and $3.",
|
490 karl 1.24 functionTypeToString(),
|
491 kumpf 1.27 _parms.size(),
492 "1", "1");
|
493 karl 1.24 throw CQLRuntimeException(mload);
494 }
|
495 kumpf 1.31
|
496 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
497 resolveValue(CI,queryCtx);
|
498 dave.sudlik 1.26
|
499 karl 1.24 if(cqlVal.getValueType() != CQLValue::String_type)
500 {
|
501 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
502 "Parameter $0 for function $1 has type $2."
503 " It must be type $3.",
504 "1",
|
505 karl 1.24 functionTypeToString(),
506 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
507 CQLValueRep::valueTypeToString(CQLValue::String_type));
508 throw CQLRuntimeException(mload);
509 }
|
510 dave.sudlik 1.26
511 if (cqlVal.isNull())
512 {
513 return CQLValue(CIMValue(CIMTYPE_REAL64, false));
514 }
|
515 kumpf 1.31
|
516 karl 1.24 PEG_METHOD_EXIT();
517 return CQLValue(CQLUtilities::stringToReal64(cqlVal.getString()));
|
518 chuck 1.3 }
519
|
520 kumpf 1.27 CQLValue CQLFunctionRep::stringToNumeric(
521 const CIMInstance& CI,
522 const QueryContext& queryCtx) const
|
523 chuck 1.3 {
|
524 kumpf 1.27 return stringToReal(CI, queryCtx);
|
525 chuck 1.3 }
526
|
527 kumpf 1.27 CQLValue CQLFunctionRep::upperCase(
528 const CIMInstance& CI,
529 const QueryContext& queryCtx) const
|
530 chuck 1.3 {
|
531 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::upperCase()");
|
532 kumpf 1.27 if (_parms.size() != 1)
|
533 karl 1.24 {
|
534 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
535 "Function $0 has $1 parameters."
536 " It must have between $2 and $3.",
|
537 karl 1.24 functionTypeToString(),
|
538 kumpf 1.27 _parms.size(),
539 "1", "1");
|
540 karl 1.24 throw CQLRuntimeException(mload);
541 }
|
542 kumpf 1.31
|
543 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
544 resolveValue(CI,queryCtx);
|
545 dave.sudlik 1.26
|
546 karl 1.24 if(cqlVal.getValueType() != CQLValue::String_type)
547 {
|
548 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
549 "Parameter $0 for function $1 has type $2."
550 " It must be type $3.",
551 "1",
|
552 karl 1.24 functionTypeToString(),
553 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
554 CQLValueRep::valueTypeToString(CQLValue::String_type));
555 throw CQLRuntimeException(mload);
556 }
|
557 kumpf 1.31
|
558 dave.sudlik 1.26 if (cqlVal.isNull())
559 {
560 return cqlVal;
561 }
|
562 kumpf 1.31
|
563 karl 1.24 String tmpStr = cqlVal.getString();
564 tmpStr.toUpper();
|
565 kumpf 1.31
|
566 karl 1.24 PEG_METHOD_EXIT();
567 return CQLValue(tmpStr);
|
568 chuck 1.3 }
569
|
570 kumpf 1.27 CQLValue CQLFunctionRep::numericToString(
571 const CIMInstance& CI,
572 const QueryContext& queryCtx) const
|
573 lucier 1.4 {
|
574 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::numericToString()");
|
575 kumpf 1.27
576 if (_parms.size() != 1)
|
577 karl 1.24 {
|
578 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
579 "Function $0 has $1 parameters."
580 " It must have between $2 and $3.",
|
581 karl 1.24 functionTypeToString(),
|
582 kumpf 1.27 _parms.size(),
583 "1", "1");
|
584 karl 1.24 throw CQLRuntimeException(mload);
585 }
|
586 kumpf 1.31
|
587 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
588 resolveValue(CI,queryCtx);
|
589 dave.sudlik 1.26
|
590 kumpf 1.31 CQLValue::CQLValueType valType = cqlVal.getValueType();
|
591 dave.sudlik 1.26
592 if (valType != CQLValue::Sint64_type && valType != CQLValue::Uint64_type
593 && valType != CQLValue::Real_type)
594 {
595 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
596 "Parameter $0 for function $1 has type $2."
597 " It must be type $3.",
598 "1",
599 functionTypeToString(),
600 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
|
601 kumpf 1.27 "Integer or Real");
|
602 dave.sudlik 1.26 throw CQLRuntimeException(mload);
603 }
604
605 if (cqlVal.isNull())
606 {
607 return CQLValue(CIMValue(CIMTYPE_STRING, false));
608 }
609
|
610 kumpf 1.27 char buffer[128];
611
|
612 karl 1.24 if (valType == CQLValue::Sint64_type)
613 {
|
614 kumpf 1.31 sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "d",
|
615 karl 1.24 cqlVal.getSint());
616 }
617 else if (valType == CQLValue::Uint64_type)
618 {
|
619 kumpf 1.31 sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
|
620 karl 1.24 cqlVal.getUint());
621 }
622 else
623 {
|
624 dave.sudlik 1.26 sprintf(buffer, "%.16E", cqlVal.getReal());
|
625 karl 1.24 }
|
626 dave.sudlik 1.26
|
627 karl 1.24 String num(buffer);
628 if (valType == CQLValue::Real_type)
629 {
630 // format the exponent
631 num = CQLUtilities::formatRealStringExponent(num);
632 }
|
633 kumpf 1.31
|
634 karl 1.24 PEG_METHOD_EXIT();
635 return CQLValue(num);
|
636 lucier 1.4 }
637
|
638 kumpf 1.27 CQLValue CQLFunctionRep::referenceToString(
639 const CIMInstance& CI,
640 const QueryContext& queryCtx) const
|
641 lucier 1.4 {
|
642 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::referenceToString()");
|
643 kumpf 1.27 if (_parms.size() != 1)
|
644 karl 1.24 {
|
645 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
646 "Function $0 has $1 parameters."
647 " It must have between $2 and $3.",
|
648 karl 1.24 functionTypeToString(),
|
649 kumpf 1.27 _parms.size(),
650 "1", "1");
|
651 karl 1.24 throw CQLRuntimeException(mload);
652 }
|
653 kumpf 1.31
|
654 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
655 resolveValue(CI,queryCtx);
|
656 kumpf 1.31
|
657 dave.sudlik 1.26 CQLValue::CQLValueType valType = cqlVal.getValueType();
658
659 if (valType != CQLValue::CIMReference_type &&
660 valType != CQLValue::CIMObject_type)
|
661 karl 1.24 {
|
662 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
663 "Parameter $0 for function $1 has type $2."
664 " It must be type $3.",
665 "1",
|
666 karl 1.24 functionTypeToString(),
|
667 dave.sudlik 1.26 CQLValueRep::valueTypeToString(valType),
|
668 kumpf 1.27 "Reference, or Object");
|
669 karl 1.24 throw CQLRuntimeException(mload);
670 }
|
671 dave.sudlik 1.26
672 if (cqlVal.isNull())
673 {
674 return CQLValue(CIMValue(CIMTYPE_STRING, false));
675 }
676
677 if (valType == CQLValue::CIMReference_type)
678 {
679 PEG_METHOD_EXIT();
680 return CQLValue(cqlVal.getReference().toString());
681 }
682
683 // We have CIMObject now, convert to string.
684 PEG_METHOD_EXIT();
685 return CQLValue(cqlVal.getObject().getPath().toString());
|
686 lucier 1.4 }
687
|
688 kumpf 1.27 CQLValue CQLFunctionRep::className(
689 const CIMInstance& CI,
690 const QueryContext& queryCtx) const
|
691 lucier 1.4 {
|
692 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::className()");
693 int parmSize = _parms.size();
|
694 kumpf 1.27 if (parmSize != 0 && parmSize != 1)
|
695 karl 1.24 {
|
696 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
697 "Function $0 has $1 parameters."
698 " It must have between $2 and $3.",
|
699 karl 1.24 functionTypeToString(),
|
700 kumpf 1.27 _parms.size(),
701 "0", "1");
|
702 karl 1.24 throw CQLRuntimeException(mload);
703 }
|
704 lucier 1.4
|
705 karl 1.24 // If there are no parameters, the default behavior is to
706 // return the class name for the instance being examined (CI).
707 if (parmSize == 0)
708 {
709 PEG_METHOD_EXIT();
710 return CQLValue(CI.getClassName().getString());
711 }
|
712 lucier 1.4
|
713 karl 1.24 // We have a parameter, so resolve it first before we use it.
714 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
715 resolveValue(CI,queryCtx);
|
716 lucier 1.4
|
717 dave.sudlik 1.26 CQLValue::CQLValueType valType = cqlVal.getValueType();
718
719 if (valType != CQLValue::CIMReference_type &&
720 valType != CQLValue::CIMObject_type &&
721 valType != CQLValue::String_type)
722 {
723 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
724 "Parameter $0 for function $1 has type $2."
725 " It must be type $3.",
726 "1",
727 functionTypeToString(),
728 CQLValueRep::valueTypeToString(valType),
|
729 kumpf 1.27 "Reference, String, or Object");
|
730 dave.sudlik 1.26 throw CQLRuntimeException(mload);
731 }
732
733 if (cqlVal.isNull())
734 {
735 return CQLValue(CIMValue(CIMTYPE_STRING, false));
736 }
737
|
738 karl 1.24 // If we have a String parameter, then we'll use it to
739 // create a CIMObjectPath in order to verify the format is correct.
740 // We will then get the class from the object path and return it.
741 if (cqlVal.getValueType() == CQLValue::String_type)
742 {
743 CIMObjectPath objPath(cqlVal.getString());
744 PEG_METHOD_EXIT();
745 return CQLValue(objPath.getClassName().getString());
746 }
|
747 lucier 1.4
|
748 karl 1.24 // If we have a CIMReference parameter, then we will just get the class
749 // name from the reference and return it. A refernce is a CIMObjectPath.
750 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
751 {
752 PEG_METHOD_EXIT();
753 return CQLValue(cqlVal.getReference().getClassName().getString());
754 }
|
755 lucier 1.4
|
756 dave.sudlik 1.26 // We have a CIMObject, then we return the class name of the obejct
757 PEG_METHOD_EXIT();
758 return CQLValue(cqlVal.getObject().getClassName().getString());
|
759 lucier 1.4 }
760
|
761 kumpf 1.27 CQLValue CQLFunctionRep::nameSpaceName(
762 const CIMInstance& CI,
763 const QueryContext& queryCtx) const
|
764 chuck 1.3 {
|
765 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::nameSpaceName()");
|
766 kumpf 1.27 Uint32 parmSize = _parms.size();
767 if (parmSize != 0 && parmSize != 1)
|
768 karl 1.24 {
|
769 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
770 "Function $0 has $1 parameters."
771 " It must have between $2 and $3.",
|
772 karl 1.24 functionTypeToString(),
|
773 kumpf 1.27 _parms.size(),
774 "0", "1");
|
775 karl 1.24 throw CQLRuntimeException(mload);
776 }
|
777 lucier 1.4
|
778 karl 1.24 // The default beavior for this function will first look at the object path
779 // of the instance being examined (CI). If the path contains a namespace,
780 // we will return it. If it does not, then we will return the default
781 // namespace from the query context.
782 // *** NOTE *** This does not function entirely according to the CQL spec.
783 // The CQL spec says to return the namespace of the instance regardless
784 // if it is set or not. However, with the current implementation
785 // (CQL phase 1 PEP 193) we only operate a query engine within a single
786 // namespace and so we can assume the default namespace.
787 if (parmSize == 0)
788 {
789 CIMNamespaceName ns = CI.getPath().getNameSpace();
790 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
791 ns = queryCtx.getNamespace();
792 PEG_METHOD_EXIT();
|
793 kumpf 1.31 return CQLValue(ns.getString());
|
794 karl 1.24 }
|
795 lucier 1.4
|
796 karl 1.24 // We have a parameter, so resolve it first before we use it.
797 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
798 resolveValue(CI,queryCtx);
|
799 lucier 1.4
|
800 dave.sudlik 1.26 CQLValue::CQLValueType valType = cqlVal.getValueType();
801
802 if (valType != CQLValue::CIMReference_type &&
803 valType != CQLValue::CIMObject_type &&
804 valType != CQLValue::String_type)
805 {
806 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
807 "Parameter $0 for function $1 has type $2."
808 " It must be type $3.",
809 "1",
810 functionTypeToString(),
811 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
|
812 kumpf 1.27 "Reference, String, or Object");
|
813 dave.sudlik 1.26 throw CQLRuntimeException(mload);
814 }
815
816 if (cqlVal.isNull())
817 {
818 return CQLValue(CIMValue(CIMTYPE_STRING, false));
819 }
820
|
821 karl 1.24 // If we have a String parameter, then we'll use it to create a
822 // CIMObjectPath in order to verify the format is correct.
823 // We will then get the namespace from the object path and return it.
824 // If there is no namespace in the path given, then an empty string will
825 // be returned.
826 if (cqlVal.getValueType() == CQLValue::String_type)
827 {
828 CIMObjectPath objPath(cqlVal.getString());
829 PEG_METHOD_EXIT();
830 return CQLValue(objPath.getNameSpace().getString());
831 }
|
832 lucier 1.4
|
833 karl 1.24 // If we have a CIMReference parameter, then we will just get the
|
834 kumpf 1.31 // namespace name from the reference and return it. A refernce is a
|
835 karl 1.24 // CIMObjectPath. If there is no namespace in the path given, then
836 // an empty string will be returned.
837 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
838 {
839 PEG_METHOD_EXIT();
840 return CQLValue(cqlVal.getReference().getNameSpace().getString());
841 }
|
842 lucier 1.4
|
843 dave.sudlik 1.26 // We have a CIMObject, now we retrieve the path of the obejct and
|
844 karl 1.24 // check to see if it has a namespace set in it. If the path contains
845 // a namespace, we will return it. If it does not, then we will
846 // return the default namespace from the query context.
847 // *** NOTE *** This does not function entirely according to the CQL spec.
848 // The CQL spec says to return the namespace of the instance
849 // regardless if it is set or not. However, with the current
850 // implementation (CQL phase 1 PEP 193) we only operate a query
|
851 kumpf 1.31 // engine within a single namespace and so we can assume the default
852 // namespace.
|
853 dave.sudlik 1.26 CIMNamespaceName ns = cqlVal.getObject().getPath().getNameSpace();
854 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
855 ns = queryCtx.getNamespace();
856 PEG_METHOD_EXIT();
857 return CQLValue(ns.getString());
|
858 chuck 1.3 }
859
|
860 karl 1.24 CQLValue CQLFunctionRep::nameSpaceType(const CIMInstance& CI,
861 const QueryContext& queryCtx) const
|
862 chuck 1.3 {
|
863 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::nameSpaceType()");
|
864 kumpf 1.31 // This is currently (as of CQL Phase 1, PEP 193) not supported in
865 // Pegasus since Pegasus does not yet support WEBM URI references.
866 // Nothing in the current object path can be used to represent
|
867 karl 1.24 // the name space type (i.e. the protocol).
|
868 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
869 "Function $0 is not supported.",
|
870 karl 1.24 functionTypeToString());
871 throw CQLRuntimeException(mload);
|
872 kumpf 1.31
|
873 karl 1.24 PEGASUS_UNREACHABLE
874 (
875 int parmSize = _parms.size();
876 if(parmSize != 0 && parmSize != 1)
877 {
|
878 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
879 "Function $0 has $1 parameters."
880 " It must have between $2 and $3.",
|
881 karl 1.24 functionTypeToString(),
|
882 kumpf 1.27 _parms.size(),
883 "0", "1");
|
884 karl 1.24 throw CQLRuntimeException(mload);
885 }
|
886 kumpf 1.31
|
887 karl 1.24 PEG_METHOD_EXIT();
888 return CQLValue(Uint64(0));
889 ) // End PEGASUS_UNREACHABLE
890 }
891
|
892 kumpf 1.27 CQLValue CQLFunctionRep::hostPort(
893 const CIMInstance& CI,
894 const QueryContext& queryCtx) const
|
895 karl 1.24 {
896 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::hostPort()");
|
897 kumpf 1.31 // Pegasus currently (as of CQL Phase 1, PEP 193) does not
898 // support WEBM URI references, however the current object
899 // path does have a host on it which we will return. Until
900 // Pegasus supports WBEM URI, it is not guaranteed that this
|
901 kumpf 1.27 // will conform to the format defined in WBEM URI, and therefore
|
902 karl 1.24 // this function is not entirely in accordance with the CQL Specification.
903 // In addition, the CQL specification allows for the parameter
|
904 kumpf 1.31 // to be left off when the query is executed as a result of
|
905 karl 1.24 // an ExecuteQuery operation. However, right now
906 // (as of CQL Phase 1, PEP 193) we are only using this for
907 // Indications, and so we are assuming a "Mode" of operation.
908 // For this function to be completely compliant with the CQL
909 // specification, it will eventually need to be "mode" aware.
|
910 kumpf 1.31
|
911 kumpf 1.27 if (_parms.size() != 1)
|
912 karl 1.24 {
|
913 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
914 "Function $0 has $1 parameters."
915 " It must have between $2 and $3.",
|
916 karl 1.24 functionTypeToString(),
|
917 kumpf 1.27 _parms.size(),
918 "1", "1");
|
919 karl 1.24 throw CQLRuntimeException(mload);
920 }
|
921 lucier 1.4
|
922 karl 1.24 // We have a parameter, so resolve it first before we use it.
923 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
924 resolveValue(CI,queryCtx);
|
925 dave.sudlik 1.26
926 CQLValue::CQLValueType valType = cqlVal.getValueType();
927
928 if (valType != CQLValue::CIMReference_type &&
929 valType != CQLValue::CIMObject_type &&
930 valType != CQLValue::String_type)
931 {
932 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
933 "Parameter $0 for function $1 has type $2."
934 " It must be type $3.",
|
935 kumpf 1.27 "1",
|
936 dave.sudlik 1.26 functionTypeToString(),
937 CQLValueRep::valueTypeToString(valType),
|
938 kumpf 1.27 "Reference, String, or Object");
|
939 dave.sudlik 1.26 throw CQLRuntimeException(mload);
940 }
941
942 if (cqlVal.isNull())
943 {
944 return CQLValue(CIMValue(CIMTYPE_STRING, false));
945 }
|
946 kumpf 1.31
947 // If we have a String parameter, then we'll use it to create a
|
948 karl 1.24 // CIMObjectPath in order to verify the format is correct. We will
949 // then get the host from the object path and return it. If there
950 // is no host in the path given, then an empty string will be returned.
951 if (cqlVal.getValueType() == CQLValue::String_type)
952 {
953 CIMObjectPath objPath(cqlVal.getString());
954 PEG_METHOD_EXIT();
955 return CQLValue(objPath.getHost());
956 }
|
957 lucier 1.4
|
958 kumpf 1.31 // If we have a CIMReference parameter, then we will just get the
|
959 karl 1.24 // host name from the reference and return it. A reference is a
960 // CIMObjectPath. If there is no host in the path given, then
961 // an empty string will be returned.
962 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
963 {
964 PEG_METHOD_EXIT();
965 return CQLValue(cqlVal.getReference().getHost());
966 }
|
967 lucier 1.4
|
968 dave.sudlik 1.26 // We have a CIMObject, now we retrieve the path of the obejct
|
969 karl 1.24 // and return the host from the path. If there is no host in the
970 // path given, then an empty string will be returned.
|
971 dave.sudlik 1.26 PEG_METHOD_EXIT();
972 return CQLValue(cqlVal.getObject().getPath().getHost());
|
973 chuck 1.3 }
974
|
975 kumpf 1.27 CQLValue CQLFunctionRep::modelPath(
976 const CIMInstance& CI,
977 const QueryContext& queryCtx) const
|
978 chuck 1.3 {
|
979 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::modelPath()");
|
980 kumpf 1.31 // This method returns the model path portion of an object path.
|
981 karl 1.24 // The model path is the class name and the key bindings (if included)..
|
982 kumpf 1.31
|
983 kumpf 1.27 Uint32 parmSize = _parms.size();
984 if (parmSize != 0 && parmSize != 1)
|
985 karl 1.24 {
|
986 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
987 "Function $0 has $1 parameters."
988 " It must have between $2 and $3.",
|
989 karl 1.24 functionTypeToString(),
|
990 kumpf 1.27 _parms.size(),
991 "0", "1");
|
992 karl 1.24 throw CQLRuntimeException(mload);
993 }
|
994 lucier 1.4
|
995 kumpf 1.31 // The default behavior for this function will be to retrieve
996 // the object path from the instance being examined (CI) and
|
997 karl 1.24 // then return the model path from that.
998 if (parmSize == 0)
999 {
1000 PEG_METHOD_EXIT();
1001 return buildModelPath(CI.getPath());
1002 }
|
1003 lucier 1.4
|
1004 karl 1.24 // We have a parameter, so resolve it first before we use it.
1005 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1006 resolveValue(CI,queryCtx);
|
1007 dave.sudlik 1.26
1008 CQLValue::CQLValueType valType = cqlVal.getValueType();
1009
1010 if (valType != CQLValue::CIMReference_type &&
1011 valType != CQLValue::CIMObject_type &&
1012 valType != CQLValue::String_type)
1013 {
1014 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1015 "Parameter $0 for function $1 has type $2."
1016 " It must be type $3.",
1017 "1",
1018 functionTypeToString(),
1019 CQLValueRep::valueTypeToString(valType),
|
1020 kumpf 1.27 "Reference, String, or Object");
|
1021 dave.sudlik 1.26 throw CQLRuntimeException(mload);
1022 }
1023
1024 if (cqlVal.isNull())
1025 {
1026 return CQLValue(CIMValue(CIMTYPE_REFERENCE, false));
1027 }
|
1028 kumpf 1.31
1029 // If we have a String parameter, then we'll use it to create a
1030 // CIMObjectPath in order to verify the format is correct.
|
1031 karl 1.24 // We will then get model path from the object path and return it.
1032 if (cqlVal.getValueType() == CQLValue::String_type)
1033 {
1034 CIMObjectPath objPath(cqlVal.getString());
1035 PEG_METHOD_EXIT();
1036 return buildModelPath(objPath);
1037 }
|
1038 lucier 1.4
|
1039 kumpf 1.31 // If we have a CIMReference parameter, then we will get the model
1040 // path from the reference and return it. A reference is a
|
1041 karl 1.24 // CIMObjectPath.
1042 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
1043 {
1044 PEG_METHOD_EXIT();
1045 return buildModelPath(cqlVal.getReference());
1046 }
|
1047 lucier 1.4
|
1048 kumpf 1.31 // We have a CIMObject, now we retrieve the path of the obejct
|
1049 karl 1.24 // and return the model path.
|
1050 dave.sudlik 1.26 PEG_METHOD_EXIT();
1051 return buildModelPath(cqlVal.getObject().getPath());
|
1052 chuck 1.3 }
1053
|
1054 lucier 1.4 CQLValue CQLFunctionRep::buildModelPath(const CIMObjectPath& objPath) const
|
1055 chuck 1.3 {
|
1056 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildModelPath()");
|
1057 kumpf 1.31 // This method will take an existing objet path, pick out the key
1058 // bindings and the class name, and use those parts to build a new
1059 // object path with just those parts in it. This is used to
|
1060 karl 1.24 // represent the model path.
1061 CIMObjectPath newPath;
1062 newPath.setClassName(objPath.getClassName());
1063 newPath.setKeyBindings(objPath.getKeyBindings());
1064 //printf("ModelPath --> %s\n", (const char *)newPath.toString().
|
1065 kumpf 1.31 // getCString());
|
1066 karl 1.24 PEG_METHOD_EXIT();
1067 return CQLValue(newPath.toString());
1068 }
1069
|
1070 kumpf 1.27 CQLValue CQLFunctionRep::classPath(
1071 const CIMInstance& CI,
1072 const QueryContext& queryCtx) const
|
1073 karl 1.24 {
1074 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::classPath()");
1075 // This method returns a class path. The class path will only have
1076 // a namespace and a class name in it. All other path information
|
1077 kumpf 1.31 // will be stripped off.
|
1078 kumpf 1.27 Uint32 parmSize = _parms.size();
1079 if (parmSize != 0 && parmSize != 1)
|
1080 karl 1.24 {
|
1081 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1082 "Function $0 has $1 parameters."
1083 " It must have between $2 and $3.",
|
1084 karl 1.24 functionTypeToString(),
|
1085 kumpf 1.27 _parms.size(),
1086 "0", "1");
|
1087 karl 1.24 throw CQLRuntimeException(mload);
1088 }
|
1089 chuck 1.3
|
1090 kumpf 1.31 // The default behavior for this function will be to retrieve the
1091 // object path from the instance being examined (CI) and build the
1092 // class path from it. If the path does not have a namespace, then
|
1093 karl 1.24 // the default namespace is used.
1094 if (parmSize == 0)
1095 {
1096 CIMObjectPath objPath(CI.getPath());
1097 CIMNamespaceName ns = objPath.getNameSpace();
1098 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
1099 ns = queryCtx.getNamespace();
1100 PEG_METHOD_EXIT();
1101 return buildClassPath(objPath, ns);
1102 }
|
1103 lucier 1.4
|
1104 karl 1.24 // We have a parameter, so resolve it first before we use it.
1105 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1106 resolveValue(CI,queryCtx);
|
1107 dave.sudlik 1.26
1108 CQLValue::CQLValueType valType = cqlVal.getValueType();
1109
1110 if (valType != CQLValue::CIMReference_type &&
1111 valType != CQLValue::CIMObject_type &&
1112 valType != CQLValue::String_type)
1113 {
1114 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1115 "Parameter $0 for function $1 has type $2."
1116 " It must be type $3.",
1117 "1",
1118 functionTypeToString(),
1119 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
|
1120 kumpf 1.27 "Reference, String, or Object");
|
1121 dave.sudlik 1.26 throw CQLRuntimeException(mload);
1122 }
1123
1124 if (cqlVal.isNull())
1125 {
1126 return CQLValue(CIMValue(CIMTYPE_REFERENCE, false));
1127 }
|
1128 kumpf 1.31
1129 // If we have a String parameter, then we'll use it to create a
1130 // CIMObjectPath in order to verify the format is correct. We will
1131 // then build the class path from the object path and return it.
1132 // If the namespace is NOT set in the object path, it will remain
|
1133 karl 1.24 // unset in the returned reference.
1134 if (cqlVal.getValueType() == CQLValue::String_type)
1135 {
1136 CIMObjectPath objPath(cqlVal.getString());
1137 PEG_METHOD_EXIT();
1138 return buildClassPath(objPath, objPath.getNameSpace());
1139 }
|
1140 lucier 1.4
|
1141 kumpf 1.31 // If we have a CIMReference parameter, then we will build the class
1142 // path from the reference and return it. If the namespace is NOT
|
1143 karl 1.24 // set in the object path, it will remain unset in the returned reference.
1144 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
1145 {
1146 CIMObjectPath objPath = cqlVal.getReference();
1147 PEG_METHOD_EXIT();
1148 return buildClassPath(objPath, objPath.getNameSpace());
1149 }
|
1150 lucier 1.4
|
1151 kumpf 1.31 // We have a CIMObject, now we retrieve the object path and
|
1152 karl 1.24 // build the class path from it. If the path does not have a namespace,
1153 // then the default namespace is used.
|
1154 dave.sudlik 1.26 CIMObjectPath objPath = cqlVal.getObject().getPath();
1155 CIMNamespaceName ns = objPath.getNameSpace();
1156 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
|
1157 karl 1.24 {
|
1158 dave.sudlik 1.26 ns = queryCtx.getNamespace();
|
1159 karl 1.24 }
|
1160 dave.sudlik 1.26 PEG_METHOD_EXIT();
1161 return buildClassPath(objPath, ns);
|
1162 chuck 1.3 }
1163
|
1164 karl 1.24 CQLValue CQLFunctionRep::buildClassPath(const CIMObjectPath& objPath,
1165 const CIMNamespaceName& ns) const
|
1166 chuck 1.3 {
|
1167 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildClassPath()");
1168 // This method will take the object path pass in and pick out the host,
|
1169 kumpf 1.31 // the class name and the namespace. The 2 parts are then combined
1170 // together into a new object path which will be used as the class
|
1171 karl 1.24 // path and returned.
1172 CIMObjectPath newPath;
1173 newPath.setHost(objPath.getHost());
|
1174 kumpf 1.31 newPath.setClassName(objPath.getClassName());
|
1175 karl 1.24 newPath.setNameSpace(ns);
1176 // printf("ClassPath --> %s\n", (const char *)newPath.toString().
1177 // getCString());
1178 PEG_METHOD_EXIT();
1179 return CQLValue(newPath);
|
1180 chuck 1.3 }
1181
|
1182 lucier 1.4
|
1183 kumpf 1.27 CQLValue CQLFunctionRep::objectPath(
1184 const CIMInstance& CI,
1185 const QueryContext& queryCtx) const
|
1186 karl 1.24 {
1187 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::objectPath()");
1188 // This method returns an object path. The object path will only have a
|
1189 kumpf 1.31 // namespace, a class name, and key bindings if it is a path to an
|
1190 karl 1.24 // instance. All other path information will be stripped off.
|
1191 kumpf 1.31
|
1192 kumpf 1.27 Uint32 parmSize = _parms.size();
1193 if (parmSize != 0 && parmSize != 1)
|
1194 karl 1.24 {
|
1195 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1196 "Function $0 has $1 parameters."
1197 " It must have between $2 and $3.",
|
1198 karl 1.24 functionTypeToString(),
|
1199 kumpf 1.27 _parms.size(),
1200 "0", "1");
|
1201 karl 1.24 throw CQLRuntimeException(mload);
1202 }
|
1203 lucier 1.4
|
1204 karl 1.24 // The default behavior for this function will be to retrieve the
|
1205 kumpf 1.31 // object path from the instance being examined (CI) and build the
1206 // object path from it. If the path does not have a namespace,
|
1207 karl 1.24 // then the default namespace is used.
1208 if (parmSize == 0)
1209 {
1210 CIMObjectPath objPath(CI.getPath());
1211 CIMNamespaceName ns = objPath.getNameSpace();
1212 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
1213 ns = queryCtx.getNamespace();
1214 PEG_METHOD_EXIT();
1215 return buildObjectPath(objPath, ns);
1216 }
|
1217 lucier 1.4
|
1218 karl 1.24 // We have a parameter, so resolve it first before we use it.
1219 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1220 resolveValue(CI,queryCtx);
|
1221 dave.sudlik 1.26
1222 CQLValue::CQLValueType valType = cqlVal.getValueType();
1223
1224 if (valType != CQLValue::CIMReference_type &&
1225 valType != CQLValue::CIMObject_type &&
1226 valType != CQLValue::String_type)
1227 {
1228 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1229 "Parameter $0 for function $1 has type $2."
1230 " It must be type $3.",
|
1231 kumpf 1.27 "1",
|
1232 dave.sudlik 1.26 functionTypeToString(),
1233 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
|
1234 kumpf 1.27 "Reference, String, or Object");
|
1235 dave.sudlik 1.26 throw CQLRuntimeException(mload);
1236 }
1237
1238 if (cqlVal.isNull())
1239 {
1240 return CQLValue(CIMValue(CIMTYPE_REFERENCE, false));
1241 }
|
1242 kumpf 1.31
1243 // If we have a String parameter, then we'll use it to create a
1244 // CIMObjectPath in order to verify the format is correct.
1245 // We will then build the object path from the object path and return it.
1246 // If the namespace is NOT set in the object path, it will remain
|
1247 karl 1.24 // unset in the returned reference.
1248 if (cqlVal.getValueType() == CQLValue::String_type)
1249 {
1250 CIMObjectPath objPath(cqlVal.getString());
1251 PEG_METHOD_EXIT();
1252 return buildObjectPath(objPath, objPath.getNameSpace());
1253 }
|
1254 kumpf 1.31
1255 // If we have a CIMReference parameter, then we will build the object
1256 // path from the reference and return it. If the namespace is NOT
|
1257 karl 1.24 // set in the object path, it will remain unset in the returned reference.
1258 if (cqlVal.getValueType() == CQLValue::CIMReference_type)
1259 {
1260 CIMObjectPath objPath = cqlVal.getReference();
1261 PEG_METHOD_EXIT();
1262 return buildObjectPath(objPath, objPath.getNameSpace());
1263 }
|
1264 lucier 1.4
|
1265 kumpf 1.31 // We have a CIMObject, now we retrieve the object path of the
1266 // obejct and build the object path from it. If the path does not
|
1267 karl 1.24 // have a namespace, then the default namespace is used.
|
1268 dave.sudlik 1.26 CIMObjectPath objPath = cqlVal.getObject().getPath();
1269 CIMNamespaceName ns = objPath.getNameSpace();
1270 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
|
1271 karl 1.24 {
|
1272 dave.sudlik 1.26 ns = queryCtx.getNamespace();
|
1273 karl 1.24 }
|
1274 dave.sudlik 1.26 PEG_METHOD_EXIT();
1275 return buildObjectPath(objPath, ns);
|
1276 chuck 1.3 }
1277
|
1278 karl 1.24 CQLValue CQLFunctionRep::buildObjectPath(const CIMObjectPath& objPath,
1279 const CIMNamespaceName& ns) const
|
1280 chuck 1.3 {
|
1281 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::buildObjectPath()");
1282 // This method will take the object path passed in and pick out the host,
|
1283 kumpf 1.31 // the class name, the namespace, and the key bindings. The parts are
1284 // then combined together into a new object path which will be used
|
1285 karl 1.24 // as the object path and returned.
1286 CIMObjectPath newPath;
1287 newPath.setHost(objPath.getHost());
|
1288 kumpf 1.31 newPath.setClassName(objPath.getClassName());
|
1289 karl 1.24 newPath.setNameSpace(ns);
1290 newPath.setKeyBindings(objPath.getKeyBindings());
1291 PEG_METHOD_EXIT();
1292 return CQLValue(newPath);
1293 }
1294
|
1295 kumpf 1.27 CQLValue CQLFunctionRep::instanceToReference(
1296 const CIMInstance& CI,
1297 const QueryContext& queryCtx) const
|
1298 karl 1.24 {
1299 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::instanceToReference()");
|
1300 kumpf 1.31 // The parameter to this function MUST be an instance object.
1301 // We will use buildPath on the instance to make the path.
|
1302 karl 1.24 // If there is no namespace on the instance, then the default namespace
|
1303 kumpf 1.31 // will be inserted. The completed path is then returned.
1304 // Note, this could, and should be a more complete reference
|
1305 karl 1.24 // than the other path functions.
|
1306 kumpf 1.31
|
1307 kumpf 1.27 Uint32 parmSize = _parms.size();
1308 if (parmSize != 0 && parmSize != 1)
|
1309 karl 1.24 {
|
1310 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1311 "Function $0 has $1 parameters."
1312 " It must have between $2 and $3.",
|
1313 karl 1.24 functionTypeToString(),
|
1314 kumpf 1.27 _parms.size(),
1315 "0", "1");
|
1316 karl 1.24 throw CQLRuntimeException(mload);
1317 }
1318 CIMInstance *inst = NULL;
1319 Boolean cleanup = false; // whether or not to delete the memory
1320 CIMObject obj;
|
1321 kumpf 1.31
1322 // The default behavior is to use the instance being examined
|
1323 karl 1.24 // as the source instance (CI).
1324 if (parmSize == 0)
1325 inst = (CIMInstance *)&CI;
1326 else
|
1327 lucier 1.8 {
|
1328 karl 1.24 // We have a parameter, so resolve it first before we use it.
1329 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1330 resolveValue(CI,queryCtx);
|
1331 dave.sudlik 1.26
|
1332 karl 1.24 // Parameter MUST be an instance object
1333 if (cqlVal.getValueType() != CQLValue::CIMObject_type)
1334 {
|
1335 kumpf 1.27 MessageLoaderParms mload(
1336 "CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1337 "Parameter $0 for function $1 has type $2."
1338 " It must be type $3.",
1339 "1",
1340 functionTypeToString(),
1341 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
1342 CQLValueRep::valueTypeToString(CQLValue::CIMObject_type));
|
1343 karl 1.24 throw CQLRuntimeException(mload);
1344 }
1345
|
1346 dave.sudlik 1.26 if (cqlVal.isNull())
1347 {
1348 return CQLValue(CIMValue(CIMTYPE_REFERENCE, false));
1349 }
|
1350 kumpf 1.31
|
1351 karl 1.24 // REVIEW question. Inefficient since the CIMobject is copied
|
1352 kumpf 1.31 // via the return by value, then it is copied again via the
|
1353 karl 1.24 // assignment. Is there a better way to handle this?
1354 obj = cqlVal.getObject();
1355 if (!obj.isInstance())
1356 {
|
1357 kumpf 1.27 MessageLoaderParms mload(
1358 "CQL.CQLFunctionRep.INVALID_OBJECT_TYPE",
1359 "Parameter $0 for function $1 must be a CIM instance.",
1360 "1",
1361 functionTypeToString());
|
1362 karl 1.24 throw CQLRuntimeException(mload);
1363 }
1364 // Make a CIM Instance
1365 inst = new CIMInstance(obj);
1366 cleanup = true;
1367 }
|
1368 kumpf 1.31
|
1369 karl 1.24 // Get the class and build the path
1370 CIMConstClass cls = queryCtx.getClass(inst->getClassName());
1371 CIMObjectPath objPath = inst->buildPath(cls);
1372 CIMNamespaceName ns = objPath.getNameSpace();
|
1373 lucier 1.5
|
1374 karl 1.24 if (ns.isNull() || String::equal(ns.getString(), String::EMPTY))
1375 objPath.setNameSpace(queryCtx.getNamespace());
|
1376 kumpf 1.31
|
1377 karl 1.24 if (cleanup)
1378 {
1379 delete inst;
1380 inst = NULL;
1381 }
1382 PEG_METHOD_EXIT();
1383 return CQLValue(objPath);
|
1384 chuck 1.3 }
1385
|
1386 lucier 1.4 CQLValue CQLFunctionRep::currentDateTime() const
|
1387 chuck 1.3 {
|
1388 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::currentDateTime()");
|
1389 kumpf 1.27 if (_parms.size() != 0)
|
1390 karl 1.24 {
|
1391 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1392 "Function $0 has $1 parameters."
1393 " It must have between $2 and $3.",
|
1394 karl 1.24 functionTypeToString(),
|
1395 kumpf 1.27 _parms.size(),
1396 "0", "0");
|
1397 karl 1.24 throw CQLRuntimeException(mload);
1398 }
|
1399 lucier 1.4
|
1400 karl 1.24 PEG_METHOD_EXIT();
1401 return(CQLValue(CIMDateTime::getCurrentDateTime()));
|
1402 chuck 1.3 }
1403
|
1404 kumpf 1.27 CQLValue CQLFunctionRep::dateTime(
1405 const CIMInstance& CI,
1406 const QueryContext& queryCtx) const
|
1407 chuck 1.3 {
|
1408 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::dateTime()");
|
1409 kumpf 1.27 if (_parms.size() != 1)
|
1410 karl 1.24 {
|
1411 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1412 "Function $0 has $1 parameters."
1413 " It must have between $2 and $3.",
|
1414 karl 1.24 functionTypeToString(),
|
1415 kumpf 1.27 _parms.size(),
1416 "1", "1");
|
1417 karl 1.24 throw CQLRuntimeException(mload);
1418 }
|
1419 kumpf 1.31
|
1420 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
|
1421 kumpf 1.31 resolveValue(CI,queryCtx);
|
1422 dave.sudlik 1.26
|
1423 karl 1.24 if(cqlVal.getValueType() != CQLValue::String_type)
1424 {
|
1425 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1426 "Parameter $0 for function $1 has type $2."
1427 " It must be type $3.",
1428 "1",
|
1429 karl 1.24 functionTypeToString(),
1430 CQLValueRep::valueTypeToString(cqlVal.getValueType()),
1431 CQLValueRep::valueTypeToString(CQLValue::String_type));
1432 throw CQLRuntimeException(mload);
1433 }
|
1434 dave.sudlik 1.26
1435 if (cqlVal.isNull())
1436 {
1437 return CQLValue(CIMValue(CIMTYPE_DATETIME, false));
1438 }
|
1439 kumpf 1.31
|
1440 karl 1.24 CIMDateTime dt(cqlVal.getString());
1441 PEG_METHOD_EXIT();
1442 return(CQLValue(dt));
|
1443 chuck 1.3 }
1444
|
1445 karl 1.24 CQLValue CQLFunctionRep::microsecondToTimestamp(const CIMInstance& CI,
1446 const QueryContext& queryCtx) const
|
1447 chuck 1.3 {
|
1448 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::microsecondToTimestamp()");
1449 if(_parms.size() != 1)
1450 {
|
1451 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_COUNT",
1452 "Function $0 has $1 parameters."
1453 " It must have between $2 and $3.",
|
1454 karl 1.24 functionTypeToString(),
|
1455 kumpf 1.27 _parms.size(),
1456 "1", "1");
|
1457 karl 1.24 throw CQLRuntimeException(mload);
1458 }
|
1459 lucier 1.4
|
1460 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1461 resolveValue(CI,queryCtx);
|
1462 dave.sudlik 1.26
|
1463 kumpf 1.31 CQLValue::CQLValueType valType = cqlVal.getValueType();
|
1464 karl 1.24 if(valType != CQLValue::Uint64_type &&
1465 valType != CQLValue::Sint64_type)
1466 {
|
1467 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1468 "Parameter $0 for function $1 has type $2."
1469 " It must be type $3.",
1470 "1",
|
1471 karl 1.24 functionTypeToString(),
|
1472 dave.sudlik 1.26 CQLValueRep::valueTypeToString(valType),
|
1473 kumpf 1.27 "Integer");
|
1474 karl 1.24 throw CQLRuntimeException(mload);
1475 }
|
1476 dave.sudlik 1.26
1477 if (cqlVal.isNull())
1478 {
1479 return CQLValue(CIMValue(CIMTYPE_UINT64, false));
1480 }
|
1481 kumpf 1.31
|
1482 karl 1.24 Uint64 uIntVal = 0;
1483 if (valType == CQLValue::Sint64_type)
|
1484 lucier 1.4 {
|
1485 karl 1.24 Sint64 intVal = cqlVal.getSint();
1486 if (intVal < 0)
1487 {
|
1488 kumpf 1.27 MessageLoaderParms mload(
1489 "CQL.CQLFunctionRep.NEGATIVE_INT_ERROR",
1490 "Parameter $0 for function $1 has a value of $2."
1491 " It must be non-negative.",
1492 "1",
1493 functionTypeToString(),
1494 intVal);
1495 throw CQLRuntimeException(mload);
|
1496 karl 1.24 }
1497 uIntVal = intVal;
|
1498 lucier 1.4 }
|
1499 karl 1.24 else
1500 uIntVal = cqlVal.getUint();
|
1501 kumpf 1.31
|
1502 karl 1.24 PEG_METHOD_EXIT();
|
1503 kumpf 1.31
|
1504 karl 1.24 return CQLValue(CIMDateTime(uIntVal, false));
|
1505 chuck 1.3 }
1506
|
1507 karl 1.24 CQLValue CQLFunctionRep::microsecondToInterval(const CIMInstance& CI,
1508 const QueryContext& queryCtx) const
|
1509 chuck 1.3 {
|
1510 karl 1.24 PEG_METHOD_ENTER(TRC_CQL,"CQLFunctionRep::microsecondToInterval()");
1511 if(_parms.size() != 1)
1512 {
|
1513 kumpf 1.27 MessageLoaderParms mload(
1514 "CQL.CQLFunctionRep.INVALID_PARM_COUNT",
|
1515 karl 1.25 "Function $0 has $1 parameters."
1516 " It must have between $2 and $3.",
|
1517 karl 1.24 functionTypeToString(),
|
1518 kumpf 1.27 _parms.size(),
1519 "1", "1");
|
1520 karl 1.24 throw CQLRuntimeException(mload);
1521 }
|
1522 kumpf 1.31
|
1523 karl 1.24 CQLValue cqlVal = _parms[0].getSimplePredicate().getLeftExpression().
1524 resolveValue(CI,queryCtx);
|
1525 dave.sudlik 1.26
|
1526 kumpf 1.31 CQLValue::CQLValueType valType = cqlVal.getValueType();
|
1527 karl 1.24 if(valType != CQLValue::Uint64_type &&
|
1528 lucier 1.4 valType != CQLValue::Sint64_type)
1529 {
|
1530 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.INVALID_PARM_TYPE",
1531 "Parameter $0 for function $1 has type $2."
1532 " It must be type $3.",
1533 "1",
|
1534 karl 1.24 functionTypeToString(),
|
1535 dave.sudlik 1.26 CQLValueRep::valueTypeToString(valType),
|
1536 kumpf 1.27 "Integer");
|
1537 karl 1.24 throw CQLRuntimeException(mload);
1538 }
|
1539 dave.sudlik 1.26
1540 if (cqlVal.isNull())
1541 {
1542 return CQLValue(CIMValue(CIMTYPE_UINT64, false));
1543 }
|
1544 kumpf 1.31
|
1545 karl 1.24 Uint64 uIntVal = 0;
|
1546 kumpf 1.31
|
1547 karl 1.24 if (valType == CQLValue::Sint64_type)
1548 {
1549 Sint64 intVal = cqlVal.getSint();
1550 if (intVal < 0)
1551 {
|
1552 karl 1.25 MessageLoaderParms mload("CQL.CQLFunctionRep.NEGATIVE_INT_ERROR",
1553 "Parameter $0 for function $1 has a value of $2."
1554 " It must be non-negative.",
1555 "1",
|
1556 karl 1.24 functionTypeToString(),
|
1557 kumpf 1.27 intVal);
|
1558 karl 1.24 throw CQLRuntimeException(mload);
1559 }
1560 uIntVal = intVal;
|
1561 lucier 1.4 }
|
1562 karl 1.24 else
|
1563 kumpf 1.27 uIntVal = cqlVal.getUint();
|
1564 kumpf 1.31
|
1565 karl 1.24 PEG_METHOD_EXIT();
|
1566 kumpf 1.31 return CQLValue(CIMDateTime(uIntVal, true));
|
1567 chuck 1.3 }
1568
|
1569 humberto 1.1 PEGASUS_NAMESPACE_END
|