Re: Blobs: How to tell when I retrieved a null blob
Posted in 1997
>From: Jacob Salomon <jake@apparel.net>
>Date: Thu, 13 Feb 1997 10:17:37 GMT
>X-Informix-List-Id: <news.33861>
>
>2 questions, after verbose explanation.
>
>I am writing a small program to insert & retrieve blobs. Right now it's
>very simple: When a user wants to insert a blob, they type the name of
>a .gif file in a field in the form. My program LOCATEs the blob
>variable in the file and does the insert.
>
>If the user omits the file name, I still do the insert but first I
>locate the blob variable in /dev/null. I have confirmed that when I
>locate in /dev/null, the onstat -d shows no fewer free blob pages. So
>this works, though I'm sure there is a better way. My first question is:
>1. Is there something I can do in 4GL to specify a null location, so
> that my code won't even bother opening /dev/null? (For that matter,
> are the 4GL library functions smart enough to recognize /dev/null and
> skip opening it already?)
Yes, but be very careful.
DEFINE blob BYTE
LOCATE blob IN FILE
LET blob = NULL
After you've set the blob to NULL, it stays NULL permanently (there was a
bug entered about this some time ago; I forget the number). I think you
have to re-locate the blob to unset the null-ness pointer, or drop into C
(ESQL/C) code passing the blob (by reference, not value!) as an argument,
and therefore using poplocator() in the C code, and fiddle the indicator
portion of the loc_t structure you are given.
>Next is the issue of how I recognize a null blob when I read it back in.
>For now, I have hard coded the location before fetching the blob i.e.
>Before fetching it I code:
> LOCATE blobvar IN FILE "yutz.blob"
> FETCH blobcurs INTO blobvar
>
>2. How can I recognize when the blob data is null? In ESQL I could look
> at the length member variable of the locator structure (I think)
You could look at the length, but that will only tell you whether you have
an empty blob; an empty blob is not null. You should look at the indicator
field -- that tells you whether the blob is null or not.
Similarly, a zero-length VARCHAR field is different from a null VARCHAR at
the database storage level -- the zero-length field is stored as '\\0',
the null is stored as '\\001', '\\0'.
> but what do I look at in 4GL to see a 0-length? BTW, when I do the
> retrieval, I can see that the file "yutz.blob" is indeed 0 bytes
> long. I don't see anything in the sqlca that would warn me.
IF blobvar IS NULL THEN
...
END IF
Sometimes, it pays to try the obvious:-)
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>