SQLite.jl icon indicating copy to clipboard operation
SQLite.jl copied to clipboard

Misleading `ERROR: SQLiteException("out of memory")` caused by closed database

Open wjholden opened this issue 3 years ago • 0 comments

I am creating this issue to hopefully help the next person who gets surprised by a misleading error message.

Suppose you build a SQLite database in Julia and you close it.

julia> using SQLite, DataFrames

julia> db = SQLite.DB("example.db");

julia> DBInterface.execute(db, "CREATE TABLE Example (ID INTEGER PRIMARY KEY)");

julia> DBInterface.execute(db, "INSERT INTO Example VALUES (1)");

julia> DBInterface.execute(db, "SELECT * FROM Example") |> DataFrame
1×1 DataFrame
 Row │ ID
     │ Int64
─────┼───────
   1 │     1

julia> close(db)

If you try to query the database again, you will get an "out of memory" error.

julia> DBInterface.execute(db, "SELECT * FROM Example") |> DataFrame
ERROR: SQLiteException("out of memory")
Stacktrace:
  [1] sqliteerror(args::SQLite.DB)
    @ SQLite C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\SQLite.jl:34
  [2] macro expansion
    @ C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\base.jl:10 [inlined]
  [3] prepare_stmt_wrapper
    @ C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\SQLite.jl:109 [inlined]
  [4] SQLite.Stmt(db::SQLite.DB, sql::String; register::Bool)
    @ SQLite C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\SQLite.jl:146
  [5] Stmt
    @ C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\SQLite.jl:145 [inlined]
  [6] prepare
    @ C:\Users\wjhol\.julia\packages\SQLite\aeqsS\src\SQLite.jl:180 [inlined]
  [7] execute
    @ C:\Users\wjhol\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:130 [inlined]
  [8] #execute#2
    @ C:\Users\wjhol\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:152 [inlined]
  [9] execute(conn::SQLite.DB, sql::String)
    @ DBInterface C:\Users\wjhol\.julia\packages\DBInterface\1Gmxx\src\DBInterface.jl:152
 [10] top-level scope
    @ REPL[7]:1

wjholden avatar Feb 09 '23 07:02 wjholden