Re: Blobs: How to tell when I retrieved a null blob
Posted in 1997
Jonathan Leffler wrote: > >>From: Jacob Salomon <jake@apparel.net> >>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? > > Yes, but be very careful. > > DEFINE blob BYTE > LOCATE blob IN FILE > LET blob = NULL Jonathan, I used Marco's solution and located the blob variable in memory; then I assigned NULL to it. It worked but in retrospect, I don't think it would have made a difference. > 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. Actually, I had no trouble with this in RDS. I set blob var to null once for one test insert and easily re-located it in a file for another insert. No C was necessary. You have, however, just opened another can of worms, worthy of a separate thread: How would I pass a blob locator structure to a C function by reference? I was never aware of any syntax for doing this. Jake: >>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. Weellll.... I can't do any of that in 4GL, though I might register a futile feature request to give 4GL programmers acccess to the locater, if only via function calls. This would be an interesting exercise, in light of my previous remarks about passing by reference from 4GL. However, your other remark: > IF blobvar IS NULL THEN > ... > END IF That works juuuust fine! One more note of general interest: Before I posted my question, I had inserted my null blobs by locating them in /dev/null. Subsequent to Jonathan's and Marco's responses, I use the explicit null assignment. When I retrieved all these blobs in a debugging session, I found that: 1. The blobs I had inserted after a NULL assignment were indeed retrieved as NULL. Exactly as required by the app. 2. The blobs I had inserted after locating them in /dev/null were retrieved as well, but when I printed them (the PR command in fgldb) they displayed as "<Byte value>", not as "(Null)". Thanks, Jonathan and Marco, for your great help! -- -- Jake (Lost in thought and won't ask for directions) . . _..-'( )`-.._ ./'. '||\\\\. }\\_/{ .//||` .`\\. ./'.|'.'||||\\\\|.. )o o( ..|//||||`.`|.`\\. ./'..|'.|| |||||\\`````` \\,@,/ ''''''/||||| ||.`|..`\\. ./'.||'.|||| ||||||||||||. ||| .|||||||||||| ||||.`||.`\\. /'|||'.|||||| ||||||||||||{ | }|||||||||||| ||||||.`|||`\\ '.|||'.||||||| ||||||||||||{ | }|||||||||||| |||||||.`|||.` '.||| ||||||||| |/' ``\\||`` | ''||/'' `\\| ||||||||| |||.` |/' \\./' `\\./ \\!|\\ /|!/ \\./' `\\./ `\\| V V V }' `\\ /' `{ V V V \\ \\ \\ V / / / +-----------------------------------------------------------+ | Impeccable Logic: A thought process which successfully | | resists chicken bites | +-----------------------------------------------------------+