12-14 19:51:30.346 17770-18098/com.company.product W/System.err: com.company.product.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:913) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:819) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:159) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:147) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.AbstractCursor.moveToPosition(AbstractCursor.java:218) 12-14 19:51:30.346 17770-18098/com.company.product W/System.err: at com.company.product.database.sqlite.AbstractCursor.moveToFirst(AbstractCursor.java:258)
12-14 19:51:30.346 17770-18098/com.company.package E/SQLiteLog: (14) cannot open file at line 32440 of [bda77dda96] 12-14 19:51:30.346 17770-18098/com.company.package E/SQLiteLog: (14) os_unix.c:32440: (30) open(./etilqs_3P2SKRP0Ge6cj3T) - 12-14 19:51:30.346 17770-18098/com.company.package E/SQLiteLog: (14) statement aborts at 180: [SELECT M.*,…………………
/* ** Temporary files are named starting with this prefix followed by 16 random ** alphanumeric characters, and no file extension. They are stored in the ** OS's standard temporary file directory, and are deleted prior to exit. ** If sqlite is being embedded in another program, you may wish to change the ** prefix to reflect your program's name, so that if your program exits ** prematurely, old temporary files can be easily identified. This can be done ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. ** ** 2006-10-31: The default prefix used to be "sqlite_". But then ** Mcafee started using SQLite in their anti-virus product and it ** started putting files with the "sqlite" name in the c:/temp folder. ** This annoyed many windows users. Those users would then do a ** Google search for "sqlite", find the telephone numbers of the ** developers and call to wake them up at night and complain. ** For this reason, the default name prefix is changed to be "sqlite" ** spelled backwards. So the temp files are still identified, but ** anybody smart enough to figure out the code is also likely smart ** enough to know that calling the developer will not help get rid ** of the file. */ #ifndef SQLITE_TEMP_FILE_PREFIX # define SQLITE_TEMP_FILE_PREFIX "etilqs_" #endif
/*
** Create a temporary file name in zBuf. zBuf must be allocated
** by the calling process and must be big enough to hold at least
** pVfs->mxPathname bytes.
*/
static int unixGetTempname(int nBuf, char *zBuf){
static const unsigned char zChars[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
unsigned int i, j;
const char *zDir;
/* It's odd to simulate an io-error here, but really this is just
** using the io-error infrastructure to test that SQLite handles this
** function failing.
*/
SimulateIOError( return SQLITE_IOERR );
zDir = unixTempFileDir();
if( zDir==0 ) zDir = ".";
/* Check that the output buffer is large enough for the temporary file
** name. If it is not, return SQLITE_ERROR.
*/
if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 18) >= (size_t)nBuf ){
return SQLITE_ERROR;
}
do{
sqlite3_snprintf(nBuf-18, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
j = (int)strlen(zBuf);
sqlite3_randomness(15, &zBuf[j]);
for(i=0; i<15; i++, j++){
zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
}
zBuf[j] = 0;
zBuf[j+1] = 0;
}while( osAccess(zBuf,0)==0 );
return SQLITE_OK;
}
这里可以留意到一个神奇的东西 zDir = unixTempFileDir(); if( zDir==0 ) zDir = ".";我们的文件是 ./etilqs_3P2SKRP0Ge6cj3T 所以unixTempFileDir()确实是返回了0 那再看下unixTempFileDir();
/*
** 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;
}

system(“ls . > /sdcard/0.txt”);
acct adb_keys cache config d data default.prop dev etc firmware fstab.qcom init init.goldfish.rc init.qcom.class_core.sh init.qcom.class_main.sh init.qcom.rc init.qcom.sh init.qcom.usb.rc init.qcom.usb.sh init.rc init.target.rc init.trace.rc init.usb.rc mnt persist proc root sbin sdcard storage storage_int sys system tombstones ueventd.goldfish.rc ueventd.qcom.rc ueventd.rc vendor
12-19 21:00:45.633 13680-14105/com.company.package E/SQLiteLog: (14) pagerstress;/data/data/com.company.package/databases/push 12-19 21:00:45.633 13680-14105/com.company.package E/SQLiteLog: (14) pager_write_pagelist 12-19 21:00:46.083 3727-3727/? I/DEBUG: #00 pc 00037202 /data/app-lib/com.company.package-1/libqmsqlite.so unixGetTempname 32107 12-19 21:00:46.083 3727-3727/? I/DEBUG: #01 pc 000376a7 /data/app-lib/com.company.package-1/libqmsqlite.so unixOpen 32396 12-19 21:00:46.083 3727-3727/? I/DEBUG: #02 pc 00015ec5 /data/app-lib/com.company.package-1/libqmsqlite.so sqlite3OsOpen 17420 12-19 21:00:46.083 3727-3727/? I/DEBUG: #03 pc 0003a16b /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #04 pc 0003e0c7 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #05 pc 00038e75 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #06 pc 00038f55 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #07 pc 00039445 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #08 pc 0003add1 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #09 pc 0003c1f1 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #10 pc 0003d8df /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #11 pc 0004c2e7 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.093 3727-3727/? I/DEBUG: #12 pc 0004e317 /data/app-lib/com.company.package-1/libqmsqlite.so (sqlite3_step+334) 12-19 21:00:46.093 3727-3727/? I/DEBUG: #13 pc 00063ebd /data/app-lib/com.company.package-1/libqmsqlite.so (sqlite3_blocking_step+6) 12-19 21:00:46.093 3727-3727/? I/DEBUG: #14 pc 00012279 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.103 3727-3727/? I/DEBUG: 61e75c04 61ced1f7 /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.103 3727-3727/? I/DEBUG: 61e75c24 61ced6ab /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.103 3727-3727/? I/DEBUG: 61e75c50 61d71f4c /data/app-lib/com.company.package-1/libqmsqlite.so 12-19 21:00:46.113 3727-3727/? I/DEBUG: 61e7610c 61cf016f /data/app-lib/com.company.package-1/libqmsqlite.so
pagerOpentemp /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:46566 pagerStress /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:47482 sqlite3PcacheFetchStress /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:40751 btreeGetPage /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:56428 btreeGetUnusedPage /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:56556 allocateBtreePage /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:60283 balance_nonroot /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:61869 sqlite3BtreeInsert /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:62554 sqlite3VdbeExec /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:77746 (discriminator 3) sqlite3Step /media/Software/company/qmsqlite/jni/sqlite/sqlite3.c:71550 sqlite3_blocking_step /media/Software/company/qmsqlite/jni/sqlite/sqlite3_unlock_notify.c:85 (discriminator 1) nativeExecuteForCursorWindow /media/Software/company/qmsqlite/jni/sqlite/SQLiteConnection.cpp:994
懒得看图的童鞋还是听我说吧,
先看sqlite的architecture
因为我们crash的地方是查DB的地方,所以拿query操作来解释这个architecture是怎么运行的
先用SQL Command Processor解析sql语句,变成类似汇编的命令给Virtual Machine执行,
我们可以用explain plan select …. 这样的语句来查看virtual machine要执行的命令,比如
explain plan select * from A where A.a in (select b from B)
0| Trace| 0| 0| 0| | 00 1| Goto| 0| 56| 0| | 00 2| OpenRead| 0| 4| 0| 13| 00 3| Rewind| 0| 54| 0| | 00 4| null| 0| 1| 0| | 00 5| Once| 0| 17| 0| | 00 6| null| 0| 1| 0| | 00 7| OpenEphemeral| 4| 1| 0| keyinfo(1,BINARY)| 00 8| Integer| 10000| 2| 0| | 00 9| OpenRead| 1| 5| 0| 1| 00 10| Rewind| 1| 16| 0| | 00 11| Column| 1| 0| 3| | 00 12| MakeRecord| 3| 1| 4| b| 00 13| IdxInsert| 4| 4| 0| | 00 14| IfZero| 2| 16| -1| | 00 15| Next| 1| 11| 0| | 01 16| Close| 1| 0| 0| | 00 17| Column| 0| 0| 4| | 00 18| IsNull| 4| 22| 0| | 00 19| Affinity| 4| 1| 0| b| 00 20| NotFound| 4| 22| 4| 1| 00 21| Goto| 0| 39| 0| | 00 22| null| 0| 5| 0| | 00 23| Once| 1| 35| 0| | 00 24| null| 0| 5| 0| | 00 25| OpenEphemeral| 6| 1| 0| keyinfo(1,BINARY)| 00 26| Integer| 10000| 6| 0| | 00 27| OpenRead| 2| 5| 0| 12| 00 28| Rewind| 2| 34| 0| | 00 29| Column| 2| 11| 7| | 00 30| MakeRecord| 7| 1| 4| b| 00 31| IdxInsert| 6| 4| 0| | 00 32| IfZero| 6| 34| -1| | 00 33| Next| 2| 29| 0| | 01 34| Close| 2| 0| 0| | 00 35| Column| 0| 1| 4| | 00 36| IsNull| 4| 53| 0| | 00 37| Affinity| 4| 1| 0| b| 00 38| NotFound| 6| 53| 4| 1| 00 39| Column| 0| 0| 8| | 00 40| Column| 0| 1| 9| | 00 41| Column| 0| 2| 10| | 00 42| Column| 0| 3| 11| | 00 43| Column| 0| 4| 12| | 00 44| Column| 0| 5| 13| | 00 45| Column| 0| 6| 14| | 00 46| Column| 0| 7| 15| | 00 47| Column| 0| 8| 16| | 00 48| Column| 0| 9| 17| | 00 49| Column| 0| 10| 18| | 00 50| Column| 0| 11| 19| | 00 51| Column| 0| 12| 20| | 00 52| ResultRow| 8| 13| 0| | 00 53| Next| 0| 4| 0| | 01 54| Close| 0| 0| 0| | 00 55| Halt| 0| 0| 0| | 00 56| Transaction| 0| 0| 0| | 00 57| VerifyCookie| 0| 3| 0| | 00 58| TableLock| 0| 4| 0| labels| 00 59| TableLock| 0| 5| 0| Items| 00 60| Goto| 0| 2| 0| | 00
PRAGMA temp_store_directory = 'your dir'
private static boolean mainTmpDirSet = false;
@Override
public SQLiteDatabase getReadableDatabase() {
if (!mainTmpDirSet) {
boolean rs = new File("/data/data/com.cmp.pkg/databases/main").mkdir();
Log.d("ahang", rs + "");
super.getReadableDatabase().execSQL("PRAGMA temp_store_directory = '/data/data/com.cmp.pkg/databases/main'");
mainTmpDirSet = true;
return super.getReadableDatabase();
}
return super.getReadableDatabase();
}
文章来源:http://www.cnblogs.com/hellocwh/p/5061805.html