Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to insert a Jsonarray that select from a table filed(Jsonarray type) to other table field (also jsonarray type)
Qt 6.11 is out! See what's new in the release blog

how to insert a Jsonarray that select from a table filed(Jsonarray type) to other table field (also jsonarray type)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 243 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cawlfj
    wrote on last edited by cawlfj
    #1

    I use queryCdby.prepare("select * from TankCapacityOld WHERE ZCertNo=:FCertNo"); to get a JSonarray filed from table TankCapcityOld.

    and i want insert to other table by :
    queryCdbN.prepare("replace INTO TankCapacity2(ZCertNo,ZCertNoOffical,TankNames) VALUES (:ZCertNo,:ZCertNoOffical,CONVERT(:TankNames USING UTF8MB4));
    queryCdbN.bindValue(":TankNames",QJsonDocument(queryCdby.value("TankNames").toJsonArray()));

    But the TankNames filed is null in table TankCapacity2.

    i use: qDebug()<<queryCdby.value("TankNames").toJsonArray()<<QJsonDocument(queryCdby.value("TankNames").toJsonArray())<<queryCdby.value("TankNames");

    got :
    QJsonArray() QJsonDocument([]) QVariant(QByteArray, "[\n "P1",\n "S1",\n "P2",\n "S2",\n "P3",\n "S3",\n "P4",\n "S4",\n "PS",\n "SS"\n]\n")

    how to insert the Jsonarray filed from a table to other table ?
    (queryCdby and queryCdbN are for different database )

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should start by ensuring that you are getting the data you want from the first query.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should start by ensuring that you are getting the data you want from the first query.

        C Offline
        C Offline
        cawlfj
        wrote on last edited by
        #3

        @SGaist
        yes the first query has got data.
        i use qDebug()<<queryCdby.value("TankNames");
        output as follow:
        QVariant(QByteArray, "[\n "P1",\n "S1",\n "P2",\n "S2",\n "P3",\n "S3",\n "P4",\n "S4",\n "PS",\n "SS"\n]\n")

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          From the looks of it, you should turn back array to a QByteArray before writing it to your other database.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved