Results 1 to 2 of 2

Thread: QSqlQuery with MySQL performs twicely (SOLVED)

  1. #1
    Join Date
    May 2011
    Posts
    30
    Thanks
    1

    Default QSqlQuery with MySQL performs twicely (SOLVED)

    Hi, I will be very glad to get a quick answer. I'm using QSqlQuery with QSqlDatabase with MySQL. I try to exec one query but client shows two entries in the table. Why?
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "MainWindow.h"
    3.  
    4. #include <QMetaType>
    5. #include <QTextCodec>
    6.  
    7. #include <QSqlDatabase>
    8. #include <QSqlQuery>
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    15. db.setHostName("localhost");
    16. db.setUserName("root");
    17. db.setPassword("password0");
    18. db.setDatabaseName("fitnesscenter");
    19. db.open();
    20.  
    21. QSqlQuery query("insert into users(fullname) values ('Someone')");
    22. query.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. mysql> delete from users;
    2. Query OK, 2 rows affected (0.04 sec)
    3.  
    4. mysql> select * from users;
    5. +----+----------+----------+
    6. | id | fullname | password |
    7. +----+----------+----------+
    8. | 39 | Someone | NULL |
    9. | 40 | Someone | NULL |
    10. +----+----------+----------+
    11. 2 rows in set (0.00 sec)
    12.  
    13. mysql>
    To copy to clipboard, switch view to plain text mode 


    EDIT:


    This post contains the right answer:
    http://www.qtcentre.org/threads/4550...742#post206742
    It is extremely unobvious!
    Last edited by zzz9; 19th August 2012 at 11:13.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQuery with MySQL performs twicely (SOLVED)

    Firstly, I think you meant to link to a different thread.

    Secondly, given that the behaviour of the constructor you used is documented QSqlQuery::QSqlQuery() I think it is obvious.

Similar Threads

  1. Replies: 1
    Last Post: 18th July 2011, 12:12
  2. MySQL QSqlQuery problem
    By Erni35 in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2010, 22:14
  3. Qt 4.5.1 / MySQL 5.1, QSqlQuery::lastError() 1295
    By wdezell in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2009, 15:36
  4. QSqlQuery, MySQL, "show engines;"
    By mbaszczewski in forum Qt Programming
    Replies: 0
    Last Post: 16th July 2009, 19:25
  5. MYSQL 5 Table qt model as small Mysql admin
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 09:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.