Skip to content

Commit 844c675

Browse files
nkottaryquinnj
authored andcommitted
Add last_insert_rowid method (#177)
1 parent 40e57a3 commit 844c675

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/SQLite.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,11 @@ returns a list of columns in `table`
422422
"""
423423
columns(db::DB, table::AbstractString, sink=DataFrame) = Query(db, "PRAGMA table_info($(esc_id(table)))") |> sink
424424

425-
end # module
425+
"""
426+
`SQLite.last_insert_rowid(db)`
427+
428+
returns the auto increment id of the last row
429+
"""
430+
last_insert_rowid(db::DB) = sqlite3_last_insert_rowid(db.handle)
431+
432+
end # module

src/api.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,4 +458,10 @@ function sqlite3_close_v2(handle::Ptr{Cvoid})
458458
warn("sqlite3_close_v2 not available.")
459459
sqlite3_close(handle)
460460
end
461-
end
461+
end
462+
function sqlite3_last_insert_rowid(handle::Ptr{Cvoid})
463+
@NULLCHECK handle
464+
return ccall( (:sqlite3_last_insert_rowid, libsqlite),
465+
Clong, (Ptr{Cvoid},),
466+
handle)
467+
end

0 commit comments

Comments
 (0)