#include<stdio.h>
#include<string.h>
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
char SQLMSG[256];
short datano;
SQL TYPE IS BLOB *image;
EXEC SQL END DECLARE SECTION;
void putmsgx(void);
main(void){
short execute;
EXEC SQL WHENEVER SQLERROR GOTO :CONNECT_ERROR;
EXEC SQL CONNECT TO 'DB01';
EXEC SQL WHENEVER SQLERROR GOTO :STM_ERROR;
EXEC SQL WHENEVER NOT FOUND GOTO :NOT_FOUND_ERROR;
image = (struct image_SQLBLOB *)malloc( 10240 + 8 );
image->image_length = 10240;
datano = 5;
/* データの取得 */
EXEC SQL SELECT IMAGE
INTO :image
FROM SCH01.TBL01
WHERE DATANO = :datano;
/* 最初の50バイトを出力 */
image->image_data[50] = '\0';
printf("データ(%d)%s\n",image->image_length,image->image_data);
STM_ERROR:
putmsgx();
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL COMMIT WORK;
EXEC SQL DISCONNECT 'DB01';
return 1;
NOT_FOUND_ERROR:
printf("\n該当データはありません.\n");
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK;
EXEC SQL DISCONNECT 'DB01';
return 0;
CONNECT_ERROR:
putmsgx();
return 1;
}
void putmsgx( void ) {
int i;
for ( i = sizeof(SQLMSG) - 2 ; SQLMSG[i] == ' ' ; i-- );
SQLMSG[++i] = '\0';
SQLSTATE[5]='\0';
printf( "SQLMSG:%s\n" , SQLMSG );
printf( "SQLSTATE:%s\n" , SQLSTATE );
return;
} |