Skip to content

Commit

Permalink
Fixed the reference to "any" type.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhaotix committed Mar 6, 2016
1 parent 4f20bc0 commit eefe8ab
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 49 deletions.
24 changes: 12 additions & 12 deletions libpgmodeler/src/operator.cpp
Expand Up @@ -31,8 +31,8 @@ Operator::Operator(void)
operators[i]=nullptr;

hashes=merges=false;
argument_types[LEFT_ARG]=PgSQLType(QString("any"));
argument_types[RIGHT_ARG]=PgSQLType(QString("any"));
argument_types[LEFT_ARG]=PgSQLType(QString("\"any\""));
argument_types[RIGHT_ARG]=PgSQLType(QString("\"any\""));

attributes[ParsersAttributes::LEFT_TYPE]=QString();
attributes[ParsersAttributes::RIGHT_TYPE]=QString();
Expand Down Expand Up @@ -112,7 +112,7 @@ void Operator::setFunction(Function *func, unsigned func_type)
else
{
unsigned param_count=func->getParameterCount();
PgSQLType param_type1=PgSQLType(QString("any")), param_type2=PgSQLType(QString("any"));
PgSQLType param_type1=PgSQLType(QString("\"any\"")), param_type2=PgSQLType(QString("\"any\""));

//Get the function parameter to make validations
param_type1=func->getParameter(0).getType();
Expand All @@ -121,25 +121,25 @@ void Operator::setFunction(Function *func, unsigned func_type)
//Validates the function parameters according to the operator arguments

//ERROR 1: The function have parameters of the type 'any'
if((param_type1==QString("any") || (param_count==2 && param_type2==QString("any"))) ||
if((param_type1==QString("\"any\"") || (param_count==2 && param_type2==QString("\"any\""))) ||

//ERROR 2: The function parameter count is 1 and the type of operator argument is not 'any'
(param_count==1 && argument_types[0]!=QString("any") && argument_types[1]!=QString("any")) ||
(param_count==1 && argument_types[0]!=QString("\"any\"") && argument_types[1]!=QString("\"any\"")) ||

//ERROR 3: The function parameter count is 2 and the operator arguments is not 'any'
(param_count==2 && ((argument_types[0]==QString("any") && argument_types[1]!=QString("any")) ||
(argument_types[0]!=QString("any") && argument_types[1]==QString("any")))) ||
(param_count==2 && ((argument_types[0]==QString("\"any\"") && argument_types[1]!=QString("\"any\"")) ||
(argument_types[0]!=QString("\"any\"") && argument_types[1]==QString("\"any\"")))) ||

/* ERROR 4: The function parameter count is 2 and the argument types differs from
parameters type */
(param_count==2 &&
((argument_types[0]==QString("any") || argument_types[1]==QString("any")) ||
((argument_types[0]==QString("\"any\"") || argument_types[1]==QString("\"any\"")) ||
(argument_types[0]!=param_type1 || argument_types[1]!=param_type2))) ||

//ERROR 5: When the function has 1 parameter the type differ from the operator argument
(param_count==1 &&
((argument_types[0]!=QString("any") && argument_types[0]!=param_type1) ||
(argument_types[1]!=QString("any") && argument_types[1]!=param_type1))))
((argument_types[0]!=QString("\"any\"") && argument_types[0]!=param_type1) ||
(argument_types[1]!=QString("\"any\"") && argument_types[1]!=param_type1))))
throw Exception(Exception::getErrorMessage(ERR_ASG_FUNCTION_INV_PARAMS)
.arg(this->getName())
.arg(BaseObject::getTypeName(OBJ_OPERATOR)),
Expand Down Expand Up @@ -259,7 +259,7 @@ QString Operator::getSignature(bool format_name)

for(i=0; i < 2; i++)
{
if(argument_types[i]==QString("any"))
if(argument_types[i]==QString("\"any\""))
args.push_back(QString("NONE"));
else
args.push_back(*argument_types[i]);
Expand Down Expand Up @@ -292,7 +292,7 @@ QString Operator::getCodeDefinition(unsigned def_type, bool reduced_form)
{
if(def_type==SchemaParser::SQL_DEFINITION)
{
if(argument_types[i]!=QString("any"))
if(argument_types[i]!=QString("\"any\""))
attributes[type_attribs[i]]=(*argument_types[i]);
}
else
Expand Down
30 changes: 19 additions & 11 deletions libpgmodeler/src/pgsqltypes.cpp
Expand Up @@ -114,7 +114,7 @@ QString BaseType::type_list[types_count]=

//Pseudo-types
//offsets 121 to 135
"any","anyarray","anyelement","anyenum",
"\"any\"","anyarray","anyelement","anyenum",
"anynonarray", "anyrange", "cstring","internal","language_handler",
"record","trigger","void","opaque", "fdw_handler", "event_trigger",

Expand All @@ -137,16 +137,17 @@ QString BaseType::type_list[types_count]=
"SECURITY DEFINER",

//Types used by the class LanguageType
//offsets 154 to 159
//offsets 154 to 160
"sql",
"c",
"plpgsql",
"pltcl",
"plperl",
"plpython",
"internal",

//Types used by the class EncodingType
//offsets 160 to 200
//offsets 161 to 201
"UTF8", "BIG5", "EUC_CN", "EUC_JP", "EUC_JIS_2004", "EUC_KR",
"EUC_TW", "GB18030", "GBK", "ISO_8859_5", "ISO_8859_6",
"ISO_8859_7", "ISO_8859_8", "JOHAB", "KOI", "LATIN1",
Expand All @@ -158,25 +159,25 @@ QString BaseType::type_list[types_count]=
"WIN1258",

//Types used by the class StorageType
//offsets 201 to 204
//offsets 202 to 205
"plain",
"external",
"extended",
"main",

//Types used by the class MatchType
//offsets 205 to 207
//offsets 206 to 208
"MATCH FULL",
"MATCH PARTIAL",
"MATCH SIMPLE",

//Types used by the class DeferralType
//offsets 208 to 209
//offsets 209 to 210
"INITIALLY IMMEDIATE",
"INITIALLY DEFERRED",

//Types used by the class CategoryType
//offsets 210 to 223 - See table 44-43 on PostgreSQL 8.4 documentation
//offsets 211 to 224 - See table 44-43 on PostgreSQL 8.4 documentation
"U", //User-defined types
"A", //Array types
"B", //Boolean types
Expand All @@ -193,7 +194,7 @@ QString BaseType::type_list[types_count]=
"X", //Unknown type

//Types used by the class FiringType
//offsets 224 to 226
//offsets 225 to 227
"BEFORE",
"AFTER",
"INSTEAD OF",
Expand All @@ -202,7 +203,7 @@ QString BaseType::type_list[types_count]=
These types accepts variations Z, M e ZM.
> Example: POINT, POINTZ, POINTM, POINTZM
Reference: http://postgis.refractions.net/documentation/manual-2.0/using_postgis_dbmanagement.html */
//offsets 227 to 234
//offsets 228 to 235
"POINT",
"LINESTRING",
"POLYGON",
Expand All @@ -213,7 +214,7 @@ QString BaseType::type_list[types_count]=
"GEOMETRYCOLLECTION",

//Types used by the class EventTriggerType
//offsets 235 to 237
//offsets 236 to 239
"ddl_command_start",
"ddl_command_end",
"sql_drop",
Expand Down Expand Up @@ -1276,7 +1277,14 @@ QString PgSQLType::operator ~ (void)
if(type_idx >= pseudo_end + 1)
return(user_types[type_idx - (pseudo_end + 1)].name);
else
return(BaseType::type_list[type_idx]);
{
QString name=BaseType::type_list[type_idx];

if(with_timezone && (name==QString("time") || name==QString("timestamp")))
name+=QString(" with time zone");

return(name);
}
}

bool PgSQLType::isArrayType(void)
Expand Down
19 changes: 10 additions & 9 deletions libpgmodeler/src/pgsqltypes.h
Expand Up @@ -33,7 +33,7 @@

class BaseType{
protected:
static const unsigned types_count=239;
static const unsigned types_count=240;
static QString type_list[types_count];

//! \brief Index of the type on the type_list vector
Expand Down Expand Up @@ -535,7 +535,7 @@ class SecurityType: public BaseType{
class LanguageType: public BaseType{
private:
static const unsigned offset=154;
static const unsigned types_count=6;
static const unsigned types_count=7;

public:
static const unsigned sql=offset;
Expand All @@ -544,6 +544,7 @@ class LanguageType: public BaseType{
static const unsigned pltcl=offset+3;
static const unsigned plperl=offset+4;
static const unsigned plpython=offset+5;
static const unsigned internal=offset+6;

LanguageType(const QString &type_name);
LanguageType(unsigned type_id);
Expand All @@ -556,7 +557,7 @@ class LanguageType: public BaseType{

class EncodingType: public BaseType{
private:
static const unsigned offset=160;
static const unsigned offset=161;
static const unsigned types_count=41;

public:
Expand All @@ -576,7 +577,7 @@ class EncodingType: public BaseType{

class StorageType: public BaseType{
private:
static const unsigned offset=201;
static const unsigned offset=202;
static const unsigned types_count=4;

public:
Expand All @@ -599,7 +600,7 @@ class StorageType: public BaseType{

class MatchType: public BaseType{
private:
static const unsigned offset=205;
static const unsigned offset=206;
static const unsigned types_count=3;

public:
Expand All @@ -618,7 +619,7 @@ class MatchType: public BaseType{

class DeferralType: public BaseType{
private:
static const unsigned offset=208;
static const unsigned offset=209;
static const unsigned types_count=2;

public:
Expand All @@ -636,7 +637,7 @@ class DeferralType: public BaseType{

class CategoryType: public BaseType{
private:
static const unsigned offset=210;
static const unsigned offset=211;
static const unsigned types_count=14;

public:
Expand Down Expand Up @@ -666,7 +667,7 @@ class CategoryType: public BaseType{

class FiringType: public BaseType{
private:
static const unsigned offset=224;
static const unsigned offset=225;
static const unsigned types_count=3;

public:
Expand All @@ -685,7 +686,7 @@ class FiringType: public BaseType{

class EventTriggerType: public BaseType{
private:
static const unsigned offset=235;
static const unsigned offset=236;
static const unsigned types_count=4;

public:
Expand Down
27 changes: 14 additions & 13 deletions libpgmodeler/src/type.cpp
Expand Up @@ -194,14 +194,14 @@ void Type::setConfiguration(unsigned conf)
setCollation(nullptr);
subtype_opclass=nullptr;

alignment="integer";
alignment=QString("integer");
delimiter='\0';
storage=StorageType::plain;
element="any";
element=QString("\"any\"");
internal_len=0;
category=CategoryType::userdefined;
preferred=collatable=by_value=false;
like_type="any";
like_type=QString("\"any\"");

this->config=conf;
setCodeInvalidated(true);
Expand Down Expand Up @@ -239,7 +239,8 @@ void Type::setFunction(unsigned func_id, Function *func)
/* Raises an error if the function language is not C.
Functions assigned to base type must be written in C */
if((func_id!=CANONICAL_FUNC && func_id!=SUBTYPE_DIFF_FUNC) &&
func->getLanguage()->getName()!=(~lang))
func->getLanguage()->getName()!=~LanguageType(LanguageType::c) &&
func->getLanguage()->getName()!=~LanguageType(LanguageType::internal))
throw Exception(ERR_ASG_FUNC_INV_LANGUAGE,__PRETTY_FUNCTION__,__FILE__,__LINE__);

/* Raises an error if the parameter count for INPUT and RECV functions
Expand All @@ -262,14 +263,14 @@ void Type::setFunction(unsigned func_id, Function *func)
OUTPUT and TPMOD_OUT should return cstring.
The other functions SEND, TPMOD_IN and ANALYZE should return bytea, integer and boolean,
respectively. Raises an error if some of conditions above is not satisfied. */
else if((func_id==INPUT_FUNC && func->getReturnType()!=QString("any")) ||
else if((func_id==INPUT_FUNC && func->getReturnType()!=QString("\"any\"")) ||
(func_id==OUTPUT_FUNC && func->getReturnType()!=QString("cstring")) ||
(func_id==RECV_FUNC && func->getReturnType()!=QString("any")) ||
(func_id==RECV_FUNC && func->getReturnType()!=QString("\"any\"")) ||
(func_id==SEND_FUNC && func->getReturnType()!=QString("bytea")) ||
(func_id==TPMOD_IN_FUNC && func->getReturnType()!=QString("integer")) ||
(func_id==TPMOD_OUT_FUNC && func->getReturnType()!=QString("cstring")) ||
(func_id==ANALYZE_FUNC && func->getReturnType()!=QString("boolean")) ||
(func_id==CANONICAL_FUNC && func->getReturnType()!=QString("any")) ||
(func_id==CANONICAL_FUNC && func->getReturnType()!=QString("\"any\"")) ||
(func_id==SUBTYPE_DIFF_FUNC && func->getReturnType()!=QString("double precision")))
throw Exception(Exception::getErrorMessage(ERR_ASG_FUNCTION_INV_RET_TYPE)
.arg(this->getName())
Expand All @@ -295,7 +296,7 @@ void Type::setFunction(unsigned func_id, Function *func)
(param_count==3 &&
(func->getParameter(1).getType()!=QString("oid") ||
func->getParameter(2).getType()!=QString("integer"))))) ||
((func_id==SEND_FUNC || func_id==CANONICAL_FUNC || func_id==OUTPUT_FUNC) && func->getParameter(0).getType()!=QString("any")) ||
((func_id==SEND_FUNC || func_id==CANONICAL_FUNC || func_id==OUTPUT_FUNC) && func->getParameter(0).getType()!=QString("\"any\"")) ||
(func_id==TPMOD_IN_FUNC && *(func->getParameter(0).getType())!=QString("cstring[]")) ||
(func_id==TPMOD_OUT_FUNC && func->getParameter(0).getType()!=QString("integer")) ||
(func_id==ANALYZE_FUNC && func->getParameter(0).getType()!=QString("internal")) ||
Expand Down Expand Up @@ -339,7 +340,7 @@ void Type::convertFunctionParameters(bool inverse_conv)
}
else
{
param.setType(PgSQLType(QString("any")));
param.setType(PgSQLType(QString("\"any\"")));
func->addParameter(param);
}
}
Expand All @@ -348,7 +349,7 @@ void Type::convertFunctionParameters(bool inverse_conv)
if(!inverse_conv)
func->setReturnType(PgSQLType(this));
else
func->setReturnType(PgSQLType(QString("any")));
func->setReturnType(PgSQLType(QString("\"any\"")));
}
}
}
Expand Down Expand Up @@ -400,7 +401,7 @@ void Type::setElement(PgSQLType elem)
if(PgSQLType::getUserTypeIndex(this->getName(true), this) == !elem)
throw Exception(Exception::getErrorMessage(ERR_USER_TYPE_SELF_REFERENCE).arg(this->getName(true)),
ERR_USER_TYPE_SELF_REFERENCE,__PRETTY_FUNCTION__,__FILE__,__LINE__);
else if(elem!=QString("any") &&
else if(elem!=QString("\"any\"") &&
(elem.isOIDType() || elem.isPseudoType() ||
elem.isUserType() || elem.isArrayType()))
throw Exception(Exception::getErrorMessage(ERR_ASG_INV_ELEMENT_TYPE).arg(this->getName(true)),
Expand Down Expand Up @@ -655,7 +656,7 @@ QString Type::getCodeDefinition(unsigned def_type, bool reduced_form)
attributes[ParsersAttributes::STORAGE]=(~storage);
attributes[ParsersAttributes::DEFAULT_VALUE]=default_value;

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

if(delimiter!='\0')
Expand All @@ -666,7 +667,7 @@ QString Type::getCodeDefinition(unsigned def_type, bool reduced_form)
attributes[ParsersAttributes::PREFERRED]=(preferred ? ParsersAttributes::_TRUE_ : QString());
attributes[ParsersAttributes::COLLATABLE]=(collatable ? ParsersAttributes::_TRUE_ : QString());

if(like_type!=QString("any"))
if(like_type!=QString("\"any\""))
{
if(def_type==SchemaParser::SQL_DEFINITION)
attributes[ParsersAttributes::LIKE_TYPE]=(*like_type);
Expand Down
8 changes: 4 additions & 4 deletions samples/oldsample.dbm
Expand Up @@ -126,7 +126,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<comment><![CDATA[Comentário na função input]]></comment>
<language name="c" sql-disabled="true"/>
<return-type>
<type name="any"/>
<type name="&quot;any&quot;"/>
</return-type>
<parameter name="param1">
<type name="cstring"/>
Expand Down Expand Up @@ -156,7 +156,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<type name="cstring"/>
</return-type>
<parameter name="param1">
<type name="any"/>
<type name="&quot;any&quot;"/>
</parameter>
<definition library="/usr/local/lib/funcoes.so" symbol="funcao_handler"/>
</function>
Expand All @@ -174,7 +174,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<comment><![CDATA[Comentário na função recv]]></comment>
<language name="c" sql-disabled="true"/>
<return-type>
<type name="any"/>
<type name="&quot;any&quot;"/>
</return-type>
<parameter name="param1">
<type name="internal"/>
Expand Down Expand Up @@ -204,7 +204,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<type name="bytea"/>
</return-type>
<parameter name="param1">
<type name="any"/>
<type name="&quot;any&quot;"/>
</parameter>
<definition library="/usr/local/lib/funcoes.so" symbol="funcao_handler"/>
</function>
Expand Down

0 comments on commit eefe8ab

Please sign in to comment.