sqlite3_close()

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

sqlite3_close()

Joe Halpin
One of the return values from sqlite3_close() is SQLITE_BUSY. The
examples I've seen so far all exit after calling this function and don't
check the return value. I need to be able to close and reopen the
database without exiting, but I'm not sure what to do if I get
SQLITE_BUSY as the return from sqlite3_close().

Should I wait and try again until I get SQLITE_OK or SQLITE_ERROR?

Thanks

Joe
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_close()

Igor Tandetnik
Joe Halpin wrote:
> One of the return values from sqlite3_close() is SQLITE_BUSY. The
> examples I've seen so far all exit after calling this function and
> don't check the return value. I need to be able to close and reopen
> the database without exiting, but I'm not sure what to do if I get
> SQLITE_BUSY as the return from sqlite3_close().
>
> Should I wait and try again until I get SQLITE_OK or SQLITE_ERROR?

sqlite3_close only returns SQLITE_BUSY if you still have prepared
statements against the db handle. You need to finalize all statements
before you can close the database. If you get this error, there is a
logical bug in your program that you need to fix. In any case, just
retrying sqlite3_close is pointless - those statements won't magically
finalize themselves so you would just get the same error over and over.

Igor Tandetnik

Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_close()

John Stanton-3
In reply to this post by Joe Halpin
Try calling sqlite3_finalize on the prepared statements before
sqlite3_close.

Joe Halpin wrote:

> One of the return values from sqlite3_close() is SQLITE_BUSY. The
> examples I've seen so far all exit after calling this function and don't
> check the return value. I need to be able to close and reopen the
> database without exiting, but I'm not sure what to do if I get
> SQLITE_BUSY as the return from sqlite3_close().
>
> Should I wait and try again until I get SQLITE_OK or SQLITE_ERROR?
>
> Thanks
>
> Joe

Reply | Threaded
Open this post in threaded view
|

Re: Re: sqlite3_close()

Joe Halpin
In reply to this post by Igor Tandetnik
Igor Tandetnik wrote:

> Joe Halpin wrote:
>
>> One of the return values from sqlite3_close() is SQLITE_BUSY. The
>> examples I've seen so far all exit after calling this function and
>> don't check the return value. I need to be able to close and reopen
>>  the database without exiting, but I'm not sure what to do if I get
>>  SQLITE_BUSY as the return from sqlite3_close().
>>
>> Should I wait and try again until I get SQLITE_OK or SQLITE_ERROR?
>
> sqlite3_close only returns SQLITE_BUSY if you still have prepared
> statements against the db handle. You need to finalize all statements
>  before you can close the database. If you get this error, there is a
>  logical bug in your program that you need to fix. In any case, just
>  retrying sqlite3_close is pointless - those statements won't
> magically finalize themselves so you would just get the same error
> over and over.

Ok, thanks. I'm pretty new to this so I haven't got all the concepts
down yet.

Joe
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_close()

Joe Halpin
In reply to this post by John Stanton-3
Ok, thanks. I'm pretty new to this kind of thing so I appreciate the
feedback.

joe

John Stanton wrote:

> Try calling sqlite3_finalize on the prepared statements before
> sqlite3_close.
>
> Joe Halpin wrote:
>
>> One of the return values from sqlite3_close() is SQLITE_BUSY. The
>> examples I've seen so far all exit after calling this function and
>> don't check the return value. I need to be able to close and reopen
>> the database without exiting, but I'm not sure what to do if I get
>> SQLITE_BUSY as the return from sqlite3_close().
>>
>> Should I wait and try again until I get SQLITE_OK or SQLITE_ERROR?
>>
>> Thanks
>>
>> Joe
>
>
>