Results 1 to 2 of 2

Thread: Maybe a bug: Reading double precision columns from a PostgreSQL Table

  1. #1
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    4

    Default Maybe a bug: Reading double precision columns from a PostgreSQL Table

    Hi,

    Let a table on my PostgreSQL 7.4 database.

    CREATE TABLE foo
    (id serial,
    coste double precision,
    pvp double precision)

    Let insert a row
    INSERT INTO foo (coste, pvp) VALUES (0.12345, 1.98765).

    Let next code

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QSqlDatabase>
    3. #include <QSqlQuery>
    4. #include <QSqlError>
    5. #include <QDebug>
    6. #include <QVariant>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication app(argc, argv);
    11.  
    12. if ( QSqlDatabase::isDriverAvailable("QPSQL") ) {
    13. QSqlDatabase db = QSqlDatabase::addDatabase( "QPSQL" ) ;
    14. db.setDatabaseName( "mydatabase" ) ;
    15. db.setHostName( "localhost" ) ;
    16. db.setUserName( "myuser");
    17. db.setPassword( "mypassword" ) ;
    18. if ( !db.open() ) {
    19. qDebug() << "Failed opening database dbToConnectTo\nReason:" ;
    20. qDebug() << db.lastError().driverText();
    21. qDebug ()<< db.lastError().databaseText() ;
    22. exit ( 1 ) ;
    23. } else {
    24. QSqlQuery qry(db);
    25. qry.prepare("select coste, pvp from foo where id=621");
    26. if ( qry.exec() ) {
    27. qry.first();
    28. qDebug() << qry.value(0).toDouble();
    29. qDebug() << qry.value(1).toDouble();
    30. }
    31. }
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    On the output, I expect to see

    -----------------------------------------
    0.12345
    1.98765
    -----------------------------------------

    But, what I get is

    -----------------------------------------
    0
    1
    -----------------------------------------

    Is that a bug? Can you test it? Maybe it's an error of my code. If it's not, I'll report the bug to Trolltech.

    Thanks!!!
    Last edited by Sparhawk; 24th July 2008 at 18:21.

  2. #2
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    4

    Default Re: Maybe a bug: Reading double precision columns from a PostgreSQL Table

    I found a workaround... Using a cast on the postgresql query to varchar:

    select cast(coste as varchar), cast(pvp as varchar) from foo ...

    Now it works.

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.