void Constraint::removeExcludeElement(unsigned elem_idx) { if(elem_idx >= excl_elements.size()) throw Exception(ERR_REF_ELEM_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); excl_elements.erase(excl_elements.begin() + elem_idx); setCodeInvalidated(true); }
void BaseObject::setPrependedSQL(const QString &sql) { if(!acceptsCustomSQL()) throw Exception(ERR_ASG_APPSQL_OBJECT_INV_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->prepended_sql != sql); this->prepended_sql=sql; }
void Type::removeEnumeration(unsigned enum_idx) { if(enum_idx >= enumerations.size()) throw Exception(ERR_REF_ENUM_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); enumerations.erase(enumerations.begin() + enum_idx); setCodeInvalidated(true); }
void Table::setCopyTable(Table *tab) { setCodeInvalidated(copy_table != tab); copy_table=tab; if(!copy_table) copy_op=CopyOptions(0,0); }
void View::removeReferences(void) { references.clear(); exp_select.clear(); exp_from.clear(); exp_where.clear(); setCodeInvalidated(true); }
void Domain::setConstraintName(const QString &constr_name) { //Raises an error if the constraint name is invalid if(!constr_name.isEmpty() && !BaseObject::isValidName(constr_name)) throw Exception(ERR_ASG_INV_NAME_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(constraint_name != constr_name); this->constraint_name=constr_name; }
void Role::setOption(unsigned op_type, bool value) { if(op_type > OP_REPLICATION) //Raises an error if the option type is invalid throw Exception(ERR_ASG_VAL_INV_ROLE_OPT_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(options[op_type] != value); options[op_type]=value; }
void Cast::setCastType(unsigned cast_type) { //Raises an error if the user tries to assign an invalid cast type if(cast_type!=ASSIGNMENT && cast_type!=IMPLICIT) throw Exception(ERR_ASG_INV_TYPE_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->cast_type != cast_type); this->cast_type=cast_type; }
void Column::setType(PgSQLType type) { //An error is raised if the column receive a pseudo-type as data type. if(type.isPseudoType()) throw Exception(ERR_ASG_PSDTYPE_COLUMN,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->type != type); this->type=type; }
void View::addReference(Reference &refer, unsigned sql_type, int expr_id) { int idx; vector<unsigned> *expr_list=nullptr; Column *col=nullptr; //Specific tests for expressions used as view definition if(sql_type==Reference::SQL_VIEW_DEFINITION) { //Raises an error if the expression is empty if(refer.getExpression().isEmpty()) throw Exception(ERR_INV_VIEW_DEF_EXPRESSION,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error if already exists a definition expression else if(hasDefinitionExpression()) throw Exception(ERR_ASG_SEC_VIEW_DEF_EXPRESSION,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error if the user try to add a definition expression when already exists another references else if(!references.empty()) throw Exception(ERR_MIX_VIEW_DEF_EXPR_REFS,__PRETTY_FUNCTION__,__FILE__,__LINE__); } //Raises an error if the user try to add a ordinary reference when there is a reference used as definition expression else if(hasDefinitionExpression()) throw Exception(ERR_MIX_VIEW_DEF_EXPR_REFS,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Checks if the reference already exists idx=getReferenceIndex(refer); //If not exists if(idx < 0) { //Inserts the reference on the view refer.setDefinitionExpression(sql_type==Reference::SQL_VIEW_DEFINITION); references.push_back(refer); idx=references.size()-1; } if(sql_type!=Reference::SQL_VIEW_DEFINITION) { //Gets the expression list expr_list=getExpressionList(sql_type); //Inserts the reference id on the expression list if(expr_id >= 0 && expr_id < static_cast<int>(expr_list->size())) expr_list->insert(expr_list->begin() + expr_id, static_cast<unsigned>(idx)); //Raises an error if the expression id is invalid else if(expr_id >= 0 && expr_id >= static_cast<int>(expr_list->size())) throw Exception(ERR_REF_OBJ_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); else expr_list->push_back(static_cast<unsigned>(idx)); col=refer.getColumn(); if(col && col->isAddedByRelationship() && col->getObjectId() > this->object_id) this->object_id=BaseObject::getGlobalId(); } setCodeInvalidated(true); }
void Type::removeAttribute(unsigned attrib_idx) { //Raises an error if the attribute index is out of bound if(attrib_idx >= type_attribs.size()) throw Exception(ERR_REF_ATTRIB_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); type_attribs.erase(type_attribs.begin() + attrib_idx); setCodeInvalidated(true); }
void Permission::removeRole(unsigned role_idx) { if(role_idx > roles.size()) throw Exception(ERR_REF_OBJ_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); roles.erase(roles.begin() + role_idx); generatePermissionId(); setCodeInvalidated(true); }
void Type::setSubtype(PgSQLType subtype) { if(PgSQLType::getUserTypeIndex(this->getName(true), this) == !subtype) throw Exception(Exception::getErrorMessage(ERR_USER_TYPE_SELF_REFERENCE).arg(this->getName(true)), ERR_USER_TYPE_SELF_REFERENCE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->subtype != subtype); this->subtype=subtype; }
void Function::setSymbol(const QString &symbol) { if(language->getName().toLower()!=~LanguageType("c")) throw Exception(Exception::getErrorMessage(ERR_ASG_FUNC_REFLIB_LANG_NOT_C) .arg(this->getSignature()), ERR_ASG_FUNC_REFLIB_LANG_NOT_C,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->symbol != symbol); this->symbol=symbol; }
void View::removeReference(unsigned expr_id, unsigned sql_type) { vector<unsigned> *vect_idref=getExpressionList(sql_type); if(expr_id >= vect_idref->size()) throw Exception(ERR_REF_OBJ_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); vect_idref->erase(vect_idref->begin() + expr_id); setCodeInvalidated(true); }
void Constraint::addExcludeElement(ExcludeElement elem) { if(getExcludeElementIndex(elem) >= 0) throw Exception(ERR_INS_DUPLIC_ELEMENT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else if(elem.getExpression().isEmpty() && !elem.getColumn()) throw Exception(ERR_ASG_INV_EXPR_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); excl_elements.push_back(elem); setCodeInvalidated(true); }
void BaseObject::setOwner(BaseObject *owner) { if(owner && owner->getObjectType()!=OBJ_ROLE) throw Exception(ERR_ASG_INV_ROLE_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else if(!acceptsOwner()) throw Exception(ERR_ASG_ROLE_OBJECT_INV_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->owner != owner); this->owner=owner; }
void Function::removeReturnedTableColumn(unsigned column_idx) { if(column_idx>=ret_table_columns.size()) throw Exception(ERR_REF_OBJ_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); vector<Parameter>::iterator itr; itr=ret_table_columns.begin()+column_idx; ret_table_columns.erase(itr); setCodeInvalidated(true); }
void BaseObject::setTablespace(BaseObject *tablespace) { if(tablespace && tablespace->getObjectType()!=OBJ_TABLESPACE) throw Exception(ERR_ASG_INV_TABLESPACE_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else if(!acceptsTablespace()) throw Exception(ERR_ASG_TABSPC_INV_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->tablespace != tablespace); this->tablespace=tablespace; }
void BaseObject::setCollation(BaseObject *collation) { if(collation && !acceptsCollation()) throw Exception(ERR_ASG_INV_COLLATION_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); if(collation && collation->getObjectType()!=OBJ_COLLATION) throw Exception(ERR_ASG_INV_COLLATION_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->collation != collation); this->collation=collation; }
void Function::setSourceCode(const QString &src_code) { if(language && language->getName().toLower()==~LanguageType("c")) throw Exception(Exception::getErrorMessage(ERR_ASG_CODE_FUNC_C_LANGUAGE) .arg(this->getSignature()), ERR_ASG_CODE_FUNC_C_LANGUAGE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->source_code != src_code); this->source_code=src_code; }
void Function::setLibrary(const QString &library) { if(language->getName().toLower()!=~LanguageType("c")) throw Exception(Exception::getErrorMessage(ERR_ASG_FUNC_REFLIB_LANG_NOT_C) .arg(/*Utf8String::create(*/this->getSignature()), ERR_ASG_FUNC_REFLIB_LANG_NOT_C,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->library != library); this->library=library; }
void Cast::setCastFunction(Function *cast_func) { unsigned param_count; bool error=false; if(!cast_func) throw Exception(Exception::getErrorMessage(ERR_ASG_NOT_ALOC_FUNCTION) .arg(/*Utf8String::create(*/this->getName()) .arg(BaseObject::getTypeName(OBJ_CAST)), ERR_ASG_NOT_ALOC_FUNCTION,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Retrieve the cast function parameter count for specific validations param_count=cast_func->getParameterCount(); //Raises an error if the function don't have at least 1 parameter or a maximum of 3 if(param_count==0 || param_count > 3) throw Exception(Exception::getErrorMessage(ERR_ASG_FUNC_INV_PARAM_COUNT) .arg(/*Utf8String::create(*/this->getName()) .arg(BaseObject::getTypeName(OBJ_CAST)), ERR_ASG_FUNC_INV_PARAM_COUNT,__PRETTY_FUNCTION__,__FILE__,__LINE__); else { /* Error condition 1: Check if the first function parameter data type differs from cast source data type */ error=(cast_func->getParameter(0).getType()!=this->types[SRC_TYPE]); /* Error condition 2: Check if the second function parameter data type is different from 'integer' */ if(!error && param_count>=2) error=(cast_func->getParameter(1).getType()!=QString("integer")); /* Error condition 3: Check if the third function parameter data type is different from 'boolean' */ if(!error && param_count==3) error=(cast_func->getParameter(2).getType()!=QString("boolean")); //In case some error condition is reached raises an error if(error) throw Exception(Exception::getErrorMessage(ERR_ASG_FUNCTION_INV_PARAMS) .arg(/*Utf8String::create(*/this->getName()) .arg(BaseObject::getTypeName(OBJ_CAST)), ERR_ASG_FUNCTION_INV_PARAMS,__PRETTY_FUNCTION__,__FILE__,__LINE__); } //Raises an error if the return type of the function differs from the destination data type if(cast_func->getReturnType()!=this->types[DST_TYPE]) throw Exception(Exception::getErrorMessage(ERR_ASG_FUNCTION_INV_RET_TYPE) .arg(/*Utf8String::create(*/this->getName()) .arg(BaseObject::getTypeName(OBJ_CAST)), ERR_ASG_FUNCTION_INV_RET_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(cast_function != cast_func); this->cast_function=cast_func; }
void Type::setSubtypeOpClass(OperatorClass *opclass) { if(opclass && opclass->getIndexingType()!=IndexingType::btree) throw Exception(Exception::getErrorMessage(ERR_ASG_INV_OPCLASS_OBJ) .arg(this->getName(true)) .arg(this->getTypeName()), ERR_ASG_INV_OPCLASS_OBJ,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(subtype_opclass != opclass); subtype_opclass=opclass; }
void EventTrigger::setFilter(const QString &variable, const QStringList &values) { if(variable.toLower()!=ParsersAttributes::TAG) throw Exception(Exception::getErrorMessage(ERR_ASG_INV_EVENT_TRIGGER_VARIABLE).arg(variable),__PRETTY_FUNCTION__,__FILE__,__LINE__); if(!values.isEmpty()) { filter[variable].append(values); setCodeInvalidated(true); } }
void Table::swapObjectsIndexes(ObjectType obj_type, unsigned idx1, unsigned idx2) { vector<TableObject *> *obj_list=nullptr; vector<TableObject *>::iterator itr1, itr2; TableObject *aux_obj=nullptr, *aux_obj1=nullptr; try { if(idx1!=idx2) { obj_list=getObjectList(obj_type); //Raises an error if both index is out of list bounds if(idx1 >= obj_list->size() && idx2 >= obj_list->size()) throw Exception(ERR_REF_OBJ_INV_INDEX,__PRETTY_FUNCTION__,__FILE__,__LINE__); //If the idx1 is out of bound inserts the element idx2 at the list's begin else if(idx1 >= obj_list->size()) { aux_obj1=obj_list->front(); itr2=obj_list->begin() + idx2; aux_obj=(*itr2); obj_list->erase(itr2); obj_list->insert(obj_list->begin(), aux_obj); } //If the idx2 is out of bound inserts the element idx1 on the list's end else if(idx2 >= obj_list->size()) { itr1=obj_list->begin() + idx1; aux_obj=(*itr1); aux_obj1=obj_list->back(); obj_list->erase(itr1); obj_list->push_back(aux_obj); } else { aux_obj=obj_list->at(idx1); itr1=obj_list->begin() + idx1; itr2=obj_list->begin() + idx2; (*itr1)=aux_obj1=(*itr2); (*itr2)=aux_obj; } if(obj_type!=OBJ_COLUMN && obj_type!=OBJ_CONSTRAINT) BaseObject::swapObjectsIds(aux_obj, aux_obj1, false); setCodeInvalidated(true); } } catch(Exception &e) { throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
void Table::restoreRelObjectsIndexes(void) { restoreRelObjectsIndexes(OBJ_COLUMN); restoreRelObjectsIndexes(OBJ_CONSTRAINT); if(!col_indexes.empty() || !constr_indexes.empty()) { setCodeInvalidated(true); this->setModified(true); } }
void Tablespace::setDirectory(const QString &dir) { QString dir_aux=dir; dir_aux.remove('\''); //Raises an error if the directory is an empty path if(dir_aux.isEmpty()) throw Exception(ERR_ASG_EMPTY_DIR_NAME,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->directory != dir_aux); this->directory=dir_aux; }
void Type::setAlignment(PgSQLType type) { QString tp=(*type); //Raises an error if the type assigned to the alignment is invalid according to the rule if(tp!=QString("char") && tp!=QString("smallint") && tp!=QString("integer") && tp!=QString("double precision")) throw Exception(Exception::getErrorMessage(ERR_ASG_INV_ALIGNMENT_TYPE).arg(this->getName(true)), ERR_ASG_INV_ALIGNMENT_TYPE,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(alignment != type); alignment=tp; }
void Function::setLanguage(BaseObject *language) { //Raises an error if the language is not allocated if(!language) throw Exception(ERR_ASG_NOT_ALOC_LANGUAGE,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Raises an error if the language object is invalid else if(language->getObjectType()!=OBJ_LANGUAGE) throw Exception(ERR_ASG_INV_LANGUAGE_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); setCodeInvalidated(this->language != language); this->language=language; }