gpt4 book ai didi

c - 执行带有参数的 SQLite 语句

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:57 24 4
gpt4 key购买 nike

我在 C 中有这个方法,我从表中删除一行。我想传递一个作为主键的参数,然后删除该行。

这是我的方法:

void eliminarAlumno(char *mat) {
abrirBD();
error = sqlite3_exec(conexion, "delete from alumnos WHERE matricula='<mat>'", 0, 0, &msjError);
comprobarError(error, msjError);
cerrarBD();
}

在哪里<mat>是参数。我该怎么做?

最佳答案

您不能直接这样做。您需要先获取一个数组,填充所需的字符串并使用 sprintf()/snprintf() 将其打印 到数组中并将该数组用作 sqlite3_exec() 的参数。

有点像

char argument[128] = {0};   //make sure the final array fits in here
sprintf(argument, "delete from alumnos WHERE matricula='%s'", mat);
error = sqlite3_exec(conexion, argument, 0, 0, &msjError);

应该完成这项工作。

关于c - 执行带有参数的 SQLite 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35753019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com