1diff -r -u -d orig/shell.c ./shell.c
2--- orig/shell.c	2015-06-12 15:32:23.260341869 -0700
3+++ ./shell.c	2015-06-12 15:33:39.024707940 -0700
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@@ -1938,6 +1944,22 @@
18                             readfileFunc, 0, 0);
19     sqlite3_create_function(p->db, "writefile", 2, SQLITE_UTF8, 0,
20                             writefileFunc, 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	2015-06-12 15:32:23.828344614 -0700
42+++ ./sqlite3.c	2015-06-12 15:33:39.048708056 -0700
43@@ -25292,6 +25292,13 @@
44 */
45 #if SQLITE_OS_UNIX              /* This file is used on unix only */
46
47+/* Use posix_fallocate() if it is available
48+*/
49+#if !defined(HAVE_POSIX_FALLOCATE) \
50+      && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L)
51+# define HAVE_POSIX_FALLOCATE 1
52+#endif
53+
54 /*
55 ** There are various methods for file locking used for concurrency
56 ** control:
57@@ -25846,7 +25853,12 @@
58 #else
59   { "pread64",      (sqlite3_syscall_ptr)0,          0  },
60 #endif
61+#ifdef ANDROID
62+// Bionic defines pread64 using off64_t rather than off_t.
63+#define osPread64   ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
64+#else
65 #define osPread64   ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
66+#endif
67
68   { "write",        (sqlite3_syscall_ptr)write,      0  },
69 #define osWrite     ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
70@@ -25864,8 +25876,14 @@
71 #else
72   { "pwrite64",     (sqlite3_syscall_ptr)0,          0  },
73 #endif
74+#ifdef ANDROID
75+// Bionic defines pwrite64 using off64_t rather than off_t.
76+#define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off64_t))\
77+                    aSyscall[13].pCurrent)
78+#else
79 #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off_t))\
80                     aSyscall[13].pCurrent)
81+#endif
82
83   { "fchmod",       (sqlite3_syscall_ptr)fchmod,     0  },
84 #define osFchmod    ((int(*)(int,mode_t))aSyscall[14].pCurrent)
85@@ -29115,7 +29133,7 @@
86   SimulateIOError( rc=1 );
87   if( rc!=0 ){
88     storeLastErrno((unixFile*)id, errno);
89-    return SQLITE_IOERR_FSTAT;
90+    return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
91   }
92   *pSize = buf.st_size;
93
94@@ -29151,7 +29169,7 @@
95     struct stat buf;              /* Used to hold return values of fstat() */
96
97     if( osFstat(pFile->h, &buf) ){
98-      return SQLITE_IOERR_FSTAT;
99+      return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
100     }
101
102     nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
103@@ -29736,7 +29754,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@@ -31082,7 +31100,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@@ -105877,7 +105895,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@@ -130850,9 +130868,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@@ -136910,16 +136928,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