Example #1
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));
}
Example #2
0
QString Table::getCodeDefinition(unsigned def_type)
{
	attributes[ParsersAttributes::OIDS]=(with_oid ? "1" : "");
	attributes[ParsersAttributes::COPY_TABLE]="";

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

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

	setColumnsAttribute(def_type);
	setConstraintsAttribute(def_type);
	setTriggersAttribute(def_type);
	setIndexesAttribute(def_type);
	setRulesAttribute(def_type);

	if(def_type==SchemaParser::XML_DEFINITION)
		setPositionAttribute();

	return(BaseObject::__getCodeDefinition(def_type));
}
Example #3
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));
}