Re: how to convert datatypes ?
Posted in 1996
Michael,
Before I go any further, let me point out that I cannot claim to be an
unbiassed observer on this, but I do have what may be some useful
information...
You also do not specify which Informix language you are using, which always
makes it more difficult to give an appropriate response. I'm going to
assume that you are referring to I4GL, but you might be referring to SPL
(Stored Procedure Language), in which case some of the comments are
somewhat different, but I go through the differences at the end of this
message.
>From: "Michael Agbaglo" <byteshif@cs.tu-berlin.de>
>Date: 1 Dec 1996 19:10:15 GMT
>X-Informix-List-Id: <news.31081>
>
>First I had to write extra code because this amateur programmers a informix
>weren't able to implement select ... into ... order by.
Pardon? As far as I know you can do:
DECLARE c_order CURSOR FOR
SELECT ...
INTO ...
FROM ...
ORDER BY ...
I can certainly get that to work for me, though I suppose it might not work
for you for some very peculiar reason -- you'd have to give a detailed
example to demonstrate that. Of course, if you've prepared the SELECT
statement, then you have to omit the INTO part from the PREPARE and DECLARE
and specify it in the FOREACH instead, but there are sound reasons for
that.
>Then I browsed the manuals for 'convert' w/o success. When I do a
>LET Stmt = VARCHAR( foo );
>it thinks VARCHAR is a procedure --- Arrgh!
I4GL converts implicitly -- it doesn't need casts as it will do the
conversion for you. So, if 'foo' is any type of variable except a blob,
and Stmt is a VARCHAR, then:
LET Stmt = foo;
will do the relevant conversion for you. No need to put in explicit
conversions at all.
>Then I browsed for string functions - nothing, no MID, LEFT, RIGHT...
Well, these are mainly a question of what you're used to. I've not used
those functions since I left BASIC behind, so I'd not go looking for them.
Let's take LEFT(), first. I assume you want to write something like:
LET substr = LEFT(string, len)
In I4GL, you do that with:
LET substr = string[1, len]
Dealing with RIGHT() next, I assume you want to write something like:
LET substr = RIGHT(string, len)
In I4GL, you do that with something based on:
LET substr = string[LENGTH(string)-len+1, LENGTH(string)]
And assuming that MID() should be used something like:
LET substr = MID(string, start, len)
In I4GL, you do that with:
LET substr = string[start, start+len-1]
>Have they been exhausted by implementing 'LENGTH' ?
No.
>If someone what's to implement a shit app - forget it Informix already did
>it !
I disagree whole-heartedly. Go to some other language like Perl, and see
whether there is a LEFT(), RIGHT() or MID() function built-in. The answer
is "No, it isn't". But that doesn't mean that it is impossible to achieve
the same effect, nor that it is impossible write a set of functions called
LEFT(), RIGHT() and MID() which do the same as the functions you are used
to using in some other language. Similarly, in I4GL, there are different
ways of achieving the same result, and nothing to stop you writing a set of
functions which do what I did in a single statement.
Now, what would be different if you are slamming SPL instead of I4GL? The
implicit conversions act the same in SPL as in I4GL. And you can use
cursors on ordered data in SPL. There isn't any dynamic SQL in SPL to
confuse the issue. OTOH, the obvious problem is that SPL does not allow
variable substring operations, so you cannot write the code I wrote above
in SPL. That is a serious problem, but it will be fixed (directly or
indirectly) by the Informix Universal Server, due to be released before the
end of this year.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>