Solved I have some problems when using a select statement in the bindValue function
-
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! -
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 -
my database is mysql,sorry i'm new here so i make some mistake when posts the first topic
-
@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.
-
@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 theQMYSQL
driver.
You must not useSELECT *
; if you spell out the columns (assuming you even need the JSON one, else omit it) you can useCAST(json_column AS TEXT)
; or, as I said there, you might create aVIEW
which does that for convenience. -
And to add @JonB 's answer: 'SELECT *' is never a good idea since the order of the columns is undefined.
-
thank you,your advise works well!