informix如何插入BYTE大对象
环境:wmware + sco+informix +esql/c
表结构:create table blobdemo( col_1 ingeger, col_2 byte in blobdbs) in datadbs;
代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
EXEC SQL INCLUDESQLCA;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
int id;
char msg[ 20 ];
loc_t photo;
memset( msg, 0x00,sizeof( msg ));
/* connect db */
EXEC SQL DATABASE pcsp;
if( sqlca.sqlcode != 0 )
{
fprintf( stderr, "connect db with error [%d][%s]/n", sqlca.sqlcode, sqlca.sqlerrm );
return( -1 );
}
else
{
fprintf( stderr, "connect db ok/n" );
}
id = 0;
strcpy( msg, "hello");
photo.loc_loctype = LOCMEMORY;
photo.loc_bufsize = strlen( msg);
photo.loc_buffer = msg;
photo.loc_size = strlen( msg );
photo.loc_mflags = 0;
EXEC SQL INSERT INTO BLOBDEMO( col_1, col_2 ) VALUES( :id, :photo );
if( sqlca.sqlcode != 0 )
{
fprintf( stderr, "INSERT with failure [%d][%s]/n", sqlca.sqlcode, sqlca.sqlerrm );
return( -1 );
}
/* disconnect db */
EXEC SQL CLOSE DATABASE;
return( 0 );
)