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 bindValue issue
Forum Updated to NodeBB v4.3 + New Features

QSql bindValue issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 2.1k Views 3 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.
  • kaansefK Offline
    kaansefK Offline
    kaansef
    wrote on last edited by
    #1

    Hi,

    My name is Kaan and I'm student. I writing a program and i was see an error. While i look generated SQL, i see blank SQL values. Please help me. (Sorry for my bad English.)

    My code is here:

    #include <QCoreApplication>
    #include <QDebug>
    #include <QSql>
    #include <QSqlQuery>
    #include <QSqlDatabase>
    #include <QSqlError>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
        database.setDatabaseName("C:/Veritabani.db");
        database.open();
        qDebug() << database.lastError();
        QSqlQuery query;
        query.prepare("INSERT INTO Users(username, e_mail, password) VALUES(:username, :e_mail, :password)");
        query.bindValue(":username", "Kaan");
        query.bindValue(":e_mail", "kaansef@gmail.com");
        query.bindValue(":password", "123456");
        query.exec();
        qDebug() << query.executedQuery();
        return a.exec();
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should check that your query executed successfully as well as the error message that it produced otherwise.

      One of the first thing that comes to mind is: Do you have that table in your database ?

      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
      • kaansefK Offline
        kaansefK Offline
        kaansef
        wrote on last edited by
        #3

        Thank you very much but i'm sure my database table is true. How to see my query's prepared state?

        the_T 1 Reply Last reply
        0
        • kaansefK kaansef

          Thank you very much but i'm sure my database table is true. How to see my query's prepared state?

          the_T Offline
          the_T Offline
          the_
          wrote on last edited by
          #4

          @kaansef
          Whats the exact error you get here?
          Maybe you could add some more debug outputs there.
          What does query.lastError() return?

          -- No support in PM --

          1 Reply Last reply
          0
          • kaansefK Offline
            kaansefK Offline
            kaansef
            wrote on last edited by
            #5

            Thanks for replies. query.lastError() returns "Parameter count mismatch".

            the_T 1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              when query exec runs it prints some error informations to cerr, could you check your console for the answer?

              Also, are username, e_mail, password the only columns in that table?

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • kaansefK kaansef

                Thanks for replies. query.lastError() returns "Parameter count mismatch".

                the_T Offline
                the_T Offline
                the_
                wrote on last edited by
                #7

                @kaansef
                To add to @VRonin: can you maybe show the output of .schema TABLENAME (for SQLite) (or describe TABLENAME if its MySQL) ? This may help to solve your problem

                -- No support in PM --

                1 Reply Last reply
                0
                • kaansefK Offline
                  kaansefK Offline
                  kaansef
                  wrote on last edited by
                  #8

                  I'm beginner Qt. So i understand you completely. My another project is QtWidgetApplication. My active project is QtWidgetApplication. Consoleapplication for you are understand more. How to cerr to cout redirect? Please help me.

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    Depends on your debugger, in Visual studio and qt creator it's the debug output window (normally at the bottom of the editor)

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

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

                      How did you check that you are currently have that table in your database ? How did you add it to your database ?

                      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

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved