How are you handling transactions in your queries? In later versions of 
Android SQLite writes by default temporary "journaling" data files that are 
not immediately merged with the actual database file (see here: 
http://www.sqlite.org/tempfiles.html). This might be an explanation for the 
reported behavior, see the following quote from the SQLite documentation:

However, if the last connection does not shutdown cleanly, the WAL file 
> will remain in the filesystem and will be automatically cleaned up the next 
> time the database is opened. 
>

Other than that, are you sure the path argument is always the same?

On Monday, July 29, 2013 7:00:11 PM UTC-5, Nathan wrote:
>
> Based on previous discussions of best practices here, I employ a factory 
> method for opening SQLite Databases. 
>
>     /**
>      * Factory method ensures only one instance of database in memory. 
>      * @param path on external storage
>      * @return
>      */
>     static public SQLiteDatabase getInstance(String path)
>     {
>         try
>         {
>             if(alreadyOpened.containsKey(path))
>             {
>                 return alreadyOpened.get(path);
>             }
>                     
>             SQLiteDatabase tdb= SQLiteDatabase.openDatabase(path, null, 
> SQLiteDatabase.OPEN_READWRITE |SQLiteDatabase.CREATE_IF_NECESSARY);
>             
>             alreadyOpened.put(path, tdb);
>             return tdb;
>         }
>         catch(Exception ex)
>         {
>             Log.e("TileDatabase", "openExisting", ex);
>             return null;
>         }
>     }
>
> This ensures that an SQLiteDatabase is opened once and closed never, which 
> Diane and others here said is a reasonable pattern. 
>
> Nonetheless, I get some reports from some users that their data 
> dissappears and reappears. In the morning it works, in the afternoon it is 
> not available, and the next day it is back again. 
>
> Ie, there is a query for blobs in this database and is either coming back 
> with zero results or throwing a SQLiteException that I am handling and 
> returning not available. If I manage to get logs from the users, I might 
> know what exception it is. 
>
> So in general, my question is this. Is there a reason that SQLiteDatabase 
> object may become inneffective, due to some changes in the system or 
> something I am doing, such as leaking a cursor or something? Could a 
> terminated process, due to Android wanting more memory or a crash, cause me 
> to be unable to open the database when the process starts again?
>
> Should I be calling SQLiteDatabase.isOpen periodically or anything like 
> that?
>
> Nathan

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to