Problem with ALTER TYPE_OF

This forum is to report technical problems with Rel.
Post Reply
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Problem with ALTER TYPE_OF

Post by steved »

I like ALTER especially as a handy point and click convenience.

Code: Select all

VAR T1 BASE REL{A CHAR, B INT, C RAT, D CHAR, E INT, F RAT}KEY{ };
T1:=REL{TUP{A "10", B 10, C 10.0, D "20", E 20, F 20.0}};
Changes from integer and rational respectively to character are successful.

Code: Select all

ALTER VAR T1
	TYPE_OF B TO CHARACTER
	TYPE_OF C TO CHARACTER;
WRITELN T1{ATTRIBUTES_OF(T1)};

RELATION {A CHARACTER, D CHARACTER, E INTEGER, F RATIONAL, B CHARACTER, C CHARACTER} {
     TUPLE {A "10", D "20", E 20, F 20.0, B "10", C "10.0"}}
Now try to apply the following changes to above relation:

Change from character to integer:

Code: Select all

ALTER VAR T1
	TYPE_OF B TO INTEGER;

Returns:

Code: Select all

	
ERROR: RS0278: No run-time invocation targets found for INTEGER(CHARACTER)     

Code: Select all

ALTER VAR T1
	TYPE_OF A TO INTEGER;
Returns:

Code: Select all

ERROR: RS0278: No run-time invocation targets found for INTEGER(CHARACTER)	
Change from character to rational:

Code: Select all

ALTER VAR T1
	TYPE_OF C TO RATIONAL;
Returns:

Code: Select all

ERROR: RS0278: No run-time invocation targets found for RATIONAL(CHARACTER)
Change from integer to rational:

Code: Select all

ALTER VAR T1
	TYPE_OF E TO RATIONAL;
Returns:

Code: Select all

ERROR: RS0278: No run-time invocation targets found for RATIONAL(CHARACTER)
Change from rational to integer:

Code: Select all

ALTER VAR T1
	TYPE_OF F TO INTEGER;
Returns:

Code: Select all

ERROR: RS0278: No run-time invocation targets found for INTEGER(CHARACTER)
I just note that every error suggests an operand of CHARACTER regardless of whether CHARACTER is
part of TYPE_OF or not.

thanks
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Problem with ALTER TYPE_OF

Post by steved »

Currently I would like new users to have the ability to open a relvar with multiple attributes with type character
in Design view and change any of these character based attributes to either integer or rational (via ALTER VAR TYPE_OF)
simply using point and click. Being able to change an integer based attribute to rational or visa versa would also be
expected. The general idea is to allow new users this capability and avoid them having write a query(s) to do this.
This is part of what i think of as surface Rel, capabilities using simple point and click that enable new users to do
things without getting too deep into the ra (at least until they're ready to do so). i hope what I'm expecting of ATLER
VAR is feasible.

thanks
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Problem with ALTER TYPE_OF

Post by Dave »

steved wrote: Sun Apr 01, 2018 6:26 am ...
Now try to apply the following changes to above relation:

Change from character to integer:

Code: Select all

ALTER VAR T1
	TYPE_OF B TO INTEGER;

Returns:

Code: Select all

	
ERROR: RS0278: No run-time invocation targets found for INTEGER(CHARACTER)     
...
This isn't actually a bug, except to the extent that my poor (read: nonexistent) documentation is a bug.

What the message is telling you is that to convert a CHARACTER attribute to an INTEGER attribute, it needs to find an operator with the signature INTEGER(CHARACTER) RETURNS INTEGER that will perform the conversion.

Once you have such an operator -- which will have to be able to deal with quote-delimited strings, if I recall correctly -- the type conversion will work.
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Problem with ALTER TYPE_OF

Post by steved »

Hi,

Any operator I try with the signature OPERATOR INTEGER(P CHARACTER) RETURNS INTEGER works outside of ALTER VAR.
When ALTER VAR is used it always returns an error that the string is invalid:

Code: Select all

ERROR: RS0390: '"10"' isn't a valid number.
Any chance you can spoon feed the appropriate operator and show how to deal with quote-delimited strings in this context?

thanks
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Problem with ALTER TYPE_OF

Post by Dave »

Try this:

Code: Select all

OPERATOR INTEGER(v CHAR) RETURNS INTEGER;
	RETURN CAST_AS_INTEGER(SUBSTRING(v, 1, LENGTH(v) - 1));
END OPERATOR;
steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Problem with ALTER TYPE_OF

Post by steved »

How stunningly obvious . How stunningly stupid I feel :( Nevertheless, thanks!
Post Reply