3

I saw that a similar issue has been reported many times. In my case, I'm directly using the "C" API invoked using my own JNI library (not the Android Java layer), with the latest amalgamation 3.8.3. So I control what I'm dealing with. Then, on certain operations (UPDATE) I'm getting an error stating that it cannot open a database file. I don't get that with INSERT statements, only UPDATE. When I activate the SQLite error callback, I'm seeing the following:

cannot open file at line 29299 of [6c643e45c2] os_unix.c: 29299: (13) open(./etilqs_1zMsiYdpXhd3JqY) - statements aborts at 36: [UPDATE .....]

Digging this a little bit further, it appears to be related to the journal file. When I set the journal_mode to MEMORY using a pragma, then the issue disappears. But all the other modes, like WAL or TRUNCATED lead to the same error.

When debugging the code from eclipse, I can see the -journal file being created when performing the INSERT. And then being removed when the transaction is complete. So it tells me that it has enough rights on the directory (/data/data//)

Note that the exact same code works perfectly (C & Java) on Windows, where I'm not getting the error. There is definitively something going on with Android and file access.

I have a way to get the error reproduced systematically. If someone has some idea on what I should check, then I'll be happy to run some experiment and report the result.

Philippe Riand
  • 673
  • 4
  • 12
  • This is a temporary file. How did you configure the temp path of your copy of the SQLite library? – CL. Feb 11 '14 at 11:10
  • I didn't do any configuration. I see the journal file being created in the same directory than the DB when INSERT are performed. But it fails when executing UPDATE. – Philippe Riand Feb 11 '14 at 15:32
  • This is not a journal file. it is a temporary file. And the current directory (`./`) is not necessarily that of the database file. – CL. Feb 11 '14 at 16:06
  • right, but I can see the -journal file created from the File explorer in Eclipse during the processing of the transaction. – Philippe Riand Feb 11 '14 at 16:31
  • You must visit the [Link][1]. It will definately solve your problem. Thanks [1]: http://stackoverflow.com/questions/17034511/android-database-sqlite-sqlitecantopendatabaseexception-unknown-error-code-14 – Pawan May 07 '15 at 05:25

1 Answers1

2

Too late answer..

I saw same problem, when using multi-thread.

Send next statement query in your first query.

PRAGMA temp_store_directory = 'some writeable path'

SQLITE3 Document says "deprecated", but.. this works for me..

Is really deprecated??

good luck..

ps. my sqlite3 version is [sqlite-amalgamation-3100200]

Anup Agrawal
  • 6,551
  • 1
  • 26
  • 32
james park
  • 21
  • 4
  • It's correct, just take a look at the source code that relate to `etilqs`, sqlite store its temp file to `/tmp`, `/usr/tmp`, but Android did not have that folder. Use this deprecated API seems to be the only answer. (There are lots of ways that sqlite might use temp directory, so just put this inside the `onConfigure` method, that should solve lots of problems). – Frank Xu Apr 18 '16 at 11:46
  • That worked for me. I'm actually setting the temp path to the parent directory of the database and it works. I'll submit an issue to the SQLite team. – Philippe Riand Sep 08 '16 at 15:11
  • But in the app already have many database then how we can decide which database or where to include this statement ? – Gaurav Mandlik Nov 18 '21 at 04:46