File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ public protocol SQLiteType {
6464 func getRow( sql: String , valuesToBind: SQLValues ? , valuesToGet: SQLValues ) throws -> [ SQLValues ]
6565 func getAllRows( in tableName: String , valuesToGet: SQLValues ) throws -> [ SQLValues ]
6666 func getByID( in tableName: String , id: Int , valuesToGet: SQLValues ) throws -> SQLValues
67+ func getLastRow( in tableName: String , valuesToGet: SQLValues ) throws -> SQLValues
6768 func getLastInsertID( ) throws -> Int
6869 func vacuum( ) throws
6970 func resetAutoincrement( in tableName: String ) throws
@@ -418,6 +419,17 @@ open class SQLite: SQLiteType {
418419 }
419420 }
420421
422+ public func getLastRow( in tableName: String , valuesToGet: SQLValues ) throws -> SQLValues {
423+ let sql = " SELECT * FROM \( tableName) WHERE id = (SELECT MAX(id) FROM \( tableName) ); "
424+ let result = try getRow ( sql: sql, valuesToBind: nil , valuesToGet: valuesToGet)
425+ if result. count == 1 {
426+ log ( " successfully read last row in \( tableName) " )
427+ return result [ 0 ]
428+ } else {
429+ throw SQLiteError . Column ( getErrorMessage ( dbPointer: dbPointer) )
430+ }
431+ }
432+
421433 public func getLastInsertID( ) throws -> Int {
422434 let sqlStatement = try prepareStatement ( sql: " SELECT last_insert_rowid(); " )
423435 defer {
You can’t perform that action at this time.
0 commit comments