Ensure that a cursor outlives its database

Cursors now borrow a pointer to the database handle. This changes the prepare() api.