Problem with QByteArray and BLOB Entry in Database
-
i have a Problem to find a Databaseentry with a QByteArray. i encrypt a QString and get a QByteArray that i can insert to my Database. The Databaseentry looks like this.
109,251,142,174,192,243,76,229,188,58,71,65,2,80,24,210,135,129,93,140,208,184,227,204,12,235,58,239,103,51,213,115
but if i search for an entry my variable shows like this.
";\xD0\xB1J\xF0""2J\x17\xBFl\xE0=6c\xCDN\x8E\xB7Z\xB6\xDD""C\x91\xDA\x8D^\xA5""e\xC4\xA2\xC3""C\xFB\xA2\xF5\x19\x9DOJ\x14\x89\x16\x87pA:\xB2\xDF"
so the Select query always returns nothing. Here my Code
QSqlQuery query; qDebug() << title; query.prepare("SELECT situation_field, emotion_field, mind_field, strength FROM event " "WHERE title = CAST((:title) AS BLOB) AND date = (:date)"); query.bindValue(":title", title)); query.bindValue(":date", date.toString()); if (query.exec()) { if (query.first()) { *situation = query.value(0).toByteArray(); *emotion = query.value(1).toByteArray(); *mind = query.value(2).toByteArray(); *strength = query.value(3).toInt(); } }
Anyone has an idea what i can do? Nothing works.
-
Hi and welcome to devnet,
Are you trying to show these values through qDebug() ?
-
Yes i do. I wanted to know why the query is empty, so i showed the variable with qdebug.
-
To check what query was run your can call executedQuery.
What you see in the console is explained in this email thread
Out of curiosity why are situation, emotion, mind and strength pointers ?
-
i found out that my Values i want to search for are always different. The Values i insert into the Database are encrypted and everytime i encrypt a String, the QByteArray looks different at the end.
This Variables are Pointers because the Code is placed in a Method of a Class and it would be to difficult to return them all.
-
Do you mean that if you encrypt the same string twice you get two different results ?
-
Yes. But i finally solved my Problem. Its to complicated to explain, but thanks for your help.