Insert VARCHAR int TEXT field
Posted in 1997
At the FTP archive of Informix-related files I find the file : blob_char
with the function blob_to_char. Here is the code :
#include <locator.h>
#include <string.h>
blob_to_char(arg)
int arg;
{
loc_t *blobp;
short charsize, n;
char s1[513];
if (arg != 2)
fgl_fatal("blob_to_char.c", 18, -1318);
popshort(&charsize);
poplocator(&blobp);
if (charsize > 512)
charsize = 512;
n = (charsize < blobp->loc_size) ? charsize : blobp->loc_size;
strncpy(s1, blobp->loc_buffer, n);
s1[n] = '\\0';
/* Replace the CR/LF car. by SPACE car. */
cr_to_spc(s1);
pushquote(s1, n);
return(1);
}
4GL Code :
DEFINE MyVar CHAR(200)
DEFINE MyText TEXT
SELECT MyTable.FText INTO MyText FROM MyTable
CALL blob_to_char(200, MyText) RETURNING MyVAR
I want to make char to blob. This is my code. Is it correct ?
#include <locator.h>
#include <string.h>
char_to_blob(arg)
int arg;
{
loc_t *blobp;
short charsize, n;
char s1[513];
if (arg != 2)
fgl_fatal("char_to_blob.c", 18, -1318);
popshort(&charsize);
popquote(s1);
if (charsize > 512)
charsize = 512;
n = (charsize < blobp->loc_size) ? charsize : blobp->loc_size;
strncpy(blobp->loc_buffer, s1, n);
blobp->loc_buffer[n] = '\\0';
** a) solution
pushlocator(blobp, n); /* Does this function exists ? */
return(1);
** b) solution
$INSERT INTO MyTable VALUES(No, FText) = (0, blobp)
return(0);
** c) another solution ?
}
4GL Code :
DEFINE MyVar CHAR(200)
DEFINE MyText TEXT
LET MyVar = "The IIUG mailing list is a technical list about Informix
products"
** a) solution
CALL char_to_blob(200, MyVar) RETURNING MyText
** b) solution
CALL char_to_blob(200, MyVar)
SELECT MyTable.FText INTO MyText FROM MyTable
** c) solution
??????? -)).
I can test it because my database is producting.
I'm afraid of breaking the database.
I use Informix On-Line 5.01 and I4GL 4.11 UC4.
The schema of MyTable is :
CREATE TABLE MyTable (
No SERIAL,
Ftext TEXT IN TABLE}
Regards from France (Normandie).