Results 1 to 4 of 4

Thread: MySQL Floatingpoint zero value

  1. #1
    Join Date
    Sep 2014
    Posts
    5

    Default MySQL Floatingpoint zero value

    Hi everyone,

    everytime I try to get a Floatingpoint value from my MySQL Database QSqlQuery.value(X) returns a invalid value.
    toFloat() returns just zero.

    If the value stored in the MySQL isnt with floatingpoint, QSqlQuery.value() returns valid data.

    Why I get only invalid values if I try to get Data from the MySQL database? Everything is working, QString, Integers, Binary, but float, double, real isnt working!

    Please help.

    Regards Marcel

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: MySQL Floatingpoint zero value

    What type do you get when you look at the value returned b QSqlQuery::value()?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2014
    Posts
    5

    Default Re: MySQL Floatingpoint zero value

    Hi,

    It returns "Invalid".

    But only if I get a floatingpoint value. If the value stored in mysql is a decimal value i.e. 24 there is no error. If i change the value to 24.12 then it retunrs "invalid".

    The type of the mysql field is double. I also tested it with float.

  4. #4
    Join Date
    Sep 2014
    Posts
    5

    Default Re: MySQL Floatingpoint zero value

    Here is an example:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setPort(3306);
    4. db.setUserName("dtf");
    5. db.setPassword("dtf");
    6. db.setDatabaseName("dtf");
    7.  
    8. if(!db.open()) {
    9. qDebug() << db.lastError();
    10. return;
    11. }
    12.  
    13. QSqlQuery sql;
    14. sql.prepare("SELECT result FROM test WHERE id = 1;");
    15.  
    16. if(!sql.exec()) {
    17. qDebug() << db.lastError();
    18. return;
    19. }
    20.  
    21. sql.next();
    22. qDebug() << "Result: " << sql.value(0).toDouble();
    To copy to clipboard, switch view to plain text mode 

    The output of this example is:
    Result: 0
    The MySQL column "result" is of type DOUBLE(10,2). If i change the type to DOUBLE() only, the result is the same.
    The data selected by the statement is "14.99".

    Its an absolute simple example. Why this wont work?


    Added after 23 minutes:


    Ive tested it without prepared-statements! And now it works! Is it a BUG in QT5?

    Thats working:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setPort(3306);
    4. db.setUserName("dtf");
    5. db.setPassword("dtf");
    6. db.setDatabaseName("dtf");
    7.  
    8. if(!db.open()) {
    9. qDebug() << db.lastError();
    10. return;
    11. }
    12.  
    13. QSqlQuery sql;
    14.  
    15. if(!sql.exec("SELECT result FROM test WHERE id = 1;")) {
    16. qDebug() << db.lastError();
    17. return;
    18. }
    19.  
    20. sql.next();
    21. qDebug() << "Result: " << sql.value(0).toDouble();
    To copy to clipboard, switch view to plain text mode 
    Last edited by sp3x; 6th June 2016 at 17:21.

Similar Threads

  1. Replies: 4
    Last Post: 8th March 2016, 15:27
  2. Replies: 2
    Last Post: 9th December 2015, 02:07
  3. I need MySQL driver for Qt 4.6, WindowsXP(32), MySQL 5.1
    By User_3 in forum Installation and Deployment
    Replies: 7
    Last Post: 15th October 2010, 16:19
  4. MySQL on Qt4
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2008, 17:12
  5. MYSQL 5 Table qt model as small Mysql admin
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 10:43

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.