diff --git a/mobile/lib/db/files_db.dart b/mobile/lib/db/files_db.dart index 0bd3a9cfa9..2fe4f5db60 100644 --- a/mobile/lib/db/files_db.dart +++ b/mobile/lib/db/files_db.dart @@ -478,11 +478,10 @@ class FilesDB { } Future getFile(int generatedID) async { - final db = await instance.database; - final results = await db.query( - filesTable, - where: '$columnGeneratedID = ?', - whereArgs: [generatedID], + final db = await instance.ffiDB; + final results = db.select( + 'SELECT * FROM $filesTable WHERE $columnGeneratedID = ?', + [generatedID], ); if (results.isEmpty) { return null; @@ -491,11 +490,10 @@ class FilesDB { } Future getUploadedFile(int uploadedID, int collectionID) async { - final db = await instance.database; - final results = await db.query( - filesTable, - where: '$columnUploadedFileID = ? AND $columnCollectionID = ?', - whereArgs: [ + final db = await instance.ffiDB; + final results = db.select( + 'SELECT * FROM $filesTable WHERE $columnUploadedFileID = ? AND $columnCollectionID = ?', + [ uploadedID, collectionID, ], @@ -506,29 +504,12 @@ class FilesDB { return convertToFiles(results)[0]; } - Future getAnyUploadedFile(int uploadedID) async { - final db = await instance.database; - final results = await db.query( - filesTable, - where: '$columnUploadedFileID = ?', - whereArgs: [ - uploadedID, - ], - ); - if (results.isEmpty) { - return null; - } - return convertToFiles(results)[0]; - } - Future> getUploadedFileIDs(int collectionID) async { - final db = await instance.database; - final results = await db.query( - filesTable, - columns: [columnUploadedFileID], - where: - '$columnCollectionID = ? AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)', - whereArgs: [ + final db = await instance.ffiDB; + final results = db.select( + 'SELECT $columnUploadedFileID FROM $filesTable' + ' WHERE $columnCollectionID = ? AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)', + [ collectionID, ], ); @@ -540,12 +521,10 @@ class FilesDB { } Future getBackedUpIDs() async { - final db = await instance.database; - final results = await db.query( - filesTable, - columns: [columnLocalID, columnUploadedFileID, columnFileSize], - where: - '$columnLocalID IS NOT NULL AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)', + final db = await instance.sqliteAsyncDB; + final results = await db.getAll( + 'SELECT $columnLocalID, $columnUploadedFileID, $columnFileSize FROM $filesTable' + ' WHERE $columnLocalID IS NOT NULL AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1)', ); final Set localIDs = {}; final Set uploadedIDs = {}; @@ -681,13 +660,12 @@ class FilesDB { } Future> getAllFilesCollection(int collectionID) async { - final db = await instance.database; + final db = await instance.sqliteAsyncDB; const String whereClause = '$columnCollectionID = ?'; final List whereArgs = [collectionID]; - final results = await db.query( - filesTable, - where: whereClause, - whereArgs: whereArgs, + final results = await db.getAll( + 'SELECT * FROM $filesTable WHERE $whereClause', + whereArgs, ); final files = convertToFiles(results); return files; @@ -697,14 +675,13 @@ class FilesDB { int collectionID, int addedTime, ) async { - final db = await instance.database; + final db = await instance.sqliteAsyncDB; const String whereClause = '$columnCollectionID = ? AND $columnAddedTime > ?'; final List whereArgs = [collectionID, addedTime]; - final results = await db.query( - filesTable, - where: whereClause, - whereArgs: whereArgs, + final results = await db.getAll( + 'SELECT * FROM $filesTable WHERE $whereClause', + whereArgs, ); final files = convertToFiles(results); return files; @@ -726,20 +703,22 @@ class FilesDB { inParam += "'" + id.toString() + "',"; } inParam = inParam.substring(0, inParam.length - 1); - final db = await instance.database; + final db = await instance.sqliteAsyncDB; final order = (asc ?? false ? 'ASC' : 'DESC'); final String whereClause = '$columnCollectionID IN ($inParam) AND $columnCreationTime >= ? AND ' '$columnCreationTime <= ? AND $columnOwnerID = ?'; final List whereArgs = [startTime, endTime, userID]; - final results = await db.query( - filesTable, - where: whereClause, - whereArgs: whereArgs, - orderBy: - '$columnCreationTime ' + order + ', $columnModificationTime ' + order, - limit: limit, + String query = 'SELECT * FROM $filesTable WHERE $whereClause ORDER BY ' + '$columnCreationTime $order, $columnModificationTime $order'; + if (limit != null) { + query += ' LIMIT ?'; + whereArgs.add(limit); + } + final results = await db.getAll( + query, + whereArgs, ); final files = convertToFiles(results); final dedupeResult =