#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;
struct {
short ind[4];
} indi;
short number;
EXEC SQL END DECLARE SECTION;
void putmsgx(void);
main(void){
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 * INTO :data :indi
FROM SCH01.TBL01
WHERE NUMBER = :number;
printf( "COL1=%d", data.num );
printf( "IND=%d", indi.ind[1] );
printf( "COL2=%s", data.name );
printf( "IND=%d", indi.ind[2] );
printf( "COL3=%s", data.atta );
printf( "IND=%d", indi.ind[3] );
printf( "COL4=%d", data.year );
printf( "IND=%d", indi.ind[4] );
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;
}
|