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. Problem with QByteArray and BLOB Entry in Database

Problem with QByteArray and BLOB Entry in Database

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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.

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

      Hi and welcome to devnet,

      Are you trying to show these values through qDebug() ?

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Yes i do. I wanted to know why the query is empty, so i showed the variable with qdebug.

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

          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 ?

          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
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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.

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

              Do you mean that if you encrypt the same string twice you get two different results ?

              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
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by A Former User
                #7

                Yes. But i finally solved my Problem. Its to complicated to explain, but thanks for your help.

                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