Skip to content

Commit e5d6d49

Browse files
committed
Merge branch 'hotfix/SDK-4130_new-virtual-column-mimetype' into 'release/v7.5.0'
SDK-4130. Create new virtual column for mimetypes (hotfix release/v7.5.0) See merge request sdk/sdk!5677
2 parents c54a98e + da95248 commit e5d6d49

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/db/sqlite.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ DbTable *SqliteDbAccess::openTableWithNodes(PrnGen &rng, FileSystemAccess &fsAcc
171171
// Create specific table for handle nodes
172172
std::string sql = "CREATE TABLE IF NOT EXISTS nodes (nodehandle int64 PRIMARY KEY NOT NULL, "
173173
"parenthandle int64, name text, fingerprint BLOB, origFingerprint BLOB, "
174-
"type tinyint, mimetype tinyint AS (getmimetype(name)) VIRTUAL, size int64, share tinyint, fav tinyint, "
175-
"ctime int64, mtime int64 DEFAULT 0, flags int64, counter BLOB NOT NULL, node BLOB NOT NULL, "
176-
"label tinyint DEFAULT 0, description text, tags text)";
174+
"type tinyint, mimetypeVirtual tinyint AS (getmimetype(name)) VIRTUAL, size "
175+
"int64, share tinyint, fav tinyint, ctime int64, mtime int64 DEFAULT 0, "
176+
"flags int64, counter BLOB NOT NULL, "
177+
"node BLOB NOT NULL, label tinyint DEFAULT 0, description text, tags text)";
178+
177179
int result = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr);
178180
if (result)
179181
{
@@ -192,7 +194,7 @@ DbTable *SqliteDbAccess::openTableWithNodes(PrnGen &rng, FileSystemAccess &fsAcc
192194
"tinyint DEFAULT 0",
193195
NodeData::COMPONENT_LABEL,
194196
NewColumn::extractDataFromNodeData<LabelType> },
195-
{"mimetype",
197+
{"mimetypeVirtual",
196198
"tinyint AS (getmimetype(name)) VIRTUAL",
197199
NodeData::COMPONENT_NONE,
198200
nullptr },
@@ -1575,11 +1577,11 @@ bool SqliteAccountState::getChildren(const mega::NodeSearchFilter& filter, int o
15751577
"AND (?8 = " + std::to_string(MIME_TYPE_UNKNOWN) +
15761578
" OR (type = " + std::to_string(FILENODE) +
15771579
" AND ((?8 = " + std::to_string(MIME_TYPE_ALL_DOCS) +
1578-
" AND mimetype IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
1580+
" AND mimetypeVirtual IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
15791581
',' + std::to_string(MIME_TYPE_PDF) +
15801582
',' + std::to_string(MIME_TYPE_PRESENTATION) +
15811583
',' + std::to_string(MIME_TYPE_SPREADSHEET) + "))"
1582-
" OR mimetype = ?8))) "
1584+
" OR mimetypeVirtual = ?8))) "
15831585
"AND (?11 = 0 OR (name REGEXP ?9)) "
15841586
"AND (?14 = 0 OR isContained(?15, description)) "
15851587
"AND (?16 = 0 OR matchTag(?17, tags)) "
@@ -1678,7 +1680,7 @@ bool SqliteAccountState::searchNodes(const NodeSearchFilter& filter, int order,
16781680
" AND nodehandle IN (SELECT nodehandle FROM nodes WHERE share = ?7)))";
16791681

16801682
string columnsForNodeAndFilters =
1681-
"nodehandle, parenthandle, flags, name, type, counter, node, size, ctime, mtime, share, mimetype, fav, label, description, tags";
1683+
"nodehandle, parenthandle, flags, name, type, counter, node, size, ctime, mtime, share, mimetypeVirtual, fav, label, description, tags";
16821684

16831685
string nodesOfShares =
16841686
"nodesOfShares(" + columnsForNodeAndFilters + ") \n"
@@ -1693,7 +1695,7 @@ bool SqliteAccountState::searchNodes(const NodeSearchFilter& filter, int order,
16931695
"WHERE parenthandle IN (SELECT nodehandle FROM ancestors) \n"
16941696
"UNION ALL \n"
16951697
"SELECT N.nodehandle, N.parenthandle, N.flags, N.name, N.type, N.counter, N.node, "
1696-
"N.size, N.ctime, N.mtime, N.share, N.mimetype, N.fav, N.label, N.description, N.tags \n"
1698+
"N.size, N.ctime, N.mtime, N.share, N.mimetypeVirtual, N.fav, N.label, N.description, N.tags \n"
16971699
"FROM nodes AS N \n"
16981700
"INNER JOIN nodesCTE AS P \n"
16991701
"ON (N.parenthandle = P.nodehandle \n"
@@ -1715,11 +1717,11 @@ bool SqliteAccountState::searchNodes(const NodeSearchFilter& filter, int order,
17151717
"AND (?8 = " + std::to_string(MIME_TYPE_UNKNOWN) +
17161718
" OR (type = " + std::to_string(FILENODE) +
17171719
" AND ((?8 = " + std::to_string(MIME_TYPE_ALL_DOCS) +
1718-
" AND mimetype IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
1720+
" AND mimetypeVirtual IN (" + std::to_string(MIME_TYPE_DOCUMENT) +
17191721
',' + std::to_string(MIME_TYPE_PDF) +
17201722
',' + std::to_string(MIME_TYPE_PRESENTATION) +
17211723
',' + std::to_string(MIME_TYPE_SPREADSHEET) + "))"
1722-
" OR mimetype = ?8))) \n"
1724+
" OR mimetypeVirtual = ?8))) \n"
17231725
"AND (?13 = 0 OR (name REGEXP ?9)) \n"
17241726
"AND (?17 = 0 OR isContained(?18, description)) \n"
17251727
"AND (?19 = 0 OR matchTag(?20, tags)) \n"

0 commit comments

Comments
 (0)