equal
deleted
inserted
replaced
10 QSqlDatabase db; |
10 QSqlDatabase db; |
11 |
11 |
12 // Find QSLite driver |
12 // Find QSLite driver |
13 db = QSqlDatabase::addDatabase("QSQLITE"); |
13 db = QSqlDatabase::addDatabase("QSQLITE"); |
14 |
14 |
|
15 #ifdef Q_OS_SYMBIAN |
15 QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation) |
16 QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation) |
16 + '/' // Qt Universal file separator |
17 + '/' // Qt Universal file separator |
17 + "seafood.db"; |
18 + "seafood.db"; |
|
19 #else |
|
20 // Windows assumed. |
|
21 // 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"; |
|
23 #endif |
18 QFile f(dbFile); |
24 QFile f(dbFile); |
19 std::string errString(dbFile.toStdString()); |
25 std::string errString(dbFile.toStdString()); |
20 if (!f.exists()) { |
26 if (!f.exists()) { |
21 qWarning("db not found "); |
27 qWarning("db not found "); |
22 } else { |
28 } else { |
50 } else { |
56 } else { |
51 this->populate(EPresentBest); |
57 this->populate(EPresentBest); |
52 this->populate(EPresentOK); |
58 this->populate(EPresentOK); |
53 this->populate(EPresentWorst); |
59 this->populate(EPresentWorst); |
54 } |
60 } |
|
61 } |
|
62 |
|
63 /* given the name of a fish, return a list of eco details in html format. |
|
64 */ |
|
65 QString Fishes::getEcoDetails(QString name) |
|
66 { |
|
67 QString detailsInHtml; |
|
68 QSqlQuery query; |
|
69 |
|
70 query.prepare("select details from ecoDetails " |
|
71 "where fid in (select fid from fish where name = :name )"); |
|
72 query.bindValue(":name",name); |
|
73 |
|
74 if (!query.exec()) |
|
75 { |
|
76 QString errCode = "failed to get eco details " + query.lastError().text(); |
|
77 qWarning(errCode.toStdString().c_str()); |
|
78 } |
|
79 |
|
80 detailsInHtml.append("<html> <title>name</title> <body> <h2>Eco Details</h2> <ul> "); |
|
81 while (query.next()){ |
|
82 detailsInHtml.append( " <li>"); |
|
83 detailsInHtml.append( query.value(0).toString()); |
|
84 detailsInHtml.append( "</li> " ); |
|
85 } |
|
86 detailsInHtml.append("</ul> </body> </html> "); |
|
87 return detailsInHtml; |
55 } |
88 } |
56 |
89 |
57 void Fishes::populate(TCATEGORIES cat) |
90 void Fishes::populate(TCATEGORIES cat) |
58 { |
91 { |
59 QSqlQuery query; |
92 QSqlQuery query; |