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. I have some problems when using a select statement in the bindValue function

I have some problems when using a select statement in the bindValue function

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 569 Views
  • 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.
  • L Offline
    L Offline
    lso70
    wrote on last edited by VRonin
    #1

    my code is

    query.prepare(QString("select * from database where name = ?"));
    query.bindValue(0,QVariant(jim));
    query.exec();
    

    the problem is when the database contain a field which datatype is json
    the query.next or query.seek(0) return false,i can't get data from query.value(index)
    if the database doesn't have a json fied
    the query.next or seek(0) return true ,and i can get the data
    do anyone have some ideas? thank you very much!

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

      Hi
      What database are you using?
      As far as i know, true JsonFields are not supported directly.

      also why did you make a new topic ?
      https://forum.qt.io/topic/102041/i-have-some-problems-when-using-a-select-statement-in-the-bindvalue-function

      1 Reply Last reply
      2
      • L Offline
        L Offline
        lso70
        wrote on last edited by
        #3

        my database is mysql,sorry i'm new here so i make some mistake when posts the first topic

        mrjjM JonBJ 2 Replies Last reply
        0
        • L lso70

          my database is mysql,sorry i'm new here so i make some mistake when posts the first topic

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @lso70
          well, shit happens.
          Just know you can actually edit a post with the menu right to it. ( the 3 ... )

          As far as I know, Qt cannot handle the json type directly. Unless driver just returns it as a string.

          1 Reply Last reply
          1
          • L lso70

            my database is mysql,sorry i'm new here so i make some mistake when posts the first topic

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @lso70
            The question was answered (as best it can be) in https://forum.qt.io/topic/101027/is-qsqlquery-not-support-json-type-in-mysql
            This boils down to the behaviour of the QMYSQL driver.
            You must not use SELECT *; if you spell out the columns (assuming you even need the JSON one, else omit it) you can use CAST(json_column AS TEXT); or, as I said there, you might create a VIEW which does that for convenience.

            L 1 Reply Last reply
            6
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              And to add @JonB 's answer: 'SELECT *' is never a good idea since the order of the columns is undefined.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              4
              • JonBJ JonB

                @lso70
                The question was answered (as best it can be) in https://forum.qt.io/topic/101027/is-qsqlquery-not-support-json-type-in-mysql
                This boils down to the behaviour of the QMYSQL driver.
                You must not use SELECT *; if you spell out the columns (assuming you even need the JSON one, else omit it) you can use CAST(json_column AS TEXT); or, as I said there, you might create a VIEW which does that for convenience.

                L Offline
                L Offline
                lso70
                wrote on last edited by
                #7

                thank you,your advise works well!

                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