Try to create table, but database is closed

I’ve created a database and am trying to create a table in it.

mkpath(spoolDir*"database")
db=SQLite.DB(spoolDir*"database/foo.db")

function makeTables()
  global db
  SQLite.execute(db,"create table if not exists nodes"*
    "(id integer primary key,x integer,y integer,z integer,ip text)")
end

The empty database file has been there since I created it a few weeks ago. But when I call makeTables, I get ERROR: SQLiteException("DB is closed"). How do I open it?