Skip to content

Commit 4027c88

Browse files
Replace NotImplementedErrors with MethodErrors
1 parent 025a5dd commit 4027c88

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

src/DBInterface.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ that returns a valid, live database connection that can be queried against.
1111
"""
1212
function connect end
1313

14-
connect(T, args...; kw...) = throw(NotImplementedError("`DBInterface.connect` not implemented for `$T`"))
14+
# Different `close!` signatures have their own docstrings.
15+
function close! end
1516

1617
"""
1718
DBInterface.close!(conn::DBInterface.Connection)
1819
1920
Immediately closes a database connection so further queries cannot be processed.
2021
"""
21-
function close! end
22+
close!(conn::Connection)
2223

23-
close!(conn::Connection) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(conn))`"))
2424

2525
"Database packages should provide a `DBInterface.Statement` subtype which represents a valid, prepared SQL statement that can be executed repeatedly"
2626
abstract type Statement end
@@ -38,7 +38,6 @@ which is often convenient when building applications.
3838
"""
3939
function prepare end
4040

41-
prepare(conn::Connection, sql::AbstractString) = throw(NotImplementedError("`DBInterface.prepare` not implemented for `$(typeof(conn))`"))
4241
prepare(f::Function, sql::AbstractString) = prepare(f(), sql)
4342

4443
const PREPARED_STMTS = Dict{Symbol, Statement}()
@@ -79,8 +78,6 @@ For use-cases involving multiple resultsets from a single query, see `DBInterfac
7978
"""
8079
function execute end
8180

82-
execute(stmt::Statement, params=()) = throw(NotImplementedError("`DBInterface.execute` not implemented for `$(typeof(stmt))`"))
83-
8481
execute(conn::Connection, sql::AbstractString, params=()) = execute(prepare(conn, sql), params)
8582

8683
struct LazyIndex{T} <: AbstractVector{Any}
@@ -138,28 +135,23 @@ executemultiple(conn::Connection, sql::AbstractString, params=()) = executemulti
138135
139136
Close a prepared statement so further queries cannot be executed.
140137
"""
141-
close!(stmt::Statement) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(stmt))`"))
138+
close!(stmt::Statement)
142139

143140
"""
144141
DBInterface.lastrowid(x::Cursor) => Int
145142
146143
If supported by the specific database cursor, returns the last inserted row id after executing an INSERT statement.
147144
"""
148-
lastrowid(::T) where {T} = throw(NotImplementedError("`DBInterface.lastrowid` not implemented for $T"))
145+
function lastrowid end
149146

150147
"""
151148
DBInterface.close!(x::Cursor) => Nothing
152149
153150
Immediately close a resultset cursor. Database packages should overload for the provided resultset `Cursor` object.
154151
"""
155-
close!(x) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(x))`"))
152+
close!(x::Cursor)
156153

157154
# exception handling
158-
"Error for signaling a database package hasn't implemented an interface method"
159-
struct NotImplementedError <: Exception
160-
msg::String
161-
end
162-
163155
"Error for signaling that parameters are used inconsistently or incorrectly."
164156
struct ParameterError <: Exception
165157
msg::String

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
using DBInterface, Test
22

3-
@test_throws DBInterface.NotImplementedError DBInterface.connect(Int64)
3+
@test_throws MethodError DBInterface.connect(Int64)

0 commit comments

Comments
 (0)