void ThreatQuery::query() { const ds::Resource::Id cms(ds::Resource::Id::CMS_TYPE, 0); std::stringstream buf; ds::query::Result r; ds::query::Result threatR; buf << "SELECT latest_threats.id, latest_threats.name FROM latest_threats ORDER BY id DESC LIMIT 10"; if (!ds::query::Client::query(cms.getDatabasePath(), buf.str(), r, ds::query::Client::INCLUDE_COLUMN_NAMES_F)) { DS_LOG_WARNING("TreatQuery error querying treats"); } if (r.rowsAreEmpty()) return; // Add the media ds::query::Result::RowIterator it(r); while (it.hasValue()) { LatestThreatModel m; m.mThreatId =it.getInt(0); m.mName = it.getWString(1); buf.str(""); buf << "SELECT country, startDate, infections FROM threat_data WHERE threatID = " << m.mThreatId; if(ds::query::Client::query(cms.getDatabasePath(), buf.str(), threatR, ds::query::Client::INCLUDE_COLUMN_NAMES_F) && !threatR.rowsAreEmpty()){ ds::query::Result::RowIterator threatIt(threatR); while(threatIt.hasValue()){ ThreatDataModel tdm; tdm.mCountry = threatIt.getWString(0); tdm.mDate = threatIt.getWString(1); tdm.mNumThreats = threatIt.getInt(2); m.mThreatData.push_back(tdm); ++threatIt; } } mLatestThreats.push_back(m); ++it; } }
void StoryQuery::query(AllData& output) { // Sample to hard-code data: ds::model::StoryRef newStory; newStory.setId(1); newStory.setTitle(L"Sample Story"); newStory.setBody(L"Sample body"); newStory.setPrimaryResource(ds::Resource(ds::Environment::expand("%APP%/data/images/temp/sample_image.png"))); output.mStories.push_back(newStory); // Sample to query from a db. // You'll need to set resource_location and resource_db in engine.xml for this to work (or supply your own db path) // resource_db is a relative path to resource_location /* */ const ds::Resource::Id cms(ds::Resource::Id::CMS_TYPE, 0); ds::query::Result result; ds::query::Result recResult; std::string dbPath = cms.getDatabasePath(); std::string resourcesPath = cms.getResourcePath(); std::map<int, ds::Resource> allResources; // 0 1 2 3 4 5 6 7 std::string recyQuery = "SELECT resourcesid, resourcestype,resourcesduration,resourceswidth,resourcesheight,resourcesfilename,resourcespath,resourcesthumbid FROM Resources"; if(ds::query::Client::query(dbPath, recyQuery, recResult)) { ds::query::Result::RowIterator rit(recResult); while(rit.hasValue()) { ds::Resource reccy; int mediaId = rit.getInt(0); reccy.setDbId(mediaId); reccy.setTypeFromString(rit.getString(1)); reccy.setDuration(rit.getFloat(2)); reccy.setWidth(rit.getFloat(3)); reccy.setHeight(rit.getFloat(4)); if(reccy.getType() == ds::Resource::WEB_TYPE){ reccy.setLocalFilePath(rit.getString(5)); } else { std::stringstream loclPath; loclPath << resourcesPath << rit.getString(6) << rit.getString(5); reccy.setLocalFilePath(loclPath.str()); } reccy.setThumbnailId(rit.getInt(7)); allResources[mediaId] = reccy; ++rit; } } }
void NewsQuery::query() { const ds::Resource::Id cms(ds::Resource::Id::CMS_TYPE, 0); std::stringstream buf; ds::query::Result r; buf << "SELECT id,year,month,day,text FROM news"; if (!ds::query::Client::query(cms.getDatabasePath(), buf.str(), r, ds::query::Client::INCLUDE_COLUMN_NAMES_F)) { DS_LOG_WARNING("NewsQuery::queryType() error querying news"); } if (r.rowsAreEmpty()) return; // Add the media ds::query::Result::RowIterator it(r); while (it.hasValue()) { TickerModel m; m.mId =it.getInt(0); m.mYear = it.getInt(1); m.mMonth = it.getInt(2); m.mDay = it.getInt(3); m.mHeadline = it.getWString(4); mOutput.push_back(m); ++it; } }