4

I have a property of class named m_database.

class SqlThread : public QThread
{
public:
SqlThread();
void run();

private:
QSqlDatabase   m_database;
QString        m_dbfilename;
};

and i instantiate in constructor like the example below:

SqlThread::SqlThread()
{
 m_database = QSqlDatabase::addDatabase("QSQLITE");
}

And i create database in run function, like that (The m_dbFileName i created with other class):

    m_database.setDatabaseName(m_dbfilename);

    if (!m_database.open())
    {
        qWarning("%s", m_database.lastError().text().toLocal8Bit().data());
        return;
    }

    QSqlQuery databaseQuery(m_database);
    databaseQuery.prepare("CREATE TABLE data (id int not null primary key, tu text, data BLOB, puits integer);");

    if (!databaseQuery.exec())
    {
        qWarning("%s", databaseQuery.lastError().text().toLocal8Bit().data());
        return;
    }

Why i receive error message: No query Unable to fetch row ??

1
  • I am really confuse, because sometimes the function works and other times no. Commented Jun 17, 2020 at 17:50

1 Answer 1

3

Replace the query string to:

databaseQuery.prepare("CREATE TABLE IF NOT EXISTS data (id int not null primary key, tu text, data BLOB, puits integer);");

Otherwise the execution fails if the table already exists.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.