Re: 4gl and NULL integers with 7.30.UC1
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Actually, if you are checking for an empty string you can simply use: if length(x) = 0 then true else false end if because the length() function returns '0' for NULL, "", and " " David Williams wrote: > > In article <m3d7ee3ekg.fsf@yakisoba.forte-intl.com>, Ronald Cole > <ronald@forte-intl.com> writes > >Knowing full well that Informix always removes trailing blanks from a > >string, as a programmer, I expect "" and " " to be the same entity: a > > Then what is clipped for? > > To check for an 'empty string use' > > if (x is null) or (( length(x CLIPPED)) = 0) then > true > else > false > end if > > > >Informix will probably never fix this for legacy reasons, but that's > >no reason to perpetuate "" being interpreted as null in one's own code > >(and as an added bonus, if Informix *does* fix it, you won't have to > >change your code: yet another reason not to perpetuate the ""-is-null > >myth)! > > > True! > > >And that is the reason for me tossing in *my* two-cents. > > > >Have a happy New Year! > > > > -- > David Williams > > -- Colin McGrath colin.mcgrath@wgint.com Washington Group International, Inc. 010-1-215-422-4144 Philadelphia, PA, USA 19103 FAX: 010-1-215-422-1445 Any opinions I state are my own and not necessarily those of my employer
Colin McGrath <cmm@trac3000.ueci.com> writes: > Actually, if you are checking for an empty string you can simply use: > > if length(x) = 0 then > true > else > false > end if > > because the length() function returns '0' for NULL, "", and " " NULL is an out of band value. A zero-length string should not represent NULL. " " != "" is bad juju!! -- Forte International, P.O. Box 1412, Ridgecrest, CA 93556-1412 Ronald Cole <ronald@forte-intl.com> Phone: (760) 499-9142 President, CEO Fax: (760) 499-9152 My GPG fingerprint: C3AF 4BE9 BEA6 F1C2 B084 4A88 8851 E6C8 69E3 B00B
In article <m3r92ttkaj.fsf@yakisoba.forte-intl.com>, Ronald Cole <ronald@forte-intl.com> writes >Colin McGrath <cmm@trac3000.ueci.com> writes: >> Actually, if you are checking for an empty string you can simply use: >> >> if length(x) = 0 then >> true >> else >> false >> end if >> >> because the length() function returns '0' for NULL, "", and " " > >NULL is an out of band value. A zero-length string should not >represent NULL. " " != "" is bad juju!! However it's never given us any problems in some 100 person-years of Informix-4GL programming. > -- Surfer! Send email to: surfer at nevis-view dot demon dot co dot uk "I can resist anything but temptation" - Oscar Wilde ;-)
Surfer! <nevis-view@nospam.demon.co.uk> writes:
> However it's never given us any problems in some 100 person-years of
> Informix-4GL programming.
It's never given me any problems, either; because I don't use "" to
represent a null string in my 4gl code. Programmers that deliberately
confuse null strings with zero-length strings because they couldn't
figure out (or didn't care) that 4gl is broken, however, should be
publicly taken to task! Look at what SQL does:
> create table foo(c1 char(10), c2 char(10), c3 char(10));
Table created.
> insert into foo values ("A", "B", "C");
1 row(s) inserted.
> insert into foo values ("D", " ", "F");
1 row(s) inserted.
> insert into foo values ("G", "", "I");
1 row(s) inserted.
> insert into foo values ("J", NULL, "L");
1 row(s) inserted.
> select * from foo where c2 is null;
c1 c2 c3
J L
1 row(s) retrieved.
> select * from foo where c2 = "";
c1 c2 c3
D F
G I
2 row(s) retrieved.
That certainly demonstrates to me like SQL knows that "" is not null!
So, I repeat: 4gl is broken in interpreting "" as null, as "" should
be the zero-length string and " " should be equivalent to ""!
Good programmers who want to initialize a string to null in 4gl use:
INITIALIZE s TO NULL
Likewise, good programmers who want to initialize a string to the
zero-length string in 4gl use:
LET s = " "
Anything else is, IMO, bad form and an invitation for a maintenance
nightmare (Consider LET s = "" to be the Floridian equivalent of a
dimpled chad with the 4gl compiler representing a Democratic
canvassing board: the programmer may have meant to vote for Bush, but
the compiler will always count it as a vote for Gore.)
And that's my last word on the subject...
--
Forte International, P.O. Box 1412, Ridgecrest, CA 93556-1412
Ronald Cole <ronald@forte-intl.com> Phone: (760) 499-9142
President, CEO Fax: (760) 499-9152
My GPG fingerprint: C3AF 4BE9 BEA6 F1C2 B084 4A88 8851 E6C8 69E3 B00B