#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "sqlca.h"
exec sql begin declare section;
char sfzbh[5];
char chsfzbh[5];
char tjrqz[15];
char chtjrqz[15];
char cxdmz[2];
char sfdmz[2];
exec sql end declare section;
int test_insert()
{
printf("please input your sfzbh:");
scanf("%s", sfzbh);
printf("please input your tjrqz:");
scanf("%s", tjrqz);
printf("please input your cxdmz:");
scanf("%s", cxdmz);
printf("please input your sfdmz:");
scanf("%s", sfdmz);
exec sql insert into test values(:sfzbh,:tjrqz,:cxdmz,:sfdmz);
if(sqlca.sqlcode)
{
printf("insert data into table error[%d]\n",sqlca.sqlcode);
exit(1);
}
return 0;
}
int test_select()
{
printf("please input your sfzbh:");
scanf("%s", chsfzbh);
exec sql select * into :sfzbh,:tjrqz,:cxdmz,:sfdmz from test where sfzbh=:chsfzbh;
if(sqlca.sqlcode)
{
printf("select from test error[%d]\n",sqlca.sqlcode);
exit(0);
}
printf("SFZBH=%s\n",sfzbh);
printf("TJRQZ=%s\n",tjrqz);
printf("CXDMZ=%s\n",cxdmz);
printf("SFDMZ=%s\n",sfdmz);
return 0;
}
int test_update()
{
printf("please input your sfzbh:");
scanf("%s", chsfzbh);
printf("please input your tjrqz:");
scanf("%s", chtjrqz);
exec sql update test set tjrqz=:chtjrqz where sfzbh=:chsfzbh;
if(sqlca.sqlcode)
{
printf("update error[%d]\n",sqlca.sqlcode);
exit(0);
}
return 0;
}
int main(int argc,char *argv[])
{
exec sql begin declare section;
char sfzbh[4];
char tjrqz[15];
char cxdmz[1];
char sfdmz[1];
exec sql end declare section;
fflush(stdout);
exec sql database zlx;
if(sqlca.sqlcode)
{
printf("connect the database error[%d]\n",sqlca.sqlcode);
exit(1);
}
test_insert();
test_select();
test_update();
test_select();
exec sql close database;
return 0;
}
阅读(708) | 评论(0) | 转发(0) |