Re: Blobs, etc.
Posted in 1996
Hi,
We get two closely related questions in one morning, and both questions
omit enough key information to make answering difficult.
=== Question 1 ===
>From: jasonb@onr.com (Jason Bodnar)
>Subject: Inserting NULL values into a column of type TEXT?
>Date: Mon, 18 Nov 1996 18:01:32 GMT
>X-Informix-List-Id: <news.30593>
>
>I'm trying to insert a NULL value into a column of type TEXT but am
>getting the following error:
>
>617: A blob data type must be supplied within this context.>
>Here's the INSERT statement (trimmed for brevity):
>
>INSERT INTO current (title, review, photos, ...) VALUES ('Twister',\\>'may96/twister/twister.htm', NULL, ...);
>
>I also tried:
>
>INSERT INTO current (title, review, photos, ...) VALUES ('Twister',\\>'may96/twister/twister.htm', '', ...);
>
>Obviously, I can insert text into a column of type TEXT (the
>preceeding colum 'review' is of type text), but how can I insert a
>NULL value or an empty string?
=== Question 2 ===
>From: Gabriel Beccar-Varela <gabriel.beccar-varela@ucop.edu>
>Date: Mon, 18 Nov 1996 11:29:47 -0800
>Subject: Re: Inserting a value to a TEXT field
>X-Informix-List-Id: <news.30596>
>
>I would like to add records to a table which includes a TEXT field. I
>cannot find a way to do it using an INSERT...VALUES statement. I would
>appreciate any help. Thank you.
What happened to the useful (important) information like:
Which version of OnLine are you using?
On which machine?
Which language are you using?
For what it is worth, using OnLine 7.21.UC1 and ESQL/C 7.21.UC1 on Solaris
2.4, I prepared and executed the following statements:
CREATE TABLE blobs
(
i SERIAL NOT NULL PRIMARY KEY,
b BYTE IN TABLE,
t TEXT IN TABLE
);
INSERT INTO blobs VALUES(0, NULL, NULL);
So, I insert NULL blobs into either BYTE or TEXT blobs by specifying the
keyword NULL in the VALUES list. I checked that the insertion was OK by
counting the number of rows in the table, too.
I don't think that you can insert literal strings into a text blob:
INSERT INTO blobs VALUES (0, NULL, 'gibberish');SQL -617: A blob data type must be supplied within this context.
Note that a text blob is very different from any of the character types.
If you are using ISQL or DB-Access (which is basically what I was doing),
you have reached the limit on what you can do with blobs (apart from using
the LOAD and UNLOAD commands which have heavy-duty code in place to handle
blobs).
If you are using a programming language, then you both can and must do more
work. But, which language are you using?
In ESQL/C, you set up a loc_t type from <locator.h> with the correct
information. What's correct depends on where you are getting the blob data
from. In the 'Twister' example, I think I would use a blob located in a
file for the HTML information, and a blob in memory for the shorter string
information I think I see. Look in the manuals.
In I4GL, you could use the LOCATE statement to get the blob data into the
right places. You'd also be very careful about ever setting the blob to
null. Look in the manuals, again.
In NewEra, you have more ways of manipulating blobs -- I'm going to refer
you on to the manual. Look in the manuals yet again.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>