📄 cqlcli.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/FileSystem.h>#include <stdio.h>#include <iostream>#include <fstream>#include <string.h>#include <Pegasus/Common/String.h>#include <Pegasus/CQL/CQLParser.h>#include <Pegasus/CQL/CQLParserState.h>#include <Pegasus/CQL/CQLSelectStatement.h>#include <Pegasus/Repository/RepositoryQueryContext.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Repository/CIMRepository.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/CIMObjectPath.h>#define PEGASUS_SINT64_MIN (PEGASUS_SINT64_LITERAL(0x8000000000000000))#define PEGASUS_UINT64_MAX PEGASUS_UINT64_LITERAL(0xFFFFFFFFFFFFFFFF)#define PEGASUS_SINT64_MAX (PEGASUS_SINT64_LITERAL(0x7FFFFFFFFFFFFFFF))PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;int CQL_parse();Boolean cqlcli_verbose = false;void hackInstances(Array<CIMInstance>& instances){ for (Uint32 i=0; i < instances.size(); i++) { CIMInstance inst = instances[i]; // Only hack it if it is an instance of CQL_TestPropertyTypes if (inst.getClassName() == "CQL_TestPropertyTypes") { // The properties which the mof compiler messes up will be removed and added manually. // Start with Instance #1 Uint64 instID; inst.getProperty(inst.findProperty("InstanceID")).getValue().get(instID); if (instID == 1) { // The stupid mof compiler loses the negative on floats. // PropertyReal32 = -32.0 inst.removeProperty(inst.findProperty("PropertyReal32")); Real32 real32Val = -32.0; inst.addProperty(CIMProperty("PropertyReal32", CIMValue(real32Val))); // PropertySint64Lower = -9223372036854775808 inst.removeProperty(inst.findProperty("PropertySint64Lower")); Sint64 sint64Val = PEGASUS_SINT64_MIN; inst.addProperty(CIMProperty("PropertySint64Lower", CIMValue(sint64Val))); // PropertySint64Upper = 9223372036854775807 inst.removeProperty(inst.findProperty("PropertySint64Upper")); sint64Val = PEGASUS_SINT64_MAX; inst.addProperty(CIMProperty("PropertySint64Upper", CIMValue(sint64Val))); } // Then do Instance #2 else if (instID == 2) { } } }}String getStatementString(const String& stmt){ // Returns the select statement string, but takes // non-ascii chars (> 0x7f) into account by turning // them into hex strings. // This is needed because some tests contain // non-ascii in their select statements, and we // want a consistent output on all platforms. String res; for (Uint32 i = 0, n = stmt.size(); i < n; i++) { Uint16 code = stmt[i]; if (code <= PEGASUS_MAX_PRINTABLE_CHAR) { res.append((char)code); } else { // turn into hex format: char hex[8]; sprintf(hex, "\\x%04X", code); res.append(hex); } } return res;}void printProperty(CIMProperty& prop, Uint32 propNum, String& prefix){ // Recursive function to handle embedded object trees cout << prefix << "Prop #" << propNum << " Name = " << prop.getName().getString(); CIMValue val = prop.getValue();#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT CIMType valType = val.getType(); if (valType != CIMTYPE_OBJECT && valType != CIMTYPE_INSTANCE)#else if (val.getType() != CIMTYPE_OBJECT)#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT { // Not embedded object if (val.isNull()) { cout << ", Value = NULL" << endl; } else { cout << ", Value = " << val.toString() << endl; } } else { // Embedded object, or array of objects Array<CIMObject> embObjs;#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT if (val.isArray()) { if(valType == CIMTYPE_INSTANCE) { Array<CIMInstance> embInsts; val.get(embInsts); int instCount = embInsts.size(); for(int i = 0; i < instCount; i++) { embObjs.append((CIMObject)embInsts[i]); } } else { val.get(embObjs); } } else { if(valType == CIMTYPE_INSTANCE) { CIMInstance tmpInst; val.get(tmpInst); embObjs.append((CIMObject)tmpInst); } else { CIMObject tmpObj; val.get(tmpObj); embObjs.append(tmpObj); } }#else if (val.isArray()) { val.get(embObjs); } else { CIMObject tmpObj; val.get(tmpObj); embObjs.append(tmpObj); }#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT for (Uint32 j = 0; j < embObjs.size(); j++) { CIMObject embObj = embObjs[j]; if (embObj.isClass()) { // Embedded class CIMClass embCls(embObj); cout << ", Value = class of " << embCls.getClassName().getString() << endl; } else { // Embedded instance, need to recurse on each property CIMInstance embInst(embObj); String newPrefix = prefix; newPrefix.append(prefix); cout << endl << newPrefix << "Instance of class " << embInst.getClassName().getString() << endl; Uint32 cnt = embInst.getPropertyCount(); if (cnt == 0) { cout << newPrefix << "No properties left after projection" << endl; } if (cnt > 10 && !cqlcli_verbose) { cout << newPrefix << "Instance has " << cnt << " properties" << endl; } else { for (Uint32 n = 0; n < cnt; n++) { CIMProperty prop = embInst.getProperty(n); printProperty(prop, n, newPrefix); } } } } }}Boolean _applyProjection(Array<CQLSelectStatement>& _statements, Array<CIMInstance>& _instances, String testOption){ if(testOption == String::EMPTY || testOption == "2") { cout << "========Apply Projection Results========" << endl; for(Uint32 i = 0; i < _statements.size(); i++) { cout << "======================================" << i << endl; cout << _statements[i].toString() << endl; for(Uint32 j = 0; j < _instances.size(); j++) { cout << "Instance of class " << _instances[j].getClassName().getString() << endl; try { CIMInstance projInst = _instances[j].clone(); // Remove the property "MissingProperty" for the // testcases that depend on the property being missing. Uint32 missing = projInst.findProperty("MissingProperty"); if (missing != PEG_NOT_FOUND) { projInst.removeProperty(missing); } CIMInstance cloneInst = projInst.clone(); Boolean gotPropExc = false; try { _statements[i].applyProjection(projInst, false); } catch (QueryRuntimePropertyException & qrpe) { // Got a missing property exception. cout << "-----" << qrpe.getMessage() << endl; gotPropExc = true; } if (gotPropExc) { // Got a missing property exception. // Try again, allowing missing properties. // Need to use a cloned instance because the original instance // was partially projected. cout << "Instance of class " << _instances[j].getClassName().getString() << ". Allow missing properties." << endl; projInst = cloneInst; _statements[i].applyProjection(projInst, true); } Uint32 cnt = projInst.getPropertyCount(); if (cnt == 0) { cout << "-----No properties left after projection" << endl; } String prefix("-----"); if (cnt > 10 && !cqlcli_verbose) { cout << "-----Instance has " << cnt << " properties" << endl; } else { for (Uint32 n = 0; n < cnt; n++) { CIMProperty prop = projInst.getProperty(n); printProperty(prop, n, prefix); } } } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} } } } return true;}Boolean _validateProperties(Array<CQLSelectStatement>& _statements, Array<CIMInstance>& _instances, String testOption){ if(testOption == String::EMPTY || testOption == "4") { cout << "======Validate Properties Results=======" << endl; for(Uint32 i = 0; i < _statements.size(); i++) { cout << "======================================" << i << endl; cout << _statements[i].toString() << endl; try { _statements[i].validate(); cout << "----- validate ok" << endl; } catch(Exception& e){ cout << "-----" << e.getMessage() << endl;} catch(...){ cout << "Unknown Exception" << endl;} } } return true; }void _printPropertyList(CIMPropertyList& propList){ if (propList.isNull()) { cout << "-----all properties required" << endl; } else if (propList.size() == 0) { cout << "-----no properties required" << endl; } else { for (Uint32 n = 0; n < propList.size(); n++) { cout << "-----Required property " << propList[n].getString() << endl; } }}Boolean _getPropertyList(Array<CQLSelectStatement>& _statements, Array<CIMInstance>& _instances, CIMNamespaceName ns, String testOption){ if(testOption == String::EMPTY || testOption == "3") { cout << "========Get Property List Results=======" << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -