Re:Creating UDFs
"Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> wrote in message
news:3C02CD31.7FF72F6B@no_spam.vertexsoftware.com...
Quote
> > SQL> select rtrim('hello ')||'x' from rdb$database;
> > =====================================================
> > hellox
> That much works fine for the concatenation, but:
> select rtrim('hello ') from rdb$database;
> ...will return "hello" with 75 spaces after it, which you might not be
> able to see in ISQL but which is very obvious in IBConsole. Since the
> result type is CSTRING(80) this seems to come out as a CHAR(80), making
> the RTRIM pointless. The CAST to VARCHAR fixes the problem
I didn't understand the point. Now I can tell you the reason: in the DSQL
layer, someone (from Borland, I suppose) wrote an interesting comment saying
that since SQL doesn't deal with CSTRING, UDFs returning CSTRING are set to
return CHAR(n) instead. This is at run-time, when a UDF call is analyzed as
part of an statement. The same person asked himself in the comment "why not
VARCHAR???" and for obvious reasons, it was my question, too. I've been
tempted a couple of times to do the change, but there may be a valid reason
why CHAR is used, so I did nothing. Now, if you could ask someone from
"inside", it would be better. What made me very cautious was that I couldn't
find a problem in the change... and when you can't see the bug that's
{*word*154} a small distance above you head... you know.
C.
--
Claudio Valderrama C. - http://www.cvalde.com - http://www.firebirdSql.org
Independent developer
Owner of the Interbase? WebRing