7月16日作业
使用 sqlite3_exec 函数,执行如下几个语句
create table if no exists tb( name text primary key, pswd text not null );
insert into tb(name,pswd) values("123","abcdefg")
char code_pswd[20] = "" printf("请输入新的密码:");
scanf("%s",code_pswd) 执行语句 :
update tb set pswd = code_pswd where name = "123";
代码
#include <25041head.h>int main(int argc, const char *argv[])
{//打开数据库sqlite3* db = NULL;char *errmsg = NULL;sqlite3_open("./Database.db",&db);const char *sql="CREATE TABLE if not exists tb(name TEXT PRIMARY KEY,pswd TEXT NOT NULL);\INSERT INTO tb(name,pswd) values('123','abcdefg');";if(sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK){printf("%s\n",errmsg);sqlite3_close(db);return -1;}char code_pswd[20]="";printf("请输入新的密码:");scanf("%s",code_pswd);char sql_t[100]="";sprintf(sql_t,"UPDATE tb SET pswd = \"%s\" WHERE name = \"123\";",code_pswd);if(sqlite3_exec(db,sql_t,NULL,NULL,&errmsg)!=SQLITE_OK){printf("%s\n",errmsg);sqlite3_close(db);return -1;}//关闭数据库sqlite3_close(db);return 0;
}