#include<stdio.h>
#include<string.h>
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
char SQLMSG[256];
char *country;
short count;
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;
country = (char *)malloc(256);
printf("国名を入力します.\n");
count = 1;
for(;;){
printf("%d件目の国名を入力してください >> ", count);
gets(country);
printf("\n");
printf("\"%s\"でよろしいですか?\n",country);
printf("よろしかったら(Y/y)を入力してください >>");
execute=getchar();
if(execute=='Y' || execute=='y'){
printf("\n");
EXEC SQL INSERT INTO SCH.TBL( COUNTRY, DATANO )
VALUES( :country, :count );
count++;
printf("入力を終えますか?(Y/y) >>");
execute=getchar();
if(execute=='Y' || execute=='y'){
break;
}
}
}
printf("\n");
EXEC SQL INSERT INTO SCH.TBL( COUNTRY )
VALUES( :country );
STM_ERROR:
putmsgx();
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL COMMIT WORK;
EXEC SQL DISCONNECT 'DB01';
return 1;
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;
} |