is sqlite3_open an expensive operation?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

is sqlite3_open an expensive operation?

jack wu
do we usually do:

open db->some operation with db->close db.

or keep the db handle with the thread and use it all
the time?

i am asking this mainly because of possible error
conditions. when an error happens, is it better to
close the database and reopen it later? i am going to
lock the handle with a global mutex, so thread safety
is not a concern, but who knows what kind of error
could occur. i would like to handle the error nicely
and still be able to use the database. so i thought
maybe always close the database is better?

jack.
Reply | Threaded
Open this post in threaded view
|

Re: is sqlite3_open an expensive operation?

D. Richard Hipp
jack wu <[hidden email]> wrote:

> do we usually do:
>
> open db->some operation with db->close db.
>
> or keep the db handle with the thread and use it all
> the time?
>
> i am asking this mainly because of possible error
> conditions. when an error happens, is it better to
> close the database and reopen it later? i am going to
> lock the handle with a global mutex, so thread safety
> is not a concern, but who knows what kind of error
> could occur. i would like to handle the error nicely
> and still be able to use the database. so i thought
> maybe always close the database is better?
>

The database schema must be read and parsed with each
sqlite3_open().  So the cost of an sqlite3_open() is
proportional to the size of your schema.
--
D. Richard Hipp <[hidden email]>