/** Adds the given colormap to this colormap. * This operator takes the given colormap and compares it to this colormap. If * this colormap has C_OTHER or C_BACKGROUND the value is compied from the other * LUT, otherwise the value is kept as is. * @param cmlt other colormap to add * @return reference to this */ Colormap & YuvColormap::operator+=(const Colormap &cmlt) { const YuvColormap *tc = dynamic_cast<const YuvColormap *>(&cmlt); if (tc == NULL) { throw TypeMismatchException("Only YUV colormaps can be added to a YUV colormap"); } if ((width_ != tc->width_) || (height_ != tc->height_) || (depth_ != tc->depth_)) { throw TypeMismatchException("YuvColormaps are of different sizes"); } unsigned char *this_lut = lut_; unsigned char *other_lut = tc->lut_; for (unsigned int i = 0; i < plane_size_ * depth_; ++i) { if ((*this_lut == C_OTHER) || (*this_lut == C_BACKGROUND)) { // can be overridden if ((*other_lut != C_OTHER) && (*other_lut != C_BACKGROUND)) { // there is something that is worth overriding this value *this_lut = *other_lut; } } ++this_lut; ++other_lut; } return *this; }
// Fill in a caller-provided unsigned int void Optarg::Value(unsigned int& i) const { CString cs = _value.getCString(); const char* s = cs; Boolean valid = true; Uint32 j; for (j = 0; j < strlen (s); j++) { if ((!isdigit (s [j])) && (!isspace (s [j]))) { valid = false; break; } } if (valid) { Uint64 i64; if ( !(sscanf (s, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", &i64)) || (i64 > 0xFFFFFFFF)) { throw TypeMismatchException (); } i = Uint32(i64); } else { throw TypeMismatchException(); } }
void CIMPropertyRep::setValue(const CIMValue& value) { // CIMType of value is immutable: if (!value.typeCompatible(_value)) throw TypeMismatchException(); if (_arraySize && _arraySize != value.getArraySize()) throw TypeMismatchException(); _value = value; }
/** Get value of current field as bool array. * @return field value * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type bool or field * is not an array (length is 1) */ bool * InterfaceFieldIterator::get_bools() const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_BOOL ) { throw TypeMismatchException("Requested value is not of type bool"); } else if (__infol->length == 1) { throw TypeMismatchException("Field %s is not an array", __infol->name); } else { return (bool *)__infol->value; } }
/** Set value of current field as byte array. * @param v an array of bytes * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type byte or field * is not an array (length is 1) */ void InterfaceFieldIterator::set_bytes(uint8_t *v) { if ( __infol == NULL ) { throw NullPointerException("Cannot set value of end element"); } else if ( __infol->type != IFT_BYTE ) { throw TypeMismatchException("Field to be written is not of type byte"); } else if (__infol->length == 1) { throw TypeMismatchException("Field %s is not an array", __infol->name); } else { memcpy(__infol->value, v, __infol->length * sizeof(uint8_t)); } }
CIMPropertyRep::CIMPropertyRep( const CIMName& name, const CIMValue& value, Uint32 arraySize, const CIMName& referenceClassName, const CIMName& classOrigin, Boolean propagated) : _name(name), _value(value), _arraySize(arraySize), _referenceClassName(referenceClassName), _classOrigin(classOrigin), _propagated(propagated), _refCounter(1), _ownerCount(0) { // ensure name is not null if (name.isNull()) { throw UninitializedObjectException(); } // Set the CIM name tag. _nameTag = generateCIMNameTag(_name); if ((arraySize != 0) && (!value.isArray() || value.getArraySize() != arraySize)) { throw TypeMismatchException(); } // A CIM Property may not be of reference array type if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE)) { throw TypeMismatchException(); } // if referenceClassName exists, must be CIMType REFERENCE. if (!referenceClassName.isNull()) { if (_value.getType() != CIMTYPE_REFERENCE) { throw TypeMismatchException(); } } // Can a property be of reference type with a null referenceClassName? // The DMTF says yes if it is a property of an instance; no if it is a // property of a class. We'll allow it here, but check in the CIMClass // addProperty() method. }
void ModuleController::_async_handleEnqueue(AsyncOpNode *op, MessageQueue *q, void *parm) { ModuleController *myself = static_cast<ModuleController *>(q); Message *request = op->get_request(); Message *response = op->get_response(); if( request && (! (request->getMask() & message_mask::ha_async))) throw TypeMismatchException(); if( response && (! (response->getMask() & message_mask::ha_async) )) throw TypeMismatchException(); op->release(); myself->return_op(op); Uint32 routing=0; // get rid of the module wrapper if( request && request->getType() == async_messages::ASYNC_MODULE_OP_START ) { (static_cast<AsyncMessage *>(request))->op = NULL; AsyncModuleOperationStart *rq = static_cast<AsyncModuleOperationStart *>(request); request = rq->get_action(); request->setRouting(routing = rq->getRouting()); delete rq; } // get rid of the module wrapper if(response && response->getType() == async_messages::ASYNC_MODULE_OP_RESULT ) { (static_cast<AsyncMessage *>(response))->op = NULL; AsyncModuleOperationResult *rp = static_cast<AsyncModuleOperationResult *>(response); response = rp->get_result(); response->setRouting(routing = rp->getRouting()); delete rp; } callback_handle *cb = reinterpret_cast<callback_handle *>(parm); cb->_module->_send_async_callback(routing, response, cb->_parm); delete cb; return; }
void CIMPropertyRep::setValue(const CIMValue& value) { // CIMType of value is immutable: if (!value.typeCompatible(_value)) throw TypeMismatchException(); if (_arraySize && _arraySize != value.getArraySize()) throw TypeMismatchException(); // A CIM Property may not be of reference array type if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE)) { throw TypeMismatchException(); } _value = value; }
void AmArg::assertArray() { if (Array == type) return; if (Undef == type) { type = Array; v_array = new ValueArray(); return; } throw TypeMismatchException(); }
/** Copy values from other interface. * @param other other interface to copy values from */ void TestInterface::copy_values(const Interface *other) { const TestInterface *oi = dynamic_cast<const TestInterface *>(other); if (oi == NULL) { throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)", type(), other->type()); } memcpy(data, oi->data, sizeof(TestInterface_data_t)); }
/** Get value of current field as string. * @return field value * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type string */ const char * InterfaceFieldIterator::get_string() const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_STRING ) { throw TypeMismatchException("Requested value is not of type string"); } else { return (const char *)__infol->value; } }
/** Get value of current enum field as integer array. * @return field value * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type int or field * is not an array (length is 1) */ int32_t * InterfaceFieldIterator::get_enums() const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_ENUM ) { throw TypeMismatchException("Requested value is not of type enum"); } else { return (int32_t *)__infol->value; } }
/** Get value of current field as byte array. * @return field value * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type byte or field * is not an array (length is 1) */ uint8_t * InterfaceFieldIterator::get_bytes() const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_BYTE ) { throw TypeMismatchException("Requested value is not of type float"); } else { return (uint8_t *)__infol->value; } }
/** Set value of current field as string. * @param v a string * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type string */ void InterfaceFieldIterator::set_string(const char *v) { if ( __infol == NULL ) { throw NullPointerException("Cannot set value of end element"); } else if ( __infol->type != IFT_STRING ) { throw TypeMismatchException("Field to be written is not of type string"); } else { strncpy((char *) __infol->value, v, __infol->length); } }
void AmArg::assertArray(size_t s) { if (Undef == type) { type = Array; v_array = new ValueArray(); } else if (Array != type) { throw TypeMismatchException(); } if (v_array->size() < s) v_array->resize(s); }
/** Assign operation. * Copies all values from the given colormap. * @param yuvcm colormap which's data to copy to this instance * @exception TypeMismatchException thrown if depth of colormaps does not match. * @return reference to this */ Colormap & YuvColormap::operator=(const YuvColormap &yuvcm) { if (lut_size_ != yuvcm.lut_size_) { throw TypeMismatchException("Size of colormaps does not match"); } memcpy(lut_, yuvcm.lut_, lut_size_); return *this; }
/** Get value of current field as unsigned integer array. * @return field value * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type unsigned int * or field is not an array (length is 1) */ uint64_t * InterfaceFieldIterator::get_uint64s() const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_UINT64 ) { throw TypeMismatchException("Requested value is not of type unsigned int"); } else { return (uint64_t *)__infol->value; } }
/** Message content constructor. * This constructor is meant to be used with FawkesNetworkMessage::msgc(). * @param component_id component ID * @param msg_id message ID * @param payload message payload * @param payload_size total payload size */ PluginListMessage::PluginListMessage(unsigned int component_id, unsigned int msg_id, void *payload, size_t payload_size) { if ( component_id != FAWKES_CID_PLUGINMANAGER ) { throw TypeMismatchException("PluginListMessage: invalid component ID"); } plugin_list_msg_t *tmsg = (plugin_list_msg_t *)payload; void *plugin_list_payload = (void *)((size_t)payload + sizeof(msg)); plugin_list = new DynamicBuffer(&(tmsg->plugin_list), plugin_list_payload, payload_size - sizeof(msg)); }
/** Get value of current enum field as integer. * @return field value * @param index array index (only use if field is an array) * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type int * @exception OutOfBoundsException thrown if index is out of bounds */ int32_t InterfaceFieldIterator::get_enum(unsigned int index) const { if ( __infol == NULL ) { throw NullPointerException("Cannot get value of end element"); } else if ( __infol->type != IFT_ENUM ) { throw TypeMismatchException("Requested value is not of type enum"); } else if (index >= __infol->length) { throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); } else { return ((int32_t *)__infol->value)[index]; } }
/** Message content constructor. * This constructor is meant to be used with FawkesNetworkMessage::msgc(). * @param component_id component ID * @param msg_id message ID * @param payload message payload * @param payload_size total payload size */ BlackBoardInterfaceListContent::BlackBoardInterfaceListContent(unsigned int component_id, unsigned int msg_id, void *payload, size_t payload_size) { if ( component_id != FAWKES_CID_BLACKBOARD ) { throw TypeMismatchException("BlackBoardInterfaceListContent: invalid component ID"); } bb_ilist_msg_t *tmsg = (bb_ilist_msg_t *)payload; void *ilist_payload = (void *)((size_t)payload + sizeof(msg)); interface_list = new DynamicBuffer(&(tmsg->interface_list), ilist_payload, payload_size - sizeof(msg)); }
/** Set value of current field as unsigned integer. * @param v the new value * @param index array index (only use if field is an array) * @exception NullPointerException invalid iterator, possibly end iterator * @exception TypeMismatchException thrown if field is not of type unsigned int * @exception OutOfBoundsException thrown if index is out of bounds */ void InterfaceFieldIterator::set_uint16(uint16_t v, unsigned int index) { if ( __infol == NULL ) { throw NullPointerException("Cannot set value of end element"); } else if ( __infol->type != IFT_UINT16 ) { throw TypeMismatchException("Field to be written is not of type unsigned int"); } else if (index >= __infol->length) { throw OutOfBoundsException("Field index out of bounds", index, 0, __infol->length); } else { char* dst = (char *) __infol->value + index * sizeof(uint16_t); memcpy((void *) dst, &v, sizeof(uint16_t)); } }
CIMKeyBinding::CIMKeyBinding(const CIMName& name, const CIMValue& value) { if (value.isArray()) { throw TypeMismatchException(); } String kbValue = value.toString(); Type kbType; switch (value.getType()) { case CIMTYPE_BOOLEAN: kbType = BOOLEAN; break; case CIMTYPE_CHAR16: case CIMTYPE_STRING: case CIMTYPE_DATETIME: kbType = STRING; break; case CIMTYPE_REFERENCE: kbType = REFERENCE; break; // case CIMTYPE_REAL32: // case CIMTYPE_REAL64: case CIMTYPE_OBJECT: case CIMTYPE_INSTANCE: // From PEP 194: EmbeddedObjects cannot be keys. throw TypeMismatchException(); break; default: kbType = NUMERIC; break; } _rep = new CIMKeyBindingRep(name, kbValue, kbType); }
CIMParameterRep::CIMParameterRep( const CIMName& name, CIMType type, Boolean isArray, Uint32 arraySize, const CIMName& referenceClassName) : _name(name), _type(type), _isArray(isArray), _arraySize(arraySize), _referenceClassName(referenceClassName) { // ensure name is not null if(name.isNull()) { throw UninitializedObjectException(); } if((_arraySize != 0) && !_isArray) { throw TypeMismatchException(); } if (!referenceClassName.isNull()) { if (_type != CIMTYPE_REFERENCE) { throw TypeMismatchException(); } } else { if (_type == CIMTYPE_REFERENCE) { throw TypeMismatchException(); } } }
Colormap & YuvColormap::operator+=(const char *filename) { ColormapFile cmf; cmf.read(filename); Colormap * tcm = cmf.get_colormap(); YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm); if (!tycm) { delete tcm; throw TypeMismatchException("File does not contain a YUV colormap"); } *this += *tycm; delete tcm; return *this; }
void CIMClientRep::compareObjectPathtoCurrentConnection(const CIMObjectPath& obj) { String ObjHost = obj.getHost(); // test if a host is given at all, if not everything is fine and we leave it at that if (ObjHost==String::EMPTY) { return; } MessageLoaderParms typeMismatchMessage; // splitting the port from hostname as we have to compare both separate int i = ObjHost.find(":"); String ObjPort = String::EMPTY; // only if there is a ":" we should split a port address from hostname string if (i > 0) { ObjPort = ObjHost.subString(i+1); ObjHost.remove(i); // lets see who we are really connected to // should stand in UInt32 _connectPortNumber and String _connectHost; // comparing the stuff // first the easy part, comparing the ports Uint32 objectport = strtoul((const char*) ObjPort.getCString(), NULL, 0); // if port in object path does not equal port of connection throw a TypeMismatch Exception if (objectport != _connectPortNumber) { typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH", "Failed validation of CIM object path: port of CIMClient connection($0) and port of object path($1) not equal", _connectPortNumber, objectport); throw TypeMismatchException(typeMismatchMessage); } } }
/*! * \overload * * This method creates a new BoundingVolume as a copy of \p copy. */ BoundingVolume* BoundingVolume::createBoundingVolume(World* world, const BoundingVolume* copy, BvhNode* parent) { if (!copy) { return createBoundingVolume(world, parent); } if (copy->getVolumeType() != getCreateRigidBoundingVolumeType(world)) { std::stringstream errormessage; errormessage << "ERROR: requested a copy of BV type " << copy->getVolumeType() << ", but expected type " << getCreateRigidBoundingVolumeType(world) << std::endl; throw TypeMismatchException(errormessage.str()); } BoundingVolume* bv = 0; switch (getCreateRigidBoundingVolumeType(world)) { case BV_TYPE_AABB: bv = new Aabb(*static_cast<const Aabb*>(copy)); break; case BV_TYPE_KDOP: bv = new Kdop(*static_cast<const Kdop*>(copy)); break; case BV_TYPE_SPHERE: bv = new BoundingSphere(*static_cast<const BoundingSphere*>(copy)); break; case BV_TYPE_OBB: bv = new Obb(*static_cast<const Obb*>(copy)); break; default: // TODO: exception!! std::cerr << dc_funcinfo << "FATAL ERROR: bounding volume type " << getCreateRigidBoundingVolumeType(world) << " not supported" << std::endl; exit(1); return 0; } bv->setHierarchyNode(parent); return bv; }
void CIMPropertyRep::resolve( DeclContext* declContext, const CIMNamespaceName& nameSpace, Boolean isInstancePart, const CIMConstProperty& inheritedProperty, Boolean propagateQualifiers) { PEGASUS_ASSERT(!inheritedProperty.isUninitialized()); // Check the type: if (!inheritedProperty.getValue().typeCompatible(_value)) { if (!( (inheritedProperty.getValue().getType() == CIMTYPE_OBJECT) && (_value.getType() == CIMTYPE_STRING) && (_qualifiers.find(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT) != PEG_NOT_FOUND) && (inheritedProperty.getValue().isArray() == _value.isArray()) ) && !( (inheritedProperty.getValue().getType() == CIMTYPE_INSTANCE) && (_value.getType() == CIMTYPE_STRING) && (_qualifiers.find(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE) != PEG_NOT_FOUND) && (inheritedProperty.getValue().isArray() == _value.isArray()) )) { throw TypeMismatchException(); } } // Validate the qualifiers of the property (according to // superClass's property with the same name). This method // will throw an exception if the validation fails. CIMScope scope = CIMScope::PROPERTY; if (_value.getType() == CIMTYPE_REFERENCE) scope = CIMScope::REFERENCE; // Test the reference class name against the inherited property if (_value.getType() == CIMTYPE_REFERENCE || _value.getType() == CIMTYPE_INSTANCE) { CIMName inheritedClassName; Array<CIMName> classNames; if (_value.getType() == CIMTYPE_INSTANCE) { Uint32 pos = inheritedProperty.findQualifier( PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE); if (pos != PEG_NOT_FOUND) { String qualStr; inheritedProperty.getQualifier(pos).getValue().get(qualStr); inheritedClassName = qualStr; } if (_value.isArray()) { Array<CIMInstance> embeddedInstances; _value.get(embeddedInstances); for (Uint32 i = 0, n = embeddedInstances.size(); i < n; ++i) { classNames.append(embeddedInstances[i].getClassName()); } } else { CIMInstance embeddedInst; _value.get(embeddedInst); classNames.append(embeddedInst.getClassName()); } } else { CIMName referenceClass; if (_referenceClassName.isNull()) { CIMObjectPath reference; _value.get(reference); referenceClass = reference.getClassName(); } else { referenceClass = _referenceClassName; } inheritedClassName = inheritedProperty.getReferenceClassName(); classNames.append(referenceClass); } // This algorithm is friendly to arrays of embedded instances. It // remembers the class names that are found to be subclasses of the // inherited class name retrieved from the inherited property. This // ensures that any branch in the inheritance hierarchy will only be // traversed once. This provides significant optimization given that // most elements of an array of embedded instances will probably be of // very closely related types. Array<CIMName> successTree; successTree.append(inheritedClassName); for (Uint32 i = 0, n = classNames.size(); i < n; ++i) { Array<CIMName> traversalHistory; CIMName currentName = classNames[i]; Boolean found = false; while (!found && !currentName.isNull()) { for (Uint32 j = 0, m = successTree.size(); j < m; ++j) { if (currentName == successTree[j]) { found = true; break; } } if (!found) { traversalHistory.append(currentName); CIMClass currentClass = declContext->lookupClass( nameSpace, currentName); if (currentClass.isUninitialized()) { throw PEGASUS_CIM_EXCEPTION( CIM_ERR_INVALID_PARAMETER, currentName.getString()); } currentName = currentClass.getSuperClassName(); } } if (!found) { throw TypeMismatchException(); } successTree.appendArray(traversalHistory); } } _qualifiers.resolve( declContext, nameSpace, scope, isInstancePart, inheritedProperty._rep->_qualifiers, propagateQualifiers); _classOrigin = inheritedProperty.getClassOrigin(); }
bool Database::db_selectVal(Node *root) { // |¯¯¯¯¯¯¯¯| // | root | // |________| // v(R) // |¯¯¯¯¯¯¯¯| // |AND(...)| // |________| // v v // |¯¯¯¯¯¯¯¯| |¯¯¯¯¯¯¯¯| // | cmp(op)| | cmp(op)| // |________| |________| // v v // column val Node* ptrConj = root->rightSon; Node* ptrExpr = nullptr; Node* columnDef = nullptr; vector<Node*> columnWithIndex; vector<Node*> columnWithoutIndex; try { m_catMgr.assertNonExistTable(root->strval); while (ptrConj != nullptr) { // now support 'and' only. // ptrExpr->operation <= OP_OR equals to // ptrExpr->operation == OP_AND || OP_OR if (ptrConj->operation == OP_AND) { // column name put in the left side ptrExpr = ptrConj->leftSon; } else { ptrExpr = ptrConj; // end here ptrConj = ptrConj->rightSon; } m_catMgr.assertNonExistColumn(root->strval, ptrExpr->leftSon->strval); columnDef = m_catMgr.get_column_def(root->strval, ptrExpr->leftSon->strval); ptrExpr->leftSon->operation = columnDef->operation; if (m_catMgr.ifexist_index_on_column(root->strval, ptrExpr->leftSon->strval)) { columnWithIndex.push_back(ptrExpr); } else { columnWithoutIndex.push_back(ptrExpr); } // check type if (CHECK_TYPE(columnDef->operation, ptrExpr->rightSon->strval)) throw TypeMismatchException(string("at column ")+string(ptrExpr->leftSon->strval)); ptrConj = ptrConj->rightSon; } } catch (TableNonExistException) { fprintf(stderr, "Error: no such table: %s\n", root->strval); return false; } catch (ColumnNonExistException) { fprintf(stderr, "Error: table %s has no column named %s\n",\ root->strval, ptrExpr->leftSon->strval); return false; } catch (TypeMismatchException e) { fprintf(stderr, "Error: type mismatch: %s\n", e.columnName.c_str()); return false; } columnDef = m_catMgr.get_column_def(root->strval); if (root->rightSon == nullptr) // currently support select * m_recMgr.print_all_record(root->strval, columnDef); else { vector<CursePair> cursor; size_t tmpSize = columnWithIndex.size(); for (auto it : columnWithIndex) { if (it == columnWithIndex[0]) m_idxMgr.select_record_raw(root->strval, it->leftSon->strval, it, cursor); else m_idxMgr.select_record(root->strval, it->leftSon->strval, it, cursor); } for (auto it : columnWithoutIndex) { if (tmpSize == 0 && it == columnWithoutIndex[0]) m_recMgr.select_record_raw(root->strval, columnDef, it, cursor); else m_recMgr.select_record(root->strval, columnDef, it, cursor); } m_recMgr.print_select_record(root->strval, columnDef, cursor); } // always print 0 printf("Query OK, 0 rows affected\n"); return true; }
Boolean WQLSelectStatementRep::evaluateWhereClause( const WQLPropertySource* source) const { if (!hasWhereClause()) return true; Stack<Boolean> stack; stack.reserveCapacity(16); // // Counter for operands: // Uint32 j = 0; // // Process each of the operations: // for (Uint32 i = 0, n = _operations.size(); i < n; i++) { WQLOperation operation = _operations[i]; switch (operation) { case WQL_OR: { PEGASUS_ASSERT(stack.size() >= 2); Boolean operand1 = stack.top(); stack.pop(); Boolean operand2 = stack.top(); stack.top() = operand1 || operand2; break; } case WQL_AND: { PEGASUS_ASSERT(stack.size() >= 2); Boolean operand1 = stack.top(); stack.pop(); Boolean operand2 = stack.top(); stack.top() = operand1 && operand2; break; } case WQL_NOT: { PEGASUS_ASSERT(stack.size() >= 1); Boolean operand = stack.top(); stack.top() = !operand; break; } case WQL_EQ: case WQL_NE: case WQL_LT: case WQL_LE: case WQL_GT: case WQL_GE: case WQL_LIKE: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 2); // // Resolve the left-hand-side to a value (if not already // a value). // WQLOperand& lhs = whereOperands[j++]; _ResolveProperty(lhs, source); // // Resolve the right-hand-side to a value (if not already // a value). // WQLOperand& rhs = whereOperands[j++]; _ResolveProperty(rhs, source); // // Check for a type mismatch: // // PEGASUS_OUT(lhs.toString()); // PEGASUS_OUT(rhs.toString()); if (rhs.getType() != lhs.getType()) throw TypeMismatchException(); if(operation == WQL_LIKE && (lhs.getType() != WQLOperand::STRING_VALUE)) { MessageLoaderParms parms( "WQL.WQLSelectStatementRep.PROP_NOT_FOUND", "LIKE syntax can only be used against string properties."); throw QueryRuntimeException(parms); } // // Now that the types are known to be alike, apply the // operation: // stack.push(_Evaluate(lhs, rhs, operation)); break; } case WQL_IS_TRUE: case WQL_IS_NOT_FALSE: { PEGASUS_ASSERT(stack.size() >= 1); break; } case WQL_IS_FALSE: case WQL_IS_NOT_TRUE: { PEGASUS_ASSERT(stack.size() >= 1); stack.top() = !stack.top(); break; } case WQL_IS_NULL: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 1); WQLOperand& operand = whereOperands[j++]; _ResolveProperty(operand, source); stack.push(operand.getType() == WQLOperand::NULL_VALUE); break; } case WQL_IS_NOT_NULL: { Array<WQLOperand> whereOperands(_operands); PEGASUS_ASSERT(whereOperands.size() >= 1); WQLOperand& operand = whereOperands[j++]; _ResolveProperty(operand, source); stack.push(operand.getType() != WQLOperand::NULL_VALUE); break; } } } PEGASUS_ASSERT(stack.size() == 1); return stack.top(); }
bool Database::db_deleteVal(Node *root) { Node* ptrConj = root->rightSon; Node* ptrExpr = nullptr; Node* columnDef = nullptr; vector<Node*> columnWithIndex; vector<Node*> columnWithoutIndex; try { m_catMgr.assertNonExistTable(root->strval); while (ptrConj != nullptr) { // now support 'and' only. // ptrExpr->operation <= OP_OR equals to // ptrExpr->operation == OP_AND || OP_OR if (ptrConj->operation == OP_AND) { // column name put in the left side ptrExpr = ptrConj->leftSon; } else { ptrExpr = ptrConj; // end here ptrConj = ptrConj->rightSon; } m_catMgr.assertNonExistColumn(root->strval, ptrExpr->leftSon->strval); columnDef = m_catMgr.get_column_def(root->strval, ptrExpr->leftSon->strval); if (m_catMgr.ifexist_index_on_column(root->strval, ptrExpr->leftSon->strval)) { columnWithIndex.push_back(ptrExpr); } else { columnWithoutIndex.push_back(ptrExpr); } // check type if (CHECK_TYPE(columnDef->operation, ptrExpr->rightSon->strval)) throw TypeMismatchException(string("at column ")+string(ptrExpr->leftSon->strval)); ptrConj = ptrConj->rightSon; } } catch (TableNonExistException) { fprintf(stderr, "Error: no such table: %s\n", root->strval); return false; } catch (ColumnNonExistException) { fprintf(stderr, "Error: table %s has no column named %s\n",\ root->strval, ptrExpr->leftSon->strval); return false; } catch (TypeMismatchException e) { fprintf(stderr, "Error: type mismatch: %s\n", e.columnName.c_str()); return false; } int returnVal; Node *ptrColumn = m_catMgr.get_column_def(root->strval); if (root->rightSon == nullptr) { returnVal = m_recMgr.delete_all_record(root->strval); while(ptrColumn != nullptr) { if (m_catMgr.ifexist_index_on_column(root->strval, ptrColumn->strval)) { m_idxMgr.delete_all_idx(root->strval, ptrColumn->strval); } ptrColumn = ptrColumn->leftSon; } } else { vector<CursePair> cursor; size_t tmpSize = columnWithIndex.size(); for (auto it : columnWithIndex) { if (it == columnWithIndex[0]) m_idxMgr.select_record_raw(root->strval, it->leftSon->strval, it, cursor); else m_idxMgr.select_record(root->strval, it->leftSon->strval, it, cursor); } for (auto it : columnWithoutIndex) { if (tmpSize == 0 && it == columnWithoutIndex[0]) m_recMgr.select_record_raw(root->strval, columnDef, it, cursor); else m_recMgr.select_record(root->strval, columnDef, it, cursor); } returnVal = m_recMgr.delete_record(root->strval, cursor); while(ptrColumn != nullptr) { if (m_catMgr.ifexist_index_on_column(root->strval, ptrColumn->strval)) { m_idxMgr.delete_entry_idx(root->strval, ptrColumn->strval, cursor); } ptrColumn = ptrColumn->leftSon; } } // delete index // for (auto it : something from cat?) // { //// TO-DO // m_idxMgr.delete_all_on_column(table, column, cursor); // } printf("Query OK, %d rows affected\n", returnVal); return true; }