Informix数据库中如何插入BYTE大对象

【字号: 日期:2023-08-16浏览:54作者:雯心
环境:wmware + sco+informix +esql/c

表结构:create table blobdemo( col_1 ingeger, col_2 byte in blobdbs) in datadbs;

代码如下:

#include

#include

#include

#include

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 okn' );

}

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 );

)

相关文章: