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
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVariant>
int main(int argc, char *argv[])
{
db.setDatabaseName( "mydatabase" ) ;
db.setHostName( "localhost" ) ;
db.setUserName( "myuser");
db.setPassword( "mypassword" ) ;
if ( !db.open() ) {
qDebug() << "Failed opening database dbToConnectTo\nReason:" ;
qDebug() << db.lastError().driverText();
qDebug ()<< db.lastError().databaseText() ;
exit ( 1 ) ;
} else {
qry.prepare("select coste, pvp from foo where id=621");
if ( qry.exec() ) {
qry.first();
qDebug() << qry.value(0).toDouble();
qDebug() << qry.value(1).toDouble();
}
}
}
}
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVariant>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
if ( QSqlDatabase::isDriverAvailable("QPSQL") ) {
QSqlDatabase db = QSqlDatabase::addDatabase( "QPSQL" ) ;
db.setDatabaseName( "mydatabase" ) ;
db.setHostName( "localhost" ) ;
db.setUserName( "myuser");
db.setPassword( "mypassword" ) ;
if ( !db.open() ) {
qDebug() << "Failed opening database dbToConnectTo\nReason:" ;
qDebug() << db.lastError().driverText();
qDebug ()<< db.lastError().databaseText() ;
exit ( 1 ) ;
} else {
QSqlQuery qry(db);
qry.prepare("select coste, pvp from foo where id=621");
if ( qry.exec() ) {
qry.first();
qDebug() << qry.value(0).toDouble();
qDebug() << qry.value(1).toDouble();
}
}
}
}
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!!!
Bookmarks