// 定义删除员工信息函数
int do_delete(sqlite3 *ppDb)
{
int del_numb = 0;
printf("请输入要删除的员工工号:");
scanf("%d", &del_numb);
getchar(); // 吸收回车
// 准备SQL语句
char sql[128] = "";
snprintf(sql, sizeof(sql), "delete from Worker where numb = %d;", del_numb);
// 执行SQL语句
char *errmsg = NULL;
if (sqlite3_exec(ppDb, sql, NULL, NULL, &errmsg) != SQLITE_OK)
{
printf(":error msg:%s\n", errmsg);
sqlite3_free(errmsg);
errmsg = NULL;
return -1;
}
printf("删除成功\n");
return 0;
}
// 定义修改员工信息函数
int do_update(sqlite3 *ppDb)
{
int upd_numb = 0;
char upd_name[20] = "";
double upd_salary = 0.0;
printf("请输入要修改的员工工号:");
scanf("%d", &upd_numb);
getchar(); // 吸收回车
printf("请输入新的姓名:");
scanf("%s", upd_name);
getchar(); // 吸收回车
printf("请输入新的工资:");
scanf("%lf", &upd_salary);
getchar(); // 吸收回车
// 准备SQL语句
char sql[128] = "";
snprintf(sql, sizeof(sql), "update Worker set name = \"%s\", salary = %.2lf where numb = %d;",
upd_name, upd_salary, upd_numb);
// 执行SQL语句
char *errmsg = NULL;
if (sqlite3_exec(ppDb, sql, NULL, NULL, &errmsg) != SQLITE_OK)
{
printf("%d %s:error msg:%s\n", __LINE__, __func__, errmsg);
sqlite3_free(errmsg);
errmsg = NULL;
return -1;
}
printf("修改成功\n");
return 0;
}