Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

JSON object into SQLite database



  • Hi Folks,

    I have an SQLite database, where the last column has TEXT type. I would like to insert into that an JSON object which will not appear in the database after the execution of the query. To do that, I'm using this SQL statement:
    @
    insert or replace into issue (title, description, state, severity, attachment) values(?, ?, ?, ?, ?)
    @
    which is filled up by the following way:
    @
    QSqlQuery query(_database);
    query.prepare(_session->value("card/sql/query/write/save").toString());
    query.addBindValue(card.title);
    query.addBindValue(card.description);
    query.addBindValue(card.state);
    query.addBindValue(card.severity);
    query.addBindValue(card.attachment);
    query.exec();
    @

    In my case the important is the last value adding: the card.attachment which is an QJsonObject instance.
    After the executuion of the query, I tried to print out the errors too, everythings seem to be OK, but the cell in the databse is empty.

    Can anybody help me?

    Regards,
    Norbert



  • Try this:

    @query.prepare("insert into Bands (Description) values (:Description);");
    query.bindValue(":Description", _session->value("card/sql/query/write/save").toString());
    if (!query.exec()) {@



  • Hi,

    it didn't help me. Can anybody suggest other solution?

    Regards,
    Norbert



  • Maybe I haven't understood.
    Haven't you got "card/sql/query/write/save" in the Description column?
    Which kind of type Description field is?



  • Hi,

    yes, maybe you misunderstood:

    • Description column is a text type column in the database, but it doesn't have any matter.
    • The important statement is the last two lines in my first post:
      ** I bind a JSon object into the prepared statement
      ** I execute the prepared statement query

    The problem is that the result doesn't appear in the database.

    Regards,
    Norbert


Log in to reply