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. QSQL SQLite problem
Forum Updated to NodeBB v4.3 + New Features

QSQL SQLite problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.9k 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.
  • J Offline
    J Offline
    JessyNay
    wrote on last edited by
    #1

    I've a problem with SQLite, when consulting the DB for a User and Pass it just doesn't work), I can ask if the user exist, but not if the password it's correct.

    @
    QSqlQuery sql;
    QString strSql = "SELECT Usuario,Clave,Administrador FROM UsuariosSistema WHERE Usuario=:usuario AND Clave=:clave";
    sql.prepare(strSql);
    sql.bindValue(":usuario", usuario);
    sql.bindValue(":clave", claveHash.toHex());
    @

    this code works in MySQL but not in SQLite, and in SQLite if I do this:

    @QSqlQuery sql;
    QString strSql = "SELECT Usuario,Clave,Administrador FROM UsuariosSistema WHERE Usuario=:usuario;
    sql.prepare(strSql);
    sql.bindValue(":usuario", usuario);@

    it works, but I need to get the password too, am I missing something? the DB has the same content..

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zither
      wrote on last edited by
      #2

      Please check with that, you got something.

      @qDebug()<<sql.lastError().text();@

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JessyNay
        wrote on last edited by
        #3

        I don't have an error! It just doesn't take the

        @claveHash.toHex()@

        if I do qDebug() << claveHash.toHex() the result is:

        @d033e22ae348aeb5660fc2140aec35850c4da997@

        And that's what I have in the DB

        @qDebug()<<sql.lastError().text();@ returns nothing " "

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          zither
          wrote on last edited by
          #4

          I see, sorry SQLite can't accept Hex data types.
          "SQLite datatypes":http://www.sqlite.org/datatype3.html
          You should try to change them into QString to store.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JessyNay
            wrote on last edited by
            #5

            the method toHex() returns a a QByteArray, so I wasn't casting it to a QString, it works now! thank you so much!! :D

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JessyNay
              wrote on last edited by
              #6

              [quote author="ron9776" date="1318822074"]1
              qDebug()<<sql.lastError().text();[/quote]

              I don't get it, What were you trying to say? that's the first answer I got

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                QByteArray::toHex() returns another QByteArray. Did you try to convert that into a QString before binding it to the SQL placeholder?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  troubalex
                  wrote on last edited by
                  #8

                  [quote author="JessyNay" date="1318822832"][quote author="ron9776" date="1318822074"]1
                  qDebug()<<sql.lastError().text();[/quote]

                  I don't get it, What were you trying to say? that's the first answer I got

                  [/quote]

                  It was a spam account. I removed the post and deleted the user.

                  THE CAKE IS A LIE
                  Web Community Manager - Qt Development Frameworks

                  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