1diff -r -u -d orig/shell.c ./shell.c
2--- orig/shell.c	2017-07-21 09:46:53.488326209 +0900
3+++ ./shell.c	2017-07-21 09:46:53.620324492 +0900
4@@ -52,6 +52,12 @@
5 #endif
6 #include <ctype.h>
7 #include <stdarg.h>
8+// Begin Android Add
9+#ifndef NO_ANDROID_FUNCS
10+#include "IcuUtils.h"
11+#include <sqlite3_android.h>
12+#endif
13+// End Android Add
14 
15 #if !defined(_WIN32) && !defined(WIN32)
16 # include <signal.h>
17@@ -3509,6 +3515,22 @@
18                             sha3QueryFunc, 0, 0);
19     sqlite3_create_function(p->db, "sha3_query", 2, SQLITE_UTF8, 0,
20                             sha3QueryFunc, 0, 0);
21+
22+    // Begin Android Add
23+    #ifndef NO_ANDROID_FUNCS
24+        InitializeIcuOrDie();
25+        int err = register_localized_collators(p->db, "en_US", 0);
26+        if (err != SQLITE_OK) {
27+          fprintf(stderr, "register_localized_collators() failed\n");
28+          exit(1);
29+        }
30+        err = register_android_functions(p->db, 0);
31+        if (err != SQLITE_OK) {
32+          fprintf(stderr, "register_android_functions() failed\n");
33+          exit(1);
34+        }
35+    #endif
36+    // End Android Add
37   }
38 }
39 
40diff -r -u -d orig/sqlite3.c ./sqlite3.c
41--- orig/sqlite3.c	2017-08-04 10:42:31.294648222 +0900
42+++ ./sqlite3.c	2017-08-10 13:27:29.784569745 +0900
43@@ -33618,7 +33618,7 @@
44   SimulateIOError( rc=1 );
45   if( rc!=0 ){
46     storeLastErrno((unixFile*)id, errno);
47-    return SQLITE_IOERR_FSTAT;
48+    return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
49   }
50   *pSize = buf.st_size;
51 
52@@ -33654,7 +33654,7 @@
53     struct stat buf;              /* Used to hold return values of fstat() */
54    
55     if( osFstat(pFile->h, &buf) ){
56-      return SQLITE_IOERR_FSTAT;
57+      return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
58     }
59 
60     nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
61@@ -34262,7 +34262,7 @@
62     ** with the same permissions.
63     */
64     if( osFstat(pDbFd->h, &sStat) ){
65-      rc = SQLITE_IOERR_FSTAT;
66+      rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
67       goto shm_open_err;
68     }
69 
70@@ -116120,7 +116120,7 @@
71   }
72   if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
73     sqlite3SetString(pzErrMsg, db, "unsupported file format");
74-    rc = SQLITE_ERROR;
75+    rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
76     goto initone_error_out;
77   }
78 
79@@ -149914,13 +149914,25 @@
80   ** module with sqlite.
81   */
82   if( SQLITE_OK==rc 
83+#ifndef ANDROID    /* fts3_tokenizer disabled for security reasons */
84    && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
85+#endif
86    && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
87    && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
88    && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
89    && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2))
90    && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
91   ){
92+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
93+    rc = sqlite3_create_module_v2(
94+        db, "fts1", &fts3Module, (void *)pHash, 0
95+        );
96+    if(rc) return rc;
97+    rc = sqlite3_create_module_v2(
98+        db, "fts2", &fts3Module, (void *)pHash, 0
99+        );
100+    if(rc) return rc;
101+#endif
102     rc = sqlite3_create_module_v2(
103         db, "fts3", &fts3Module, (void *)pHash, hashDestroy
104     );
105