本文整理汇总了C++中DatabaseResult::at方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseResult::at方法的具体用法?C++ DatabaseResult::at怎么用?C++ DatabaseResult::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseResult
的用法示例。
在下文中一共展示了DatabaseResult::at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDatabaseResults
bool DatabaseUtils::GetDatabaseResults(const MediaType &mediaType, const FieldList &fields, const std::unique_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results)
{
if (dataset->num_rows() == 0)
return true;
const dbiplus::result_set &resultSet = dataset->get_result_set();
unsigned int offset = results.size();
if (fields.empty())
{
DatabaseResult result;
for (unsigned int index = 0; index < resultSet.records.size(); index++)
{
result[FieldRow] = index + offset;
results.push_back(result);
}
return true;
}
if (resultSet.record_header.size() < fields.size())
return false;
std::vector<int> fieldIndexLookup;
fieldIndexLookup.reserve(fields.size());
for (FieldList::const_iterator it = fields.begin(); it != fields.end(); ++it)
fieldIndexLookup.push_back(GetFieldIndex(*it, mediaType));
results.reserve(resultSet.records.size() + offset);
for (unsigned int index = 0; index < resultSet.records.size(); index++)
{
DatabaseResult result;
result[FieldRow] = index + offset;
unsigned int lookupIndex = 0;
for (FieldList::const_iterator it = fields.begin(); it != fields.end(); ++it)
{
int fieldIndex = fieldIndexLookup[lookupIndex++];
if (fieldIndex < 0)
return false;
std::pair<Field, CVariant> value;
value.first = *it;
if (!GetFieldValue(resultSet.records[index]->at(fieldIndex), value.second))
CLog::Log(LOGWARNING, "GetDatabaseResults: unable to retrieve value of field %s", resultSet.record_header[fieldIndex].name.c_str());
if (value.first == FieldYear &&
(mediaType == MediaTypeTvShow || mediaType == MediaTypeEpisode))
{
CDateTime dateTime;
dateTime.SetFromDBDate(value.second.asString());
if (dateTime.IsValid())
{
value.second.clear();
value.second = dateTime.GetYear();
}
}
result.insert(value);
}
result[FieldMediaType] = mediaType;
if (mediaType == MediaTypeMovie || mediaType == MediaTypeVideoCollection ||
mediaType == MediaTypeTvShow || mediaType == MediaTypeMusicVideo)
result[FieldLabel] = result.at(FieldTitle).asString();
else if (mediaType == MediaTypeEpisode)
{
std::ostringstream label;
label << (int)(result.at(FieldSeason).asInteger() * 100 + result.at(FieldEpisodeNumber).asInteger());
label << ". ";
label << result.at(FieldTitle).asString();
result[FieldLabel] = label.str();
}
else if (mediaType == MediaTypeAlbum)
result[FieldLabel] = result.at(FieldAlbum).asString();
else if (mediaType == MediaTypeSong)
{
std::ostringstream label;
label << (int)result.at(FieldTrackNumber).asInteger();
label << ". ";
label << result.at(FieldTitle).asString();
result[FieldLabel] = label.str();
}
else if (mediaType == MediaTypeArtist)
result[FieldLabel] = result.at(FieldArtist).asString();
results.push_back(result);
}
return true;
}