On Tue, Oct 29, 2013 at 9:23 AM, Matthew Dumbleton <msd...@hotmail.com>wrote:

> I have an android application using sqlite that starts with a database
> being created and then filled with a lot of data.
> I have noticed that occasionally, after the data is entered and the
> transaction ended, the close method call produces an error 'unable to close
> due to unfinalised statements' and logCat shows the SQLITE_BUSY error code.
>


A wild guess:  You might have some statements that are not be explicitly
finalized, but are instead being finalized by the garbage collector, which
means they may or may not get finalized before you close.


> I know this error normally occurs where a Cursor is used and not closed
> but this method doesn't do anything other than insert data.
> I managed to work around the problem in two ways, firstly by using the
> isOpen method to loop the close call like so:
>
> finally
> {
>             writer.endTransaction();
>             while(writer.isOpen())
>             {
>                 try
>                 {
>                     writer.close();
>                 }
>                 catch(SQLiteException e)
>                 {
>                     if(e.getMessage().contains("unable to close due to
> unfinalised statements"))
>                     {
>                        //do nothing here, loop to try again
>                     }
>                     else
>                     {
>                         throw e;
>                     }
>                 }
>             }
> and this seems to mean the second time of calling does not error and the
> program continues, but I have been told this is because the second call to
> close doesn't actually do anything.  Is this true?
>
> The second way involves simply adding a thread.sleep after the
> endTransaction and this seems to stop the error ever occuring.  Does this
> mean the endTransaction returns before the actual commit/rollback is
> complete?/Is there another reason why this pause might resolve the issue?
> (Maybe something to do with the way I insert the data?)
>
> I have already posted this question on stackoverflow under the name
> 'Android & SQLite - Occasional error 'unable to close due to unfinalised
> statements' if anyone wants more explanation or code snippets.
>
> Thanks in advance.
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to