#include<stdio.h>
#include<string.h>
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
char SQLMSG[256];
struct {
long num;
char name[21];
char atta[41];
short year;
} data;
short number;
EXEC SQL END DECLARE SECTION;
void putmsgx(void);
main(void){
short execute;
memset( &data, 0x00, sizeof( data ) );
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;
number = 1;
/* データの取得 */
EXEC SQL SELECT COL01, COL02, COL03, COL04 INTO :data
FROM SCH01.TBL01
WHERE NUMBER = :number;
printf( "COL1=%d", data.num );
printf( "COL2=%s", data.name );
printf( "COL3=%s", data.atta );
printf( "COL4=%d", data.year );
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;
} |