Пример #1
0
	void disableObjectSQL(BaseObject *object, bool disable)
	{
		if(object && object->getObjectType()!=BASE_RELATIONSHIP)
		{
			Messagebox msgbox;
			ObjectType obj_type=object->getObjectType();
			bool curr_val=object->isSQLDisabled();

			if(object->isSystemObject())
				throw Exception(Exception::getErrorMessage(ERR_OPR_RESERVED_OBJECT)
								.arg(object->getName(true))
								.arg(object->getTypeName()),
								ERR_OPR_RESERVED_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__);

			object->setSQLDisabled(disable);

			if(obj_type!=OBJ_DATABASE && curr_val!=disable)
			{
				msgbox.show(QString(QT_TR_NOOP("Do you want to apply the <strong>SQL %1 status</strong> to the object's references too? This will avoid problems when exporting or validating the model.")).arg(disable ? QT_TR_NOOP("disabling") : QT_TR_NOOP("enabling")),
							Messagebox::CONFIRM_ICON, Messagebox::YES_NO_BUTTONS);

				if(msgbox.result()==QDialog::Accepted)
					disableReferencesSQL(object);
			}

			/* Special case for tables. When disable the code there is the need to disable constraints
	   codes when the code of parent table is disabled too in order to avoid export errors */
			if(object->getObjectType()==OBJ_TABLE)
			{
				Constraint *constr = nullptr;
				vector<TableObject *> *objects=dynamic_cast<Table *>(object)->getObjectList(OBJ_CONSTRAINT);

				for(auto &obj : (*objects))
				{
					constr=dynamic_cast<Constraint *>(obj);

					/* If the constraint is not FK but is declared outside table via alter (ALTER TABLE...ADD CONSTRAINT...) or
		   The constraint is FK and the reference table is disabled the FK will not be enabled */
					if((constr->getConstraintType()!=ConstraintType::foreign_key && !constr->isDeclaredInTable()) ||
							(constr->getConstraintType()==ConstraintType::foreign_key &&
							 (disable || (!disable && !constr->getReferencedTable()->isSQLDisabled()))))
						constr->setSQLDisabled(disable);
				}
			}
		}
	}