Skip to content

Commit a262080

Browse files
committed
Improved insertRow(sql:valuesToBind:)
Now returns the id for the last inserted row
1 parent e3c5066 commit a262080

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Sources/SQLiteAdapter/SQLiteAdapter.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public protocol SQLiteType {
5454
func dropIndex(in tableName: String, forColumn columnName: String) throws
5555
func beginTransaction() throws
5656
func endTransaction() throws
57-
func insertRow(sql: String, valuesToBind: SQLValues?) throws
57+
func insertRow(sql: String, valuesToBind: SQLValues?) throws -> Int
5858
func updateRow(sql: String, valuesToBind: SQLValues?) throws
5959
func deleteRow(sql: String, valuesToBind: SQLValues?) throws
6060
func deleteByID(in tableName: String, id: Int) throws
@@ -291,9 +291,11 @@ open class SQLite: SQLiteType {
291291
}
292292

293293
/// Can be used to insert one or several rows depending on the SQL statement
294-
public func insertRow(sql: String, valuesToBind: SQLValues? = nil) throws {
294+
/// - Returns: The id for the last inserted row
295+
public func insertRow(sql: String, valuesToBind: SQLValues? = nil) throws -> Int {
295296
try operation(sql: sql, valuesToBind: valuesToBind)
296297
log("successfully inserted row(s), sql: \(sql)")
298+
return Int(sqlite3_last_insert_rowid(dbPointer))
297299
}
298300

299301
/// Can be used to update one or several rows depending on the SQL statement

0 commit comments

Comments
 (0)