今晚就实现两个功能,可运行,细节有待完善,好饿。
明天再完善。
void add_contact()
{
int ret;
char sql[MAX_SIZE];
char name[MAX_SIZE];
char tel[MAX_SIZE];
char addr[MAX_SIZE];
char flag;
printf("please put in the name:\n");
scanf("%s",name);
getchar();
printf("please put in the telephone:\n");
scanf("%s",tel);
getchar();
printf("please put in the address:\n");
scanf("%s",addr);
getchar();
sprintf(sql,"insert into contact (name,tel,addr) values ('%s','%s','%s');",name,tel,addr);
ret = sqlite3_exec(db,sql,0,0,&errmsg);
if(ret)
{
printf("add failed!\n");
}
else
{
printf("add success!\n");
}
printf("Do you want to continue? y or n.\n");
scanf("%c",&flag);
getchar();
while((flag != 'y') && (flag != 'n'))
{
printf("please put in again\n");
scanf("%c",&flag);
getchar();
}
if(flag == 'y')
{
add_contact();
}
else
{
return;
}
}
void view_contact()
{
int ret;
int i,j;
int row,column;
int flag;
printf("which order do you want? 1.id 2.name\n");
scanf("%d",&flag);
getchar();
if(flag == 1)
{
ret = sqlite3_get_table(db,"select * from contact order by id",&result,&row,&column,&errmsg);
}
else if(flag == 2)
{
ret = sqlite3_get_table(db,"select * from contact order by name",&result,&row,&column,&errmsg);
}
if(ret)
{
printf("view failed!\n");
}
else
{
for(i = 0; i <= row; i++)
{
for(j = 0; j < column; j++)
{
printf("%s|",result[i * column + j]);
}
printf("\n");
}
}
printf("press any key to exit:\n");
getchar();
getchar();
return;
}