首页 > 开发 > 综合 > 正文

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

2024-07-21 02:42:12
字体:
来源:转载
供稿:网友
环境: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 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 );

)


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表