예제 #1
0
파일: tag.cpp 프로젝트: Ox0000/pgmodeler
QString Tag::getCodeDefinition(unsigned def_type, bool reduced_form)
{
	if(def_type==SchemaParser::SQL_DEFINITION)
		return(QString());
	else
	{
		QString code_def=getCachedCode(def_type, reduced_form);
		if(!code_def.isEmpty()) return(code_def);

		try
		{
			attribs_map attribs;

			for(auto &itr : color_config)
			{
				attribs[ParsersAttributes::ID]=itr.first;
				attribs[ParsersAttributes::COLORS]=QString();

				if(itr.first==ParsersAttributes::TABLE_NAME || itr.first==ParsersAttributes::TABLE_SCHEMA_NAME)
					attribs[ParsersAttributes::COLORS]=itr.second[FILL_COLOR1].name();
				else
					attribs[ParsersAttributes::COLORS]=itr.second[FILL_COLOR1].name() + QString(",") +
													   itr.second[FILL_COLOR2].name() + QString(",") + itr.second[BORDER_COLOR].name();

				attributes[ParsersAttributes::STYLES]+=schparser.getCodeDefinition(ParsersAttributes::STYLE, attribs, SchemaParser::XML_DEFINITION);
			}
		}
		catch(Exception &e)
		{
			throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
		}

		return(BaseObject::getCodeDefinition(def_type, reduced_form));
	}
}
예제 #2
0
파일: role.cpp 프로젝트: Ox0000/pgmodeler
QString Role::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	unsigned i;
	QString op_attribs[]={ ParsersAttributes::SUPERUSER, ParsersAttributes::CREATEDB,
						   ParsersAttributes::CREATEROLE, ParsersAttributes::INHERIT,
						   ParsersAttributes::LOGIN, ParsersAttributes::ENCRYPTED,
						   ParsersAttributes::REPLICATION };

	setRoleAttribute(REF_ROLE);
	setRoleAttribute(MEMBER_ROLE);
	setRoleAttribute(ADMIN_ROLE);

	for(i=0; i <= OP_REPLICATION; i++)
		attributes[op_attribs[i]]=(options[i] ? ParsersAttributes::_TRUE_ : QString());

	attributes[ParsersAttributes::PASSWORD]=password;
	attributes[ParsersAttributes::VALIDITY]=validity;

	if(conn_limit >= 0)
		attributes[ParsersAttributes::CONN_LIMIT]=QString("%1").arg(conn_limit);

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #3
0
QString Sequence::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

  Table *table=nullptr;

	if(owner_col)
	{
    attributes[ParsersAttributes::OWNER_COLUMN]=owner_col->getSignature();
    table=dynamic_cast<Table *>(owner_col->getParentTable());
	}

  attributes[ParsersAttributes::TABLE]=(table ? table->getName(true) : QString());
	attributes[ParsersAttributes::COLUMN]=(owner_col ? owner_col->getName(true) : QString());

	attributes[ParsersAttributes::INCREMENT]=increment;
	attributes[ParsersAttributes::MIN_VALUE]=min_value;
	attributes[ParsersAttributes::MAX_VALUE]=max_value;
	attributes[ParsersAttributes::START]=start;
	attributes[ParsersAttributes::CACHE]=cache;
	attributes[ParsersAttributes::CYCLE]=(cycle ? ParsersAttributes::_TRUE_ : QString());

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #4
0
QString View::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::CTE_EXPRESSION]=cte_expression;
  attributes[ParsersAttributes::MATERIALIZED]=(materialized ? ParsersAttributes::_TRUE_ : QString());
  attributes[ParsersAttributes::RECURSIVE]=(recursive ? ParsersAttributes::_TRUE_ : QString());
  attributes[ParsersAttributes::WITH_NO_DATA]=(with_no_data ? ParsersAttributes::_TRUE_ : QString());
  attributes[ParsersAttributes::COLUMNS]=QString();
  attributes[ParsersAttributes::TAG]=QString();

  setSQLObjectAttribute();

  if(recursive)
    attributes[ParsersAttributes::COLUMNS]=getColumnsList().join(',');

  if(tag && def_type==SchemaParser::XML_DEFINITION)
   attributes[ParsersAttributes::TAG]=tag->getCodeDefinition(def_type, true);

	if(def_type==SchemaParser::SQL_DEFINITION)
		setDeclarationAttribute();
	else
	{
		setPositionAttribute();
		setReferencesAttribute();
	}

  return(BaseObject::__getCodeDefinition(def_type));
}
예제 #5
0
QString EventTrigger::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::EVENT]=~event;

	if(def_type==SchemaParser::SQL_DEFINITION)
	{
		QStringList str_list;

		if(function)
			attributes[ParsersAttributes::FUNCTION]=function->getSignature();

    for(auto &flt : filter)
      str_list.push_back(QString("%1 IN ('%2')").arg(flt.first).arg(flt.second.join(QString("','"))));

    attributes[ParsersAttributes::FILTER]=str_list.join(QString("\n\t AND "));
	}
	else
	{
		if(function)
			attributes[ParsersAttributes::FUNCTION]=function->getCodeDefinition(def_type, true);

    for(auto &flt : filter)
			//Creating an element <filter variable="" values=""/>
			attributes[ParsersAttributes::FILTER]+=QString("\t<%1 %2=\"%3\" %4=\"%5\"/>\n")
																						 .arg(ParsersAttributes::FILTER)
																						 .arg(ParsersAttributes::VARIABLE).arg(flt.first)
                                             .arg(ParsersAttributes::VALUES).arg(flt.second.join(','));
	}

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #6
0
QString Table::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::OIDS]=(with_oid ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::GEN_ALTER_CMDS]=(gen_alter_cmds ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::UNLOGGED]=(unlogged ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::COPY_TABLE]=QString();
	attributes[ParsersAttributes::ANCESTOR_TABLE]=QString();
  attributes[ParsersAttributes::TAG]=QString();

	if(def_type==SchemaParser::SQL_DEFINITION && copy_table)
		attributes[ParsersAttributes::COPY_TABLE]=copy_table->getName(true) + copy_op.getSQLDefinition();

  if(tag && def_type==SchemaParser::XML_DEFINITION)
   attributes[ParsersAttributes::TAG]=tag->getCodeDefinition(def_type, true);

	(copy_table ? copy_table->getName(true) : QString());

	setColumnsAttribute(def_type);
	setConstraintsAttribute(def_type);
	setAncestorTableAttribute();

	if(def_type==SchemaParser::XML_DEFINITION)
  {
    setRelObjectsIndexesAttribute();
		setPositionAttribute();
  }

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #7
0
QString Column::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	if(getParentTable())
		attributes[ParsersAttributes::TABLE]=getParentTable()->getName(true);

	attributes[ParsersAttributes::TYPE]=type.getCodeDefinition(def_type);

	attributes[ParsersAttributes::DEFAULT_VALUE]=QString();

	if(!sequence)
		attributes[ParsersAttributes::DEFAULT_VALUE]=default_value;
	else
	{
		//Configuring the default value of the column to get the next value of the sequence
		if(def_type==SchemaParser::SQL_DEFINITION)
			attributes[ParsersAttributes::DEFAULT_VALUE]=QString("nextval('%1'::regclass)").arg(sequence->getSignature());//.remove("\""));

		attributes[ParsersAttributes::SEQUENCE]=sequence->getName(true);
	}

	attributes[ParsersAttributes::NOT_NULL]=(!not_null ? QString() : ParsersAttributes::_TRUE_);
	attributes[ParsersAttributes::DECL_IN_TABLE]=(isDeclaredInTable() ? ParsersAttributes::_TRUE_ : QString());

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #8
0
QString Language::getCodeDefinition(unsigned def_type, bool reduced_form)
{
	QString code_def=getCachedCode(def_type, reduced_form);
	if(!code_def.isEmpty()) return(code_def);

	unsigned i;
	QString attribs_func[3]={ParsersAttributes::VALIDATOR_FUNC,
													 ParsersAttributes::HANDLER_FUNC,
													 ParsersAttributes::INLINE_FUNC};

	attributes[ParsersAttributes::TRUSTED]=(is_trusted ? ParsersAttributes::_TRUE_ : QString());

	if(!reduced_form && def_type==SchemaParser::XML_DEFINITION)
		reduced_form=(!functions[VALIDATOR_FUNC] && !functions[HANDLER_FUNC] && !functions[INLINE_FUNC] && !this->getOwner());

	for(i=0; i < 3; i++)
	{
		if(functions[i])
		{
			if(def_type==SchemaParser::SQL_DEFINITION)
				attributes[attribs_func[i]]=functions[i]->getName(true);
			else
			{
				functions[i]->setAttribute(ParsersAttributes::REF_TYPE, attribs_func[i]);
				attributes[attribs_func[i]]=functions[i]->getCodeDefinition(def_type, true);
			}
		}
	}

	return(BaseObject::getCodeDefinition(def_type, reduced_form));
}
예제 #9
0
QString Schema::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::FILL_COLOR]=fill_color.name();
	attributes[ParsersAttributes::RECT_VISIBLE]=(rect_visible ? ParsersAttributes::_TRUE_ : QString());
	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #10
0
QString Tablespace::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

  if(!directory.isEmpty())
    attributes[ParsersAttributes::DIRECTORY]=QString("'") + directory + QString("'");

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #11
0
QString Extension::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::NAME]=this->getName(true, false);
	attributes[ParsersAttributes::HANDLES_TYPE]=(handles_type ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::CUR_VERSION]=versions[CUR_VERSION];
	attributes[ParsersAttributes::OLD_VERSION]=versions[OLD_VERSION];
	attributes[ParsersAttributes::NAME]=this->getName(def_type==SchemaParser::SQL_DEFINITION, false);
	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #12
0
QString Domain::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::NOT_NULL]=(not_null ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::DEFAULT_VALUE]=default_value;
	attributes[ParsersAttributes::EXPRESSION]=expression;
	attributes[ParsersAttributes::CONSTRAINT]=BaseObject::formatName(constraint_name);

	if(def_type==SchemaParser::SQL_DEFINITION)
		attributes[ParsersAttributes::TYPE]=(*type);
	else
	{
		attributes[ParsersAttributes::TYPE]=type.getCodeDefinition(def_type);
	}

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #13
0
QString Conversion::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	attributes[ParsersAttributes::DEFAULT]=(is_default ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::SRC_ENCODING]=(~encodings[SRC_ENCODING]);
	attributes[ParsersAttributes::DST_ENCODING]=(~encodings[DST_ENCODING]);

	if(conversion_func)
	{
		if(def_type==SchemaParser::SQL_DEFINITION)
			attributes[ParsersAttributes::FUNCTION]=conversion_func->getName(true);
		else
			attributes[ParsersAttributes::FUNCTION]=conversion_func->getCodeDefinition(def_type, true);
	}

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #14
0
QString Function::getCodeDefinition(unsigned def_type, bool reduced_form)
{
	QString code_def=getCachedCode(def_type, reduced_form);
	if(!code_def.isEmpty()) return(code_def);

	setParametersAttribute(def_type);

	attributes[ParsersAttributes::EXECUTION_COST]=QString("%1").arg(execution_cost);
	attributes[ParsersAttributes::ROW_AMOUNT]=QString("%1").arg(row_amount);
	attributes[ParsersAttributes::FUNCTION_TYPE]=(~function_type);

	if(language)
	{
		if(def_type==SchemaParser::SQL_DEFINITION)
		{
			attributes[ParsersAttributes::LANGUAGE]=language->getName(false);
			attributes[ParsersAttributes::RETURN_TYPE]=(*return_type);
		}
		else
		{
			attributes[ParsersAttributes::LANGUAGE]=language->getCodeDefinition(def_type,true);
			attributes[ParsersAttributes::RETURN_TYPE]=return_type.getCodeDefinition(def_type);
		}
	}

	setTableReturnTypeAttribute(def_type);

	attributes[ParsersAttributes::RETURNS_SETOF]=(returns_setof ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::WINDOW_FUNC]=(is_wnd_function ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::LEAKPROOF]=(is_leakproof ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::SECURITY_TYPE]=(~security_type);
	attributes[ParsersAttributes::BEHAVIOR_TYPE]=(~behavior_type);
	attributes[ParsersAttributes::DEFINITION]=source_code;

	if(language->getName()==~LanguageType(LanguageType::c))
	{
		attributes[ParsersAttributes::SYMBOL]=symbol;
		attributes[ParsersAttributes::LIBRARY]=library;
	}

	attributes[ParsersAttributes::SIGNATURE]=signature;
	return(BaseObject::getCodeDefinition(def_type, reduced_form));
}
예제 #15
0
QString BaseRelationship::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type);
	if(!code_def.isEmpty()) return(code_def);

	if(def_type==SchemaParser::SQL_DEFINITION)
	{
		if(rel_type!=RELATIONSHIP_FK)
      return(QString());
		else
		{
			QString sql_code;
			vector<Constraint *> fks;

			dynamic_cast<Table *>(src_table)->getForeignKeys(fks, false, dynamic_cast<Table *>(dst_table));

			while(!fks.empty())
			{
				sql_code+=fks.back()->getCodeDefinition(SchemaParser::SQL_DEFINITION);
				fks.pop_back();
			}

			cached_code[def_type]=sql_code;
			return(sql_code);
		}
	}
	else
	{
		bool reduced_form;
		setRelationshipAttributes();
		reduced_form=(attributes[ParsersAttributes::POINTS].isEmpty() &&
								 attributes[ParsersAttributes::LABELS_POS].isEmpty());

		if(!reduced_form)
			cached_reduced_code.clear();

		return(BaseObject::getCodeDefinition(SchemaParser::XML_DEFINITION,reduced_form));
	}
}
예제 #16
0
파일: cast.cpp 프로젝트: Halfnhav/pgmodeler
QString Cast::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	if(def_type==SchemaParser::SQL_DEFINITION)
	{
		attributes[ParsersAttributes::SOURCE_TYPE]=(*types[SRC_TYPE]);
		attributes[ParsersAttributes::DEST_TYPE]=(*types[DST_TYPE]);
	}
	else
	{
		attributes[ParsersAttributes::SOURCE_TYPE]=types[SRC_TYPE].getCodeDefinition(def_type);
		attributes[ParsersAttributes::DEST_TYPE]=types[DST_TYPE].getCodeDefinition(def_type);
	}

	if(!is_in_out && cast_function)
	{
		if(def_type==SchemaParser::SQL_DEFINITION)
      attributes[ParsersAttributes::FUNCTION]=cast_function->getSignature();
		else
      attributes[ParsersAttributes::FUNCTION]=cast_function->getCodeDefinition(def_type, true);
	}
	else
		attributes[ParsersAttributes::IO_CAST]=(is_in_out ? ParsersAttributes::_TRUE_ : QString());

	if(cast_type==ASSIGNMENT)
		attributes[ParsersAttributes::CAST_TYPE]=ParsersAttributes::ASSIGNMENT;
	else if(cast_type==IMPLICIT)
		attributes[ParsersAttributes::CAST_TYPE]=ParsersAttributes::IMPLICIT;
	else
		attributes[ParsersAttributes::CAST_TYPE]=ParsersAttributes::EXPLICIT;

	if(def_type==SchemaParser::SQL_DEFINITION)
		attributes[ParsersAttributes::CAST_TYPE]=attributes[ParsersAttributes::CAST_TYPE].toUpper();

  return(BaseObject::__getCodeDefinition(def_type));
}
예제 #17
0
QString Permission::getCodeDefinition(unsigned def_type)
{
	QString code_def=getCachedCode(def_type, false);
	if(!code_def.isEmpty()) return(code_def);

	unsigned i, count;
	ObjectType obj_type;
	QString priv_vect[12]={ ParsersAttributes::SELECT_PRIV, ParsersAttributes::INSERT_PRIV,
													ParsersAttributes::UPDATE_PRIV, ParsersAttributes::DELETE_PRIV,
													ParsersAttributes::TRUNCATE_PRIV, ParsersAttributes::REFERENCES_PRIV,
													ParsersAttributes::TRIGGER_PRIV, ParsersAttributes::CREATE_PRIV,
													ParsersAttributes::CONNECT_PRIV, ParsersAttributes::TEMPORARY_PRIV,
													ParsersAttributes::EXECUTE_PRIV, ParsersAttributes::USAGE_PRIV };

	obj_type=object->getObjectType();

  attributes[ParsersAttributes::REVOKE]=(revoke ? ParsersAttributes::_TRUE_ : QString());
  attributes[ParsersAttributes::CASCADE]=(cascade ? ParsersAttributes::_TRUE_ : QString());
  attributes[ParsersAttributes::OBJECT]=object->getSignature();

	if(def_type==SchemaParser::SQL_DEFINITION)
	{
		//Views and Tables uses the same key word when setting permission (TABLE)
		attributes[ParsersAttributes::TYPE]=
		 (object->getObjectType()==OBJ_VIEW ? BaseObject::getSQLName(OBJ_TABLE): BaseObject::getSQLName(object->getObjectType()));
	}
	else
		attributes[ParsersAttributes::TYPE]=BaseObject::getSchemaName(object->getObjectType());

	if(obj_type==OBJ_COLUMN)
		attributes[ParsersAttributes::PARENT]=dynamic_cast<Column *>(object)->getParentTable()->getName(true);

	if(def_type==SchemaParser::XML_DEFINITION)
	{
		for(i=0; i < 12; i++)
		{
			if(privileges[i] && grant_option[i])
				attributes[priv_vect[i]]=ParsersAttributes::GRANT_OP;
			else if(privileges[i])
				attributes[priv_vect[i]]=ParsersAttributes::_TRUE_;
			else
        attributes[priv_vect[i]]=QString();
		}
	}
	else
	{
		for(i=0; i < 12; i++)
		{
			if(privileges[i] && !grant_option[i])
        attributes[ParsersAttributes::PRIVILEGES]+=priv_vect[i].toUpper() + QString(",");
			else if(grant_option[i])
        attributes[ParsersAttributes::PRIVILEGES_GOP]+=priv_vect[i].toUpper() + QString(",");
		}

		attributes[ParsersAttributes::PRIVILEGES].remove(attributes[ParsersAttributes::PRIVILEGES].size()-1,1);
		attributes[ParsersAttributes::PRIVILEGES_GOP].remove(attributes[ParsersAttributes::PRIVILEGES_GOP].size()-1,1);
	}

	count=roles.size();

	for(i=0; i < count; i++)
    attributes[ParsersAttributes::ROLES]+=roles[i]->getName(true) + QString(",");

	attributes[ParsersAttributes::ROLES].remove(attributes[ParsersAttributes::ROLES].size()-1,1);

  return(BaseObject::__getCodeDefinition(def_type));
}
예제 #18
0
QString Constraint::getCodeDefinition(unsigned def_type, bool inc_addedbyrel)
{
	QString code_def=getCachedCode(def_type, false);
	if(!inc_addedbyrel && !code_def.isEmpty()) return(code_def);

	QString attrib;

	attributes[ParsersAttributes::PK_CONSTR]=QString();
	attributes[ParsersAttributes::FK_CONSTR]=QString();
	attributes[ParsersAttributes::CK_CONSTR]=QString();
	attributes[ParsersAttributes::UQ_CONSTR]=QString();
	attributes[ParsersAttributes::EX_CONSTR]=QString();

	switch(!constr_type)
	{
		case ConstraintType::check:
			attrib=ParsersAttributes::CK_CONSTR;
		break;
		case ConstraintType::primary_key:
			attrib=ParsersAttributes::PK_CONSTR;
		break;
		case ConstraintType::foreign_key:
			attrib=ParsersAttributes::FK_CONSTR;
		break;
		case ConstraintType::unique:
			attrib=ParsersAttributes::UQ_CONSTR;
		break;
		default:
			attrib=ParsersAttributes::EX_CONSTR;
		break;
	}
	attributes[attrib]=ParsersAttributes::_TRUE_;

	attributes[ParsersAttributes::TYPE]=attrib;
	attributes[ParsersAttributes::UPD_ACTION]=(~upd_action);
	attributes[ParsersAttributes::DEL_ACTION]=(~del_action);
	attributes[ParsersAttributes::EXPRESSION]=expression;

	if(constr_type!=ConstraintType::check)
	{
		if(constr_type!=ConstraintType::exclude)
			setColumnsAttribute(SOURCE_COLS, def_type, inc_addedbyrel);
		else
			setExcludeElementsAttribute(def_type);

		/* Only generates the definition of the foreign key referenced columns
		 if the number of columns of the source and referenced cols list are equal,
		 this means the constraint is configured correctly, otherwise don't generates
		 the attribute forcing the schema parser to return an error because the foreign key is
		 misconfigured. */
		if(constr_type==ConstraintType::foreign_key && columns.size() == ref_columns.size())
			setColumnsAttribute(REFERENCED_COLS, def_type, inc_addedbyrel);
	}

	attributes[ParsersAttributes::REF_TABLE]=(ref_table ? ref_table->getName(true) : QString());
	attributes[ParsersAttributes::DEFERRABLE]=(deferrable ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::NO_INHERIT]=(no_inherit ? ParsersAttributes::_TRUE_ : QString());
	attributes[ParsersAttributes::COMPARISON_TYPE]=(~match_type);
	attributes[ParsersAttributes::DEFER_TYPE]=(~deferral_type);
	attributes[ParsersAttributes::INDEX_TYPE]=(~ index_type);

	if(getParentTable())
		attributes[ParsersAttributes::TABLE]=getParentTable()->getName(true);

	setDeclInTableAttribute();

	if(fill_factor!=0 && (constr_type==ConstraintType::primary_key || constr_type==ConstraintType::unique))
		attributes[ParsersAttributes::FACTOR]=QString("%1").arg(fill_factor);
	else
		attributes[ParsersAttributes::FACTOR]=QString();

	return(BaseObject::__getCodeDefinition(def_type));
}
예제 #19
0
파일: type.cpp 프로젝트: Ox0000/pgmodeler
QString Type::getCodeDefinition(unsigned def_type, bool reduced_form)
{
	QString code_def=getCachedCode(def_type, reduced_form);
	if(!code_def.isEmpty()) return(code_def);

	if(config==ENUMERATION_TYPE)
	{
		attributes[ParsersAttributes::ENUM_TYPE]=ParsersAttributes::_TRUE_;
		setEnumerationsAttribute(def_type);
	}
	else if(config==COMPOSITE_TYPE)
	{
		attributes[ParsersAttributes::COMPOSITE_TYPE]=ParsersAttributes::_TRUE_;
		setElementsAttribute(def_type);
	}
	else if(config==RANGE_TYPE)
	{
		attributes[ParsersAttributes::RANGE_TYPE]=ParsersAttributes::_TRUE_;

		if(def_type==SchemaParser::SQL_DEFINITION)
			attributes[ParsersAttributes::SUBTYPE]=(*subtype);
		else
			attributes[ParsersAttributes::SUBTYPE]=subtype.getCodeDefinition(SchemaParser::XML_DEFINITION);

		if(subtype_opclass)
		{
			if(def_type==SchemaParser::SQL_DEFINITION)
				attributes[ParsersAttributes::OP_CLASS]=subtype_opclass->getName(true);
			else
				attributes[ParsersAttributes::OP_CLASS]=subtype_opclass->getCodeDefinition(def_type, true);
		}
	}
	else
	{
		attributes[ParsersAttributes::BASE_TYPE]=ParsersAttributes::_TRUE_;

		if(internal_len==0 && def_type==SchemaParser::SQL_DEFINITION)
			attributes[ParsersAttributes::INTERNAL_LENGTH]=QString("VARIABLE");
		else
			attributes[ParsersAttributes::INTERNAL_LENGTH]=QString("%1").arg(internal_len);

		attributes[ParsersAttributes::BY_VALUE]=(by_value ? ParsersAttributes::_TRUE_ : QString());
		attributes[ParsersAttributes::ALIGNMENT]=(*alignment);
		attributes[ParsersAttributes::STORAGE]=(~storage);
		attributes[ParsersAttributes::DEFAULT_VALUE]=default_value;

		if(element!=QString("\"any\""))
			attributes[ParsersAttributes::ELEMENT]=(*element);

		if(delimiter!='\0')
			attributes[ParsersAttributes::DELIMITER]=delimiter;

		attributes[ParsersAttributes::CATEGORY]=~(category);

		attributes[ParsersAttributes::PREFERRED]=(preferred ? ParsersAttributes::_TRUE_ : QString());
		attributes[ParsersAttributes::COLLATABLE]=(collatable ? ParsersAttributes::_TRUE_ : QString());

		if(like_type!=QString("\"any\""))
		{
			if(def_type==SchemaParser::SQL_DEFINITION)
				attributes[ParsersAttributes::LIKE_TYPE]=(*like_type);
			else
				attributes[ParsersAttributes::LIKE_TYPE]=like_type.getCodeDefinition(SchemaParser::XML_DEFINITION);
		}
	}

	if(config==BASE_TYPE || config==RANGE_TYPE)
	{
		unsigned i;
		QString func_attrib[]={ParsersAttributes::INPUT_FUNC,
							   ParsersAttributes::OUTPUT_FUNC,
							   ParsersAttributes::RECV_FUNC,
							   ParsersAttributes::SEND_FUNC,
							   ParsersAttributes::TPMOD_IN_FUNC,
							   ParsersAttributes::TPMOD_OUT_FUNC,
							   ParsersAttributes::ANALYZE_FUNC,
							   ParsersAttributes::CANONICAL_FUNC,
							   ParsersAttributes::SUBTYPE_DIFF_FUNC};

		for(i=0; i < sizeof(functions)/sizeof(Function *); i++)
		{
			if(functions[i])
			{
				if(def_type==SchemaParser::SQL_DEFINITION)
					attributes[func_attrib[i]]=functions[i]->getName();
				else
				{
					functions[i]->setAttribute(ParsersAttributes::REF_TYPE, func_attrib[i]);
					attributes[func_attrib[i]]=functions[i]->getCodeDefinition(def_type, true);
				}
			}
		}
	}

	return(BaseObject::getCodeDefinition(def_type, reduced_form));
}