176 QMap<
int, QString> attributeIds;
177 m_query->exec(
"SELECT DISTINCT Id, Name FROM FilterAttributeTable ORDER BY Id"_L1);
178 while (m_query->next())
179 attributeIds.insert(m_query->value(0).toInt(), m_query->value(1).toString());
183 QList<
int> usedAttributeIds;
184 for (
auto it = attributeIds.cbegin(), end = attributeIds.cend(); it != end; ++it) {
185 const int attributeId = it.key();
186 if (isAttributeUsed(m_query.get(),
"IndexFilterTable"_L1, attributeId)
187 || isAttributeUsed(m_query.get(),
"ContentsFilterTable"_L1, attributeId)
188 || isAttributeUsed(m_query.get(),
"FileFilterTable"_L1, attributeId)) {
189 usedAttributeIds.append(attributeId);
194 m_query->exec(
"SELECT * FROM pragma_table_info('IndexTable') WHERE name='ContextName'"_L1);
198 const QString identifierColumnName = legacy ?
"ContextName"_L1 :
"Identifier"_L1;
199 const int usedAttributeCount = usedAttributeIds.size();
201 QMap<
int, IndexItem> idToIndexItem;
202 m_query->exec(QString::fromLatin1(
"SELECT Name, %1, FileId, Anchor, Id "
204 "ORDER BY Id").arg(identifierColumnName));
205 while (m_query->next()) {
207 indexItem.name = m_query->value(0).toString();
208 indexItem.identifier = m_query->value(1).toString();
209 indexItem.fileId = m_query->value(2).toInt();
210 indexItem.anchor = m_query->value(3).toString();
211 const int indexId = m_query->value(4).toInt();
213 idToIndexItem.insert(indexId, indexItem);
216 QMap<
int, FileItem> idToFileItem;
217 QMap<
int,
int> originalFileIdToNewFileId;
222 "FileNameTable.FileId, "
223 "FileNameTable.Name, "
224 "FileNameTable.Title "
225 "FROM FileNameTable, FolderTable "
226 "WHERE FileNameTable.FolderId = FolderTable.Id "
227 "ORDER BY FileId"_L1);
228 while (m_query->next()) {
229 const int fileId = m_query->value(0).toInt();
231 fileItem.name = m_query->value(1).toString();
232 fileItem.title = m_query->value(2).toString();
234 idToFileItem.insert(fileId, fileItem);
235 originalFileIdToNewFileId.insert(fileId, filesCount);
239 QMap<
int, ContentsItem> idToContentsItem;
241 m_query->exec(
"SELECT Data, Id FROM ContentsTable ORDER BY Id"_L1);
242 while (m_query->next()) {
244 contentsItem.data = m_query->value(0).toByteArray();
245 const int contentsId = m_query->value(1).toInt();
247 idToContentsItem.insert(contentsId, contentsItem);
250 bool optimized =
true;
252 if (usedAttributeCount) {
261 const bool mayOptimizeIndexTable = filterDataCount(m_query.get(),
"IndexFilterTable"_L1)
262 == idToIndexItem.size() * usedAttributeCount;
263 const bool mayOptimizeFileTable = filterDataCount(m_query.get(),
"FileFilterTable"_L1)
264 == idToFileItem.size() * usedAttributeCount;
265 const bool mayOptimizeContentsTable =
266 filterDataCount(m_query.get(),
"ContentsFilterTable"_L1)
267 == idToContentsItem.size() * usedAttributeCount;
268 optimized = mayOptimizeIndexTable && mayOptimizeFileTable && mayOptimizeContentsTable;
273 "IndexFilterTable.IndexId, "
274 "FilterAttributeTable.Name "
277 "FilterAttributeTable "
279 "IndexFilterTable.FilterAttributeId = FilterAttributeTable.Id"_L1);
280 while (m_query->next()) {
281 const int indexId = m_query->value(0).toInt();
282 auto it = idToIndexItem.find(indexId);
283 if (it != idToIndexItem.end())
284 it.value().filterAttributes.append(m_query->value(1).toString());
289 "FileFilterTable.FileId, "
290 "FilterAttributeTable.Name "
293 "FilterAttributeTable "
295 "FileFilterTable.FilterAttributeId = FilterAttributeTable.Id"_L1);
296 while (m_query->next()) {
297 const int fileId = m_query->value(0).toInt();
298 auto it = idToFileItem.find(fileId);
299 if (it != idToFileItem.end())
300 it.value().filterAttributes.append(m_query->value(1).toString());
305 "ContentsFilterTable.ContentsId, "
306 "FilterAttributeTable.Name "
308 "ContentsFilterTable, "
309 "FilterAttributeTable "
311 "ContentsFilterTable.FilterAttributeId = FilterAttributeTable.Id"_L1);
312 while (m_query->next()) {
313 const int contentsId = m_query->value(0).toInt();
314 auto it = idToContentsItem.find(contentsId);
315 if (it != idToContentsItem.end())
316 it.value().filterAttributes.append(m_query->value(1).toString());
322 for (
auto it = idToIndexItem.cbegin(), end = idToIndexItem.cend(); it != end; ++it) {
323 IndexItem item = it.value();
324 item.fileId = originalFileIdToNewFileId.value(item.fileId);
325 table.indexItems.append(item);
328 table.fileItems = idToFileItem.values();
329 table.contentsItems = idToContentsItem.values();
332 for (
int attributeId : usedAttributeIds)
333 table.usedFilterAttributes.append(attributeIds.value(attributeId));
433QMultiMap<QString, QByteArray>
QHelpDBReader::filesData(
const QStringList &filterAttributes,
434 const QString &extensionFilter)
const
441 if (!extensionFilter.isEmpty())
442 extension =
"AND FileNameTable.Name LIKE \'%.%1\'"_L1.arg(extensionFilter);
444 if (filterAttributes.isEmpty()) {
447 "FileNameTable.Name, "
448 "FileDataTable.Data "
453 "WHERE FileDataTable.Id = FileNameTable.FileId "
454 "AND FileNameTable.FolderId = FolderTable.Id %1"_L1.arg(extension);
456 for (
int i = 0; i < filterAttributes.size(); ++i) {
458 query.append(
" INTERSECT "_L1);
461 "FileNameTable.Name, "
462 "FileDataTable.Data "
468 "FilterAttributeTable "
469 "WHERE FileDataTable.Id = FileNameTable.FileId "
470 "AND FileNameTable.FolderId = FolderTable.Id "
471 "AND FileNameTable.FileId = FileFilterTable.FileId "
472 "AND FileFilterTable.FilterAttributeId = FilterAttributeTable.Id "
473 "AND FilterAttributeTable.Name = \'%1\' %2"_L1
474 .arg(quote(filterAttributes.at(i)), extension));
477 m_query->exec(query);
478 QMultiMap<QString, QByteArray> result;
479 while (m_query->next())
480 result.insert(m_query->value(0).toString(), qUncompress(m_query->value(1).toByteArray()));