From 4027c88a427f6c53eb3318eb9bdc90a374e644ea Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Sat, 13 Jun 2020 12:51:03 +0100 Subject: [PATCH 1/2] Replace `NotImplementedError`s with `MethodError`s --- src/DBInterface.jl | 20 ++++++-------------- test/runtests.jl | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/DBInterface.jl b/src/DBInterface.jl index ef43ac5..93ff215 100644 --- a/src/DBInterface.jl +++ b/src/DBInterface.jl @@ -11,16 +11,16 @@ that returns a valid, live database connection that can be queried against. """ function connect end -connect(T, args...; kw...) = throw(NotImplementedError("`DBInterface.connect` not implemented for `$T`")) +# Different `close!` signatures have their own docstrings. +function close! end """ DBInterface.close!(conn::DBInterface.Connection) Immediately closes a database connection so further queries cannot be processed. """ -function close! end +close!(conn::Connection) -close!(conn::Connection) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(conn))`")) "Database packages should provide a `DBInterface.Statement` subtype which represents a valid, prepared SQL statement that can be executed repeatedly" abstract type Statement end @@ -38,7 +38,6 @@ which is often convenient when building applications. """ function prepare end -prepare(conn::Connection, sql::AbstractString) = throw(NotImplementedError("`DBInterface.prepare` not implemented for `$(typeof(conn))`")) prepare(f::Function, sql::AbstractString) = prepare(f(), sql) const PREPARED_STMTS = Dict{Symbol, Statement}() @@ -79,8 +78,6 @@ For use-cases involving multiple resultsets from a single query, see `DBInterfac """ function execute end -execute(stmt::Statement, params=()) = throw(NotImplementedError("`DBInterface.execute` not implemented for `$(typeof(stmt))`")) - execute(conn::Connection, sql::AbstractString, params=()) = execute(prepare(conn, sql), params) struct LazyIndex{T} <: AbstractVector{Any} @@ -138,28 +135,23 @@ executemultiple(conn::Connection, sql::AbstractString, params=()) = executemulti Close a prepared statement so further queries cannot be executed. """ -close!(stmt::Statement) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(stmt))`")) +close!(stmt::Statement) """ 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")) +function lastrowid end """ DBInterface.close!(x::Cursor) => Nothing Immediately close a resultset cursor. Database packages should overload for the provided resultset `Cursor` object. """ -close!(x) = throw(NotImplementedError("`DBInterface.close!` not implemented for `$(typeof(x))`")) +close!(x::Cursor) # exception handling -"Error for signaling a database package hasn't implemented an interface method" -struct NotImplementedError <: Exception - msg::String -end - "Error for signaling that parameters are used inconsistently or incorrectly." struct ParameterError <: Exception msg::String diff --git a/test/runtests.jl b/test/runtests.jl index 6e68fae..30fc30a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,3 @@ using DBInterface, Test -@test_throws DBInterface.NotImplementedError DBInterface.connect(Int64) \ No newline at end of file +@test_throws MethodError DBInterface.connect(Int64) From 3d9e4e95a3630afa74b285c2b1a1f32b24ff1eb9 Mon Sep 17 00:00:00 2001 From: Nick Robinson Date: Sat, 13 Jun 2020 12:52:49 +0100 Subject: [PATCH 2/2] Bump minor version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 813b14a..e366ba5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DBInterface" uuid = "a10d1c49-ce27-4219-8d33-6db1a4562965" authors = ["Jacob Quinn "] -version = "2.1.0" +version = "2.2.0" [compat] julia = "1"