SQLite Android Bindings
Check-in [87449ff921]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a dummy version (equivalent to BINARY) of collation sequence LOCALIZED to all new database handles. Now a simple "SELECT sqlite_version()" works.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 87449ff92154151a203dafa06dfb62b3b70d0b5f
User & Date: dan 2013-12-18 18:04:57
Context
2013-12-18
18:18
Remove unused file JniInvocation.cpp. check-in: b23d835f18 user: dan tags: trunk
18:04
Add a dummy version (equivalent to BINARY) of collation sequence LOCALIZED to all new database handles. Now a simple "SELECT sqlite_version()" works. check-in: 87449ff921 user: dan tags: trunk
17:36
Update CustomSqlite.java to call "SELECT sqlite_version()". check-in: 71a3449ef6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to jni/android_database_SQLiteConnection.cpp.

   110    110   
   111    111   // Called after each SQLite VM instruction when cancelation is enabled.
   112    112   static int sqliteProgressHandlerCallback(void* data) {
   113    113       SQLiteConnection* connection = static_cast<SQLiteConnection*>(data);
   114    114       return connection->canceled;
   115    115   }
   116    116   
          117  +/*
          118  +** This function is a collation sequence callback equivalent to the built-in
          119  +** BINARY sequence. 
          120  +**
          121  +** Stock Android uses a modified version of sqlite3.c that calls out to a module
          122  +** named "sqlite3_android" to add extra built-in collations and functions to
          123  +** all database handles. Specifically, collation sequence "LOCALIZED". For now,
          124  +** this module does not include sqlite3_android (since it is difficult to build
          125  +** with the NDK only). Instead, this function is registered as "LOCALIZED" for all
          126  +** new database handles. 
          127  +*/
          128  +static int coll_localized(
          129  +  void *not_used,
          130  +  int nKey1, const void *pKey1,
          131  +  int nKey2, const void *pKey2
          132  +){
          133  +  int rc, n;
          134  +  n = nKey1<nKey2 ? nKey1 : nKey2;
          135  +  rc = memcmp(pKey1, pKey2, n);
          136  +  if( rc==0 ){
          137  +    rc = nKey1 - nKey2;
          138  +  }
          139  +  return rc;
          140  +}
   117    141   
   118    142   static jint nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlags,
   119    143           jstring labelStr, jboolean enableTrace, jboolean enableProfile) {
   120    144       int sqliteFlags;
   121    145       if (openFlags & SQLiteConnection::CREATE_IF_NECESSARY) {
   122    146           sqliteFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
   123    147       } else if (openFlags & SQLiteConnection::OPEN_READONLY) {
................................................................................
   135    159       env->ReleaseStringUTFChars(labelStr, labelChars);
   136    160   
   137    161       sqlite3* db;
   138    162       int err = sqlite3_open_v2(path.c_str(), &db, sqliteFlags, NULL);
   139    163       if (err != SQLITE_OK) {
   140    164           throw_sqlite3_exception_errcode(env, err, "Could not open database");
   141    165           return 0;
          166  +    }
          167  +    err = sqlite3_create_collation(db, "localized", SQLITE_UTF8, 0, coll_localized);
          168  +    if (err != SQLITE_OK) {
          169  +        throw_sqlite3_exception_errcode(env, err, "Could not register collation");
          170  +        sqlite3_close(db);
          171  +        return 0;
   142    172       }
   143    173   
   144    174       // Check that the database is really read/write when that is what we asked for.
   145    175       if ((sqliteFlags & SQLITE_OPEN_READWRITE) && sqlite3_db_readonly(db, NULL)) {
   146    176           throw_sqlite3_exception(env, db, "Could not open the database in read/write mode.");
   147    177           sqlite3_close(db);
   148    178           return 0;