New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLiteCantOpenDatabaseException unable to open db-journal #380
Comments
@battlmonstr You'll run into this crash whenever you're rapidly querying a Sqlite database, especially on multiple threads. I've always found when dealing with network or disk that try catches are for the best. You can create a singleton class that is your query handler to centralize your error handling. |
Same problem here. 1/ When you're using this, you're putting try/catch around every methods that can call a SQL request? How does work your singleton? Looks a lot of boilerplate without speaking about error scenarios you have to write everywhere, no? 2/ How do you handle when the issue comes from the lib? (see below) |
Following an advice from @kaeawc I've made my own wrapper of the query methods that I use from DBFlow (like queryList, querySingle etc), and I have to use it instead of DBFlow methods all over the place. I would really prefer if this functionality (common exception handler) would be implemented by the DBFlow itself, because it's easy to miss out wrapping some call, and also it's not trivial to do for all DBFlow methods in general. |
Yes, but what could be the good implementation to manage these exceptions? |
battlmonstr, Make sure for every query that has a cursor, you close() the cursor when done. Let me know if that helps! |
I got this exception after I query the database many times. In my sql, I do a lot of subquery, and when the exception looked like this: I think it was caused by the error of the temp file etilqs_TcZfcNFRZAgwTln. Could somebody tell me any reason that could cause the failure of opening this file? |
Ydvisual, It's not a problem of opened cursors. I'm only using queryList() and querySingle(), which close the cursor for me. I also use some Delete-s, for which I call queryClose(). |
OK battlmonstr; I see. On Mon, Dec 7, 2015 at 6:30 PM, battlmonstr notifications@github.com
|
I think I'm having the same issue on a app I'm working on. |
I got my answer. This crash happened when I do a lot of query on my DB; /*
** Return the name of a directory in which to put temporary files.
** If no suitable temporary file directory can be found, return NULL.
*/
static const char *unixTempFileDir(void){
static const char *azDirs[] = {
0,
0,
0,
"/var/tmp",
"/usr/tmp",
"/tmp",
0 /* List terminator */
};
unsigned int i;
struct stat buf;
const char *zDir = 0;
azDirs[0] = sqlite3_temp_directory;
if( !azDirs[1] ) azDirs[1] = getenv("SQLITE_TMPDIR");
if( !azDirs[2] ) azDirs[2] = getenv("TMPDIR");
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
if( zDir==0 ) continue;
if( osStat(zDir, &buf) ) continue;
if( !S_ISDIR(buf.st_mode) ) continue;
if( osAccess(zDir, 07) ) continue;
break;
}
return zDir;
} in android system, none of the directory is writable,
so it's sure that sqlite can not create of open this temp file named "./etilqs_3P2SKRP0Ge6cj3T". To trigger this crash, you can insert a lot of records into you databases and repeatly do something like select * from a where a.x in (select * from b) or other things that will rapidly exhaust the memory for page, and you will trigger sqlite to open this kind of temp file and get the crash. so how to fix the problem? I suggest to set the temp dir to your database directory's subdirectory like: Sqlite will automatically clear the temp files under the directory after the temp file is useless, Good luck. if you can understand Chinese, you can have a look at this link: |
Hardcore stuff, @cwhGitHub 梦里风林 ! |
I assume this is fixed? |
@ahangchen this pragma is deprecated
|
open it! |
I'm getting an exception that comes from SQLite not being able to open db-journal.
I'm running a lot of queries successfully, but at some point it crashes.
This happens rarely, and it is hard to reproduce.
If you google "db-journal" and SQLiteCantOpenDatabaseException , it gives a lot of similar crashes that people have (without using DBFlow), and the solution they suggest is to close the DB handle, wait a second and try to open it again.
The first question, should it be done inside DBFlow, or can it be done in my code ?
Another question is: is it possible to catch this kind of exception centrally somehow, because I don't want to put every DBFlow call in a try-catch. (or should I?)
Device: Google Nexus 7
OS : Android 5
log:
The text was updated successfully, but these errors were encountered: