Qt不能在sqlite3中创建表

can not make a table in sqlite3 by Qt

本文关键字:创建 sqlite3 不能 Qt      更新时间:2023-10-16

我已经用这个命令在终端中创建了一个数据库:

sqlite3 test.db  

然后我试着用这些代码制作一个表:

ui->setupUi(this);
db1.setDatabaseName("test.db");
bool k=db1.open();
QSqlQuery q(db1);
q.prepare("CREATE TABLE by_code(id INT)");
q.exec();
qDebug()<<"isOpen: "<<k<<" Error:"<<q.lastError();

输出为:

isOpen: true  Error: QSqlError(-1, "Unable to fetch row", "No query") 
有什么问题,我该如何解决?

Qt试图获得查询的结果,但CREATE TABLE语句不返回结果。

不被认为是实际错误。查询是否成功,可查看exec函数的返回值