1diff -r -u -d orig/shell.c ./shell.c 2--- orig/shell.c 2015-08-26 20:14:53.502376811 -0400 3+++ ./shell.c 2015-08-26 20:15:12.150229710 -0400 4@@ -35,6 +35,11 @@ 5 #include "sqlite3.h" 6 #include <ctype.h> 7 #include <stdarg.h> 8+// Begin Android Add 9+#ifndef NO_ANDROID_FUNCS 10+#include <sqlite3_android.h> 11+#endif 12+// End Android Add 13 14 #if !defined(_WIN32) && !defined(WIN32) 15 # include <signal.h> 16@@ -1737,6 +1742,21 @@ 17 readfileFunc, 0, 0); 18 sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0, 19 writefileFunc, 0, 0); 20+ 21+ // Begin Android Add 22+ #ifndef NO_ANDROID_FUNCS 23+ int err = register_localized_collators(db, "en_US", 0); 24+ if (err != SQLITE_OK) { 25+ fprintf(stderr, "register_localized_collators() failed\n"); 26+ exit(1); 27+ } 28+ err = register_android_functions(db, 0); 29+ if (err != SQLITE_OK) { 30+ fprintf(stderr, "register_android_functions() failed\n"); 31+ exit(1); 32+ } 33+ #endif 34+ // End Android Add 35 } 36 } 37 38diff -r -u -d orig/sqlite3.c ./sqlite3.c 39--- orig/sqlite3.c 2015-08-26 20:14:53.518376684 -0400 40+++ ./sqlite3.c 2015-08-26 20:15:12.150229710 -0400 41@@ -24115,6 +24115,13 @@ 42 */ 43 #if SQLITE_OS_UNIX /* This file is used on unix only */ 44 45+/* Use posix_fallocate() if it is available 46+*/ 47+#if !defined(HAVE_POSIX_FALLOCATE) \ 48+ && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L) 49+# define HAVE_POSIX_FALLOCATE 1 50+#endif 51+ 52 /* 53 ** There are various methods for file locking used for concurrency 54 ** control: 55@@ -24666,7 +24673,12 @@ 56 #else 57 { "pread64", (sqlite3_syscall_ptr)0, 0 }, 58 #endif 59+#ifdef ANDROID 60+// Bionic defines pread64 using off64_t rather than off_t. 61+#define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent) 62+#else 63 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) 64+#endif 65 66 { "write", (sqlite3_syscall_ptr)write, 0 }, 67 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) 68@@ -24684,8 +24696,14 @@ 69 #else 70 { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, 71 #endif 72+#ifdef ANDROID 73+// Bionic defines pwrite64 using off64_t rather than off_t. 74+#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\ 75+ aSyscall[13].pCurrent) 76+#else 77 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ 78 aSyscall[13].pCurrent) 79+#endif 80 81 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, 82 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) 83@@ -27915,7 +27933,7 @@ 84 SimulateIOError( rc=1 ); 85 if( rc!=0 ){ 86 ((unixFile*)id)->lastErrno = errno; 87- return SQLITE_IOERR_FSTAT; 88+ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath); 89 } 90 *pSize = buf.st_size; 91 92@@ -27950,7 +27968,9 @@ 93 i64 nSize; /* Required file size */ 94 struct stat buf; /* Used to hold return values of fstat() */ 95 96- if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; 97+ if( osFstat(pFile->h, &buf) ) { 98+ return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath); 99+ } 100 101 nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; 102 if( nSize>(i64)buf.st_size ){ 103@@ -28516,7 +28536,7 @@ 104 ** with the same permissions. 105 */ 106 if( osFstat(pDbFd->h, &sStat) && pInode->bProcessLock==0 ){ 107- rc = SQLITE_IOERR_FSTAT; 108+ rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath); 109 goto shm_open_err; 110 } 111 112@@ -29854,7 +29874,7 @@ 113 *pUid = sStat.st_uid; 114 *pGid = sStat.st_gid; 115 }else{ 116- rc = SQLITE_IOERR_FSTAT; 117+ rc = unixLogError(SQLITE_IOERR_FSTAT, "stat", zDb); 118 } 119 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){ 120 *pMode = 0600; 121@@ -100894,7 +100914,7 @@ 122 } 123 if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){ 124 sqlite3SetString(pzErrMsg, db, "unsupported file format"); 125- rc = SQLITE_ERROR; 126+ rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;" 127 goto initone_error_out; 128 } 129 130@@ -124817,9 +124837,9 @@ 131 #endif 132 133 #ifdef SQLITE_ENABLE_FTS3 134- if( !db->mallocFailed && rc==SQLITE_OK ){ 135- rc = sqlite3Fts3Init(db); 136- } 137+ if( !db->mallocFailed && rc==SQLITE_OK ){ 138+ rc = sqlite3Fts3Init(db); 139+ } 140 #endif 141 142 #ifdef SQLITE_ENABLE_ICU 143@@ -130716,16 +130736,28 @@ 144 ** module with sqlite. 145 */ 146 if( SQLITE_OK==rc 147+#ifndef ANDROID /* fts3_tokenizer disabled for security reasons */ 148 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer")) 149+#endif 150 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1)) 151 && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1)) 152 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1)) 153 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2)) 154 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1)) 155 ){ 156+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS 157+ rc = sqlite3_create_module_v2( 158+ db, "fts1", &fts3Module, (void *)pHash, 0 159+ ); 160+ if(rc) return rc; 161+ rc = sqlite3_create_module_v2( 162+ db, "fts2", &fts3Module, (void *)pHash, 0 163+ ); 164+ if(rc) return rc; 165+#endif 166 rc = sqlite3_create_module_v2( 167 db, "fts3", &fts3Module, (void *)pHash, hashDestroy 168- ); 169+ ); 170 if( rc==SQLITE_OK ){ 171 rc = sqlite3_create_module_v2( 172 db, "fts4", &fts3Module, (void *)pHash, 0 173