Seafood/Fishes.cpp
changeset 11 f3dbeee07821
parent 10 79eeacfd15ff
child 14 a16afe3df8c9
equal deleted inserted replaced
10:79eeacfd15ff 11:f3dbeee07821
     6 #include "Fishes.h"
     6 #include "Fishes.h"
     7 
     7 
     8 Fishes::Fishes(QObject *parent) : QObject(parent)
     8 Fishes::Fishes(QObject *parent) : QObject(parent)
     9 {
     9 {
    10     QSqlDatabase db;
    10     QSqlDatabase db;
       
    11     this->dbErrString = "noErr";
    11 
    12 
    12     // Find QSLite driver
    13     // Find QSLite driver
    13     db = QSqlDatabase::addDatabase("QSQLITE");
    14     db = QSqlDatabase::addDatabase("QSQLITE");
    14 
    15 
    15 #ifdef Q_OS_SYMBIAN
    16 #ifdef Q_OS_SYMBIAN
    16     QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
    17     QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
    17                      + '/'  // Qt Universal file separator
    18                      + '/'  // Qt Universal file separator
    18                      + "seafood.db";
    19                      + "seafood.db";
       
    20     dbFile.replace("/","\\");
    19 #else
    21 #else
    20     // Windows assumed.
    22     // Windows assumed.
    21     // unfortunately, "C:\Documents and Settings" is corrupted on my home PC. hard coding until I fix it. -jk
    23     // unfortunately, "C:\Documents and Settings" is corrupted on my home PC. hard coding until I fix it. -jk
    22     QString dbFile = "C:/workspace/QtExamples/Seafood/populateDB/seafood.db";
    24     QString dbFile = "C:/workspace/QtExamples/Seafood/populateDB/seafood.db";
    23 #endif
    25 #endif
    32     db.setDatabaseName(dbFile);
    34     db.setDatabaseName(dbFile);
    33 
    35 
    34     // Open databasee
    36     // Open databasee
    35     if(!db.open())
    37     if(!db.open())
    36     {
    38     {
    37         std::string errCode =  db.lastError().databaseText().toStdString();
    39         this->dbErrString =  db.lastError().databaseText();
    38 
    40 
    39         qWarning("DB: failed to open.");
    41         qWarning("DB: failed to open.");
    40 
    42 
    41         this->bestFish << "Abalone (farmed)" << "Anchovy, European" << "Barramundi U.S."
    43         this->bestFish << "Abalone (farmed)" << "Anchovy, European" << "Barramundi U.S."
    42             << "Capelin, smelt roe (Iceland)" << "Catfish (U.S.)" << "Clam, softshell"
    44             << "Capelin, smelt roe (Iceland)" << "Catfish (U.S.)" << "Clam, softshell"
    64  */
    66  */
    65 QString Fishes::getEcoDetails(QString name)
    67 QString Fishes::getEcoDetails(QString name)
    66 {
    68 {
    67     QString detailsInHtml;
    69     QString detailsInHtml;
    68     QSqlQuery query;
    70     QSqlQuery query;
       
    71     this->dbErrString = "noErr";
    69 
    72 
    70     query.prepare("select details from ecoDetails "
    73     query.prepare("select details from ecoDetails "
    71                   "where fid in (select fid from fish where name = :name )");
    74                   "where fid in (select fid from fish where name = :name )");
    72     query.bindValue(":name",name);
    75     query.bindValue(":name",name);
    73 
    76 
    74     if (!query.exec())
    77     if (!query.exec())
    75     {
    78     {
    76         QString errCode =  "failed to get eco details " + query.lastError().text();
    79         QString errCode =  "failed to get eco details " + query.lastError().text();
    77         qWarning(errCode.toStdString().c_str());
    80         qWarning(errCode.toStdString().c_str());
       
    81         this->dbErrString = name + " " + query.lastError().text();
    78     }
    82     }
    79 
    83 
    80     detailsInHtml.append("<html> <title>name</title> <body> <h2>Eco Details</h2> <ul> ");
    84     detailsInHtml.append("<html> <title>name</title> <body> <h2>Eco Details</h2> <ul> ");
    81     while (query.next()){
    85     while (query.next()){
    82         detailsInHtml.append( " <li>");
    86         detailsInHtml.append( " <li>");