Wer_Bn
12th October 2016, 17:06
Hello
I'm trying to follow procedure as stated in
http://doc.qt.io/qt-4.8/qsqlquery.html
I take this as reference
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();
This query item, in my case, is a pointer declared as member of a class.
With this query pointer, I do in the class constructor, the following:
mydb.setDatabaseName("BlaBla.db");
mydb.open();
query = new QSqlQuery(mydb);
query->exec("create table MY_TABLE "
"(column integer)");
query->prepare("INSERT INTO MY_TABLE(column) VALUES(:holder)");
With mydb being initialized as QSqlDatabase::addDatabase("QSQLITE")
Ok, so far so good, the table is created.
Now, I want to use this query in a efficient way.
I want to prepare it, and use it several times to add an entry to the database. That's why, at the end of the constructor, I prepare it already.
So after I do this, I call a method that uses this query, from within the mainwindow thread. Please notice that the database is also created when the mainwindow thread is initialized.
So, the method, inside the SAME class, is
query->bindValue(":holder", receivedVal);
if (query->exec())
qDebug() << "Record Inserted";
else
qDebug() << "Record not inserted";
In this function I always get "Record not inserted"
Now, for the funny fact:
If, inside this method, I create a LOCAL query with the same command, the data will be successfully added. Problem is, I have to prepare it ALWAYS, and this is the reason it gets really slow, I believe. UI gets really slow and freezing.
I've searched a lot already, but all I can find is scope ideas, that I believe I'm not missing.
So, I appreciate your help
Thank you :)
I'm trying to follow procedure as stated in
http://doc.qt.io/qt-4.8/qsqlquery.html
I take this as reference
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();
This query item, in my case, is a pointer declared as member of a class.
With this query pointer, I do in the class constructor, the following:
mydb.setDatabaseName("BlaBla.db");
mydb.open();
query = new QSqlQuery(mydb);
query->exec("create table MY_TABLE "
"(column integer)");
query->prepare("INSERT INTO MY_TABLE(column) VALUES(:holder)");
With mydb being initialized as QSqlDatabase::addDatabase("QSQLITE")
Ok, so far so good, the table is created.
Now, I want to use this query in a efficient way.
I want to prepare it, and use it several times to add an entry to the database. That's why, at the end of the constructor, I prepare it already.
So after I do this, I call a method that uses this query, from within the mainwindow thread. Please notice that the database is also created when the mainwindow thread is initialized.
So, the method, inside the SAME class, is
query->bindValue(":holder", receivedVal);
if (query->exec())
qDebug() << "Record Inserted";
else
qDebug() << "Record not inserted";
In this function I always get "Record not inserted"
Now, for the funny fact:
If, inside this method, I create a LOCAL query with the same command, the data will be successfully added. Problem is, I have to prepare it ALWAYS, and this is the reason it gets really slow, I believe. UI gets really slow and freezing.
I've searched a lot already, but all I can find is scope ideas, that I believe I'm not missing.
So, I appreciate your help
Thank you :)