-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.0.1
-
None
When inserting a single record into a table, I see that the record was added twice. This is a BIG issue as I cannot at this point store data correctly into a SQLite3 database.
The following example produces this error:
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlError>
#include <QString>
#include <QVariant>
#include <iostream>
using namespace std;
void execSql(QString sql, QSqlDatabase db);
void showRecordCount(QSqlDatabase db);
int main(int argc, char *argv[]) {
QCoreApplication runtime(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "db1");
db.setDatabaseName(QString("%1/db1.db").arg(QCoreApplication::applicationDirPath()));
if (db.open())
{ cout << "Database open!" << endl; execSql("CREATE TABLE IF NOT EXISTS Table1 (Field1 TEXT)", db); showRecordCount(db); execSql("INSERT INTO Table1 (Field1) VALUES (\'value1\')", db); showRecordCount(db); db.close(); cout << "Database closed!" << endl; } else
cout << "Database not open! " << db.lastError().text().toStdString() << endl;
return 0;
}
void execSql(QString sql, QSqlDatabase db) {
QSqlQuery cmd(sql, db);
cmd.exec();
}
void showRecordCount(QSqlDatabase db) {
QSqlQuery qry("SELECT count(1) FROM Table1", db);
if (qry.exec())
{ if (qry.next()) cout << "Record Count: " << qry.record().value(0).toULongLong() << endl; }}