Skip to content

Commit

Permalink
Merge branch 'hotfix/SDK-3536_Spreadsheets-PDFs-and-presentations-not…
Browse files Browse the repository at this point in the history
…-included-with-documents-filter' into 'release/v5.2.1'

SDK-3536. Spreadsheets, PDFs and presentations are not included with the documents filter

See merge request sdk/sdk!5197
  • Loading branch information
catalinr-m committed Jan 16, 2024
2 parents 44b4846 + 04240cd commit 702020e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/mega/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ typedef enum { MIME_TYPE_UNKNOWN = 0,
MIME_TYPE_PROGRAM = 8, // programExtensions
MIME_TYPE_MISC = 9, // miscExtensions
MIME_TYPE_SPREADSHEET = 10, // spreadsheetExtensions
MIME_TYPE_ALL_DOCS = 11, // any of {document, pdf, presentation, spreadsheet}
} MimeType_t;

typedef enum { LBL_UNKNOWN = 0, LBL_RED = 1, LBL_ORANGE = 2, LBL_YELLOW = 3, LBL_GREEN = 4,
Expand Down
4 changes: 3 additions & 1 deletion include/megaapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9222,6 +9222,7 @@ class MegaSearchFilter
* - MegaApi::FILE_TYPE_PROGRAM = 8
* - MegaApi::FILE_TYPE_MISC = 9
* - MegaApi::FILE_TYPE_SPREADSHEET = 10
* - MegaApi::FILE_TYPE_ALL_DOCS = 11 --> any of {DOCUMENT, PDF, PRESENTATION, SPREADSHEET}
*/
virtual void byCategory(int mimeType);

Expand Down Expand Up @@ -16391,7 +16392,8 @@ class MegaApi
FILE_TYPE_PROGRAM,
FILE_TYPE_MISC,
FILE_TYPE_SPREADSHEET,
FILE_TYPE_LAST = FILE_TYPE_SPREADSHEET,
FILE_TYPE_ALL_DOCS, // any of {DOCUMENT, PDF, PRESENTATION, SPREADSHEET}
FILE_TYPE_LAST = FILE_TYPE_ALL_DOCS,
};

enum { SEARCH_TARGET_INSHARE = 0,
Expand Down
26 changes: 20 additions & 6 deletions src/db/sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,13 @@ bool SqliteAccountState::getChildren(const mega::NodeSearchFilter& filter, vecto
"AND (? = " + std::to_string(TYPE_UNKNOWN) + " OR n1.type = ?) "
"AND (? = 0 OR ? < n1.ctime) AND (? = 0 OR n1.ctime < ?) "
"AND (? = 0 OR ? < n1.mtime) AND (? = 0 OR (0 < n1.mtime AND n1.mtime < ?)) " // mtime is not used (0) for some nodes
"AND (? = " + std::to_string(MIME_TYPE_UNKNOWN) + " OR (n1.type = " + std::to_string(FILENODE) + " AND n1.mimetype = ?)) "
"AND (? = " + std::to_string(MIME_TYPE_UNKNOWN) +
" OR (n1.type = " + std::to_string(FILENODE) +
" AND ((? = " + std::to_string(MIME_TYPE_ALL_DOCS) + " AND n1.mimetype IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
',' + std::to_string(MIME_TYPE_PDF) +
',' + std::to_string(MIME_TYPE_PRESENTATION) +
',' + std::to_string(MIME_TYPE_SPREADSHEET) + "))"
" OR n1.mimetype = ?))) "
"AND (n1.name REGEXP ?) ";
// Leading and trailing '*' will be added to argument '?' so we are looking for a substring of name
// Our REGEXP implementation is case insensitive
Expand All @@ -1379,10 +1385,11 @@ bool SqliteAccountState::getChildren(const mega::NodeSearchFilter& filter, vecto
(sqlResult = sqlite3_bind_int64(mStmtGetChildren, 11, filter.byModificationTimeUpperLimit())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int64(mStmtGetChildren, 12, filter.byModificationTimeUpperLimit())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtGetChildren, 13, filter.byCategory())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtGetChildren, 14, filter.byCategory())) == SQLITE_OK)
(sqlResult = sqlite3_bind_int(mStmtGetChildren, 14, filter.byCategory())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtGetChildren, 15, filter.byCategory())) == SQLITE_OK)
{
string wildCardName = '*' + filter.byName() + '*';
if ((sqlResult = sqlite3_bind_text(mStmtGetChildren, 15, wildCardName.c_str(), static_cast<int>(wildCardName.length()), SQLITE_STATIC)) == SQLITE_OK)
if ((sqlResult = sqlite3_bind_text(mStmtGetChildren, 16, wildCardName.c_str(), static_cast<int>(wildCardName.length()), SQLITE_STATIC)) == SQLITE_OK)
{
result = processSqlQueryNodes(mStmtGetChildren, children);
}
Expand Down Expand Up @@ -1421,7 +1428,13 @@ bool SqliteAccountState::searchNodes(const NodeSearchFilter& filter, vector<pair
"AND (? = 0 OR ? < n1.ctime) AND (? = 0 OR n1.ctime < ?) "
"AND (? = 0 OR ? < n1.mtime) AND (? = 0 OR (0 < n1.mtime AND n1.mtime < ?)) " // mtime is not used (0) for some nodes
"AND (? = " + std::to_string(NO_SHARES) + " OR n1.share = ?) "
"AND (? = " + std::to_string(MIME_TYPE_UNKNOWN) + " OR (n1.type = " + std::to_string(FILENODE) + " AND n1.mimetype = ?)) "
"AND (? = " + std::to_string(MIME_TYPE_UNKNOWN) +
" OR (n1.type = " + std::to_string(FILENODE) +
" AND ((? = " + std::to_string(MIME_TYPE_ALL_DOCS) + " AND n1.mimetype IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
',' + std::to_string(MIME_TYPE_PDF) +
',' + std::to_string(MIME_TYPE_PRESENTATION) +
',' + std::to_string(MIME_TYPE_SPREADSHEET) + "))"
" OR n1.mimetype = ?))) "
"AND (n1.name REGEXP ?) ";
// Leading and trailing '*' will be added to argument '?' so we are looking for a substring of name
// Our REGEXP implementation is case insensitive
Expand All @@ -1448,10 +1461,11 @@ bool SqliteAccountState::searchNodes(const NodeSearchFilter& filter, vector<pair
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 12, filter.byShareType())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 13, filter.byShareType())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 14, filter.byCategory())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 15, filter.byCategory())) == SQLITE_OK)
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 15, filter.byCategory())) == SQLITE_OK &&
(sqlResult = sqlite3_bind_int(mStmtSearchNodes, 16, filter.byCategory())) == SQLITE_OK)
{
string wildCardName = '*' + filter.byName() + '*';
if ((sqlResult = sqlite3_bind_text(mStmtSearchNodes, 16, wildCardName.c_str(), static_cast<int>(wildCardName.length()), SQLITE_STATIC)) == SQLITE_OK)
if ((sqlResult = sqlite3_bind_text(mStmtSearchNodes, 17, wildCardName.c_str(), static_cast<int>(wildCardName.length()), SQLITE_STATIC)) == SQLITE_OK)
{
result = processSqlQueryNodes(mStmtSearchNodes, nodes);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/SdkTest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15617,6 +15617,14 @@ TEST_F(SdkTest, SdkTestGetNodeByMimetype)
ASSERT_EQ(nodeList->size(), 1);
ASSERT_EQ(nodeList->get(0)->getHandle(), handleSpreadsheetFile);

filterResults->byCategory(MegaApi::FILE_TYPE_ALL_DOCS); // any of {DOCUMENT, PDF, PRESENTATION, SPREADSHEET}
nodeList.reset(megaApi[0]->search(filterResults.get(), MegaApi::ORDER_DEFAULT_ASC)); // order Alphabetical asc
ASSERT_EQ(nodeList->size(), 4);
ASSERT_EQ(nodeList->get(0)->getHandle(), handleDocumentFile);
ASSERT_EQ(nodeList->get(1)->getHandle(), handleSpreadsheetFile);
ASSERT_EQ(nodeList->get(2)->getHandle(), handlePdfFile);
ASSERT_EQ(nodeList->get(3)->getHandle(), handleTxtFile);

deleteFile(PUBLICFILE);
}

Expand Down

0 comments on commit 702020e

Please sign in to comment.