/*====================================================
* Copyright (C) 2018 All rights reserved.
*
* 文件名称:sqltie3_get_tables.c
* 创 建 者:cyz [email protected]
* 创建日期:2018年01月15日
* 描 述:
2、使用sqlite3的接口函数完成一个用户登录验证功能模块设计
要封装成独立函数,在独立的main中调用测试;
===============================================================*/
#include <stdio.h>
#include <sqlite3.h>
int main(int argc, char *argv[])
{
sqlite3 * db = NULL;
int ret = sqlite3_open("./msg.db", &db);
if(ret < 0)
{
perror("sqlite3 open error \n");
return -1;
}
printf("sqlite 3 open ok \n");
char buf[128]={0};
char ** rest = NULL;
int row =0, col = 0;
char name[128]={0};
char pass[128]={0};
int i = 0;
while(1){
printf("please input name:");
scanf("%s",name);
printf("please input passwd:");
scanf("%s",pass);
sprintf(buf,"select * from user where name = '%s' and pass = '%s';",name,pass);
ret = sqlite3_get_table(db,buf,&rest,&row,&col,NULL);
if(ret < 0)
{
perror("sqlite3 get table error");
return -1;
}
if(row>=1)break;
i++;
if(i>=3){
printf("不好意思,你的id已经被查封!\n");
return -1;
}
printf("你还有%d次机会!\n",3-i);
}
printf("login successful!welcome\n");
sqlite3_close(db);
return 0;
}
* Copyright (C) 2018 All rights reserved.
*
* 文件名称:sqltie3_get_tables.c
* 创 建 者:cyz [email protected]
* 创建日期:2018年01月15日
* 描 述:
2、使用sqlite3的接口函数完成一个用户登录验证功能模块设计
要封装成独立函数,在独立的main中调用测试;
===============================================================*/
#include <stdio.h>
#include <sqlite3.h>
int main(int argc, char *argv[])
{
sqlite3 * db = NULL;
int ret = sqlite3_open("./msg.db", &db);
if(ret < 0)
{
perror("sqlite3 open error \n");
return -1;
}
printf("sqlite 3 open ok \n");
char buf[128]={0};
char ** rest = NULL;
int row =0, col = 0;
char name[128]={0};
char pass[128]={0};
int i = 0;
while(1){
printf("please input name:");
scanf("%s",name);
printf("please input passwd:");
scanf("%s",pass);
sprintf(buf,"select * from user where name = '%s' and pass = '%s';",name,pass);
ret = sqlite3_get_table(db,buf,&rest,&row,&col,NULL);
if(ret < 0)
{
perror("sqlite3 get table error");
return -1;
}
if(row>=1)break;
i++;
if(i>=3){
printf("不好意思,你的id已经被查封!\n");
return -1;
}
printf("你还有%d次机会!\n",3-i);
}
printf("login successful!welcome\n");
sqlite3_close(db);
return 0;
}