I am creating a table using sqlite
database in Qt 5.9 and I am getting this error:
我在Qt 5.9中使用sqlite数据库创建一个表,我收到此错误:
No query Unable to fetch row
无查询无法获取行
QSqlQuery query("create table credit(username text primary key, password text);");
if(!query.exec())
{
ui->result->append("dataentry unsuccessful...\n"+query.lastError().text()+"\n");
}
else
{
ui->result->append("looks good...");
}
1 个解决方案
#1
0
Two things:
-
DDL statements are possible within QSqlQuery. But there is no need to add the semi-colon(;) at the end of
"create table credit(username text primary key, password text);"
在QSqlQuery中可以使用DDL语句。但是没有必要在“create table credit(用户名文本主键,密码文本)”的末尾添加分号(;);“
-
Secondly, when you create a QSqlQuery object with query string as parameter, it executes it immediately. There is no need to call
query.exec()
.其次,当您使用查询字符串作为参数创建QSqlQuery对象时,它会立即执行它。无需调用query.exec()。
You can substitute the exec()
with a isValid()
method to check validity of the query in the condition.
您可以使用isValid()方法替换exec()以检查条件中查询的有效性。
Hope this helps.
希望这可以帮助。
#1
0
Two things:
-
DDL statements are possible within QSqlQuery. But there is no need to add the semi-colon(;) at the end of
"create table credit(username text primary key, password text);"
在QSqlQuery中可以使用DDL语句。但是没有必要在“create table credit(用户名文本主键,密码文本)”的末尾添加分号(;);“
-
Secondly, when you create a QSqlQuery object with query string as parameter, it executes it immediately. There is no need to call
query.exec()
.其次,当您使用查询字符串作为参数创建QSqlQuery对象时,它会立即执行它。无需调用query.exec()。
You can substitute the exec()
with a isValid()
method to check validity of the query in the condition.
您可以使用isValid()方法替换exec()以检查条件中查询的有效性。
Hope this helps.
希望这可以帮助。