@@ -237,7 +237,7 @@ class DatabaseManager {
237
237
- Returns: The executed statement
238
238
- Throws: SQL execution errors
239
239
*/
240
- private func fetchMessages( using db: Connection , where queryWhere: String ? = nil , sort querySort: String ? = nil , limit queryLimit: Int ? = nil ) throws -> Statement {
240
+ private func fetchMessages( using db: Connection , where queryWhere: String ? = nil , sort querySort: String ? = nil , limit queryLimit: Int ? = nil , bindings queryBindings : [ Binding ? ] = [ ] ) throws -> Statement {
241
241
var rows : [ String ] = [
242
242
" message.ROWID " ,
243
243
" message.guid " ,
@@ -285,7 +285,7 @@ class DatabaseManager {
285
285
rows. map { " \( $0) AS \" \( $0) \" " } . joined ( separator: " , " ) ,
286
286
extraClauses. joined ( separator: " " )
287
287
)
288
- return try db. prepare ( query)
288
+ return try db. prepare ( query, queryBindings )
289
289
}
290
290
291
291
//MARK: Requests
@@ -300,7 +300,7 @@ class DatabaseManager {
300
300
let timeLower = convertDBTime ( fromUNIX: timeLowerUNIX)
301
301
let timeUpper = convertDBTime ( fromUNIX: timeUpperUNIX)
302
302
303
- let stmt = try fetchMessages ( using: dbConnection, where: " message.date > \( timeLower ) AND message.date < \( timeUpper ) " )
303
+ let stmt = try fetchMessages ( using: dbConnection, where: " message.date > ? AND message.date < ? " , bindings : [ timeLower , timeUpper ] )
304
304
let indices = DatabaseConverter . makeColumnIndexDict ( stmt. columnNames)
305
305
let rows = try stmt. map { row in
306
306
try DatabaseConverter . processMessageRow ( row, withIndices: indices, ofDB: dbConnection)
@@ -314,7 +314,7 @@ class DatabaseManager {
314
314
public func fetchGrouping( fromID idLower: Int64 ) throws -> DBFetchGrouping {
315
315
guard let dbConnection = dbConnection else { throw DatabaseDisconnectedError ( ) }
316
316
317
- let stmt = try fetchMessages ( using: dbConnection, where: " message.ROWID > \( idLower ) " )
317
+ let stmt = try fetchMessages ( using: dbConnection, where: " message.ROWID > ? " , bindings : [ idLower ] )
318
318
let indices = DatabaseConverter . makeColumnIndexDict ( stmt. columnNames)
319
319
let rows = try stmt. map { row in
320
320
try DatabaseConverter . processMessageRow ( row, withIndices: indices, ofDB: dbConnection)
@@ -475,7 +475,7 @@ class DatabaseManager {
475
475
if let timeLowerUNIX = timeLowerUNIX {
476
476
let timeLower = convertDBTime ( fromUNIX: timeLowerUNIX)
477
477
478
- stmt = try fetchMessages ( using: dbConnection, where: " message.date > \( timeLower ) " )
478
+ stmt = try fetchMessages ( using: dbConnection, where: " message.date > ? " , bindings : [ timeLower ] )
479
479
} else {
480
480
stmt = try fetchMessages ( using: dbConnection)
481
481
}
@@ -556,11 +556,19 @@ class DatabaseManager {
556
556
public func fetchLiteThread( chatGUID: String , before: Int64 ? ) throws -> [ ConversationItem ] {
557
557
guard let dbConnection = dbConnection else { throw DatabaseDisconnectedError ( ) }
558
558
559
+ var fetchWhere : String = " chat.GUID = ? "
560
+ var fetchBindings : [ Binding ? ] = [ chatGUID]
561
+ if let before = before {
562
+ fetchWhere += " AND message.ROWID < ? "
563
+ fetchBindings. append ( before)
564
+ }
565
+
559
566
let stmt = try fetchMessages (
560
567
using: dbConnection,
561
- where: " chat.GUID = \" \( chatGUID ) \" " + ( before . map { " AND message.ROWID < \( $0 ) " } ?? " " ) ,
568
+ where: fetchWhere ,
562
569
sort: " message.ROWID DESC " ,
563
- limit: 24
570
+ limit: 24 ,
571
+ bindings: fetchBindings
564
572
)
565
573
let indices = DatabaseConverter . makeColumnIndexDict ( stmt. columnNames)
566
574
0 commit comments