Skip to content

Commit

Permalink
Add DBInterface.lastrowid
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Jan 9, 2020
1 parent dc03f77 commit 235f9e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,8 @@ stmt = DBInterface.prepare(conn, sql) # prepare a sql statement against the conn

results = DBInterface.execute!(stmt) # execute a prepared statement; returns an iterator of rows (property-accessible & indexable)

rowid = DBInterface.lastrowid(results) # get the last row id of an INSERT statement, as supported by the database

# example of using a query resultset
for row in results
@show propertynames(row) # see possible column names of row results
Expand Down Expand Up @@ -46,4 +48,5 @@ DBInterface.close!
DBInterface.Statement
DBInterface.prepare
DBInterface.execute!
DBInterface.lastrowid
```
9 changes: 8 additions & 1 deletion src/DBInterface.jl
Expand Up @@ -110,7 +110,14 @@ function executemany!(stmt::Statement, args...; kw...)
return
end

DBInterface.executemany!(conn::Connection, sql::AbstractString, args...; kw...) = DBInterface.executemany!(DBInterface.prepare(conn, sql), args...; kw...)
executemany!(conn::Connection, sql::AbstractString, args...; kw...) = executemany!(prepare(conn, sql), args...; kw...)

"""
DBInterface.lastrowid(x::Cursor) => Int
If supported by the specific database cursor, returns the last inserted row id after executing an INSERT statement.
"""
lastrowid(::T) where {T} = throw(NotImplementedError("`DBInterface.lastrowid` not implemented for $T"))

"""
DBInterface.close!(x::Cursor) => Nothing
Expand Down

0 comments on commit 235f9e4

Please sign in to comment.