Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Feature request: NO_LOCALIZED_COLLATORS on Android

I have an app that downloads an sqlite database from the web, places it in the databases directory then loads it via Titanium's database API. This works fine on iPhone, but fails on Android because a special table android_meta is missing.

It looks like the DB load would not fail if the special constant NO_LOCALIZED_COLLATORS were passed in to the open call. From the docs:

public static final int NO_LOCALIZED_COLLATORS

Since: API Level 1
Flag for openDatabase(String, SQLiteDatabase.CursorFactory, int) to open the database without support for localized collators.
This causes the collator LOCALIZED not to be created. You must be consistent when using this flag to use the setting the database was created with. If this is set, setLocale(Locale) will do nothing.
Constant Value: 16 (0x00000010)

Please consider adding a flag to the Database.open() call so we can open externally fetched databases in the future.

Edit: here is a patch which makes it the default, for anyone interested.

diff --git a/android/modules/database/src/ti/modules/titanium/database/DatabaseModule.java b/android/modules/database/src/ti/modules/titanium/database/DatabaseModule.java
index 918eb50..8b10e75 100644
--- a/android/modules/database/src/ti/modules/titanium/database/DatabaseModule.java
+++ b/android/modules/database/src/ti/modules/titanium/database/DatabaseModule.java
@@ -36,9 +36,15 @@ public class DatabaseModule extends TiModule

     public TiDatabaseProxy open(String name) {
         TiDatabaseProxy dbp = null;
+                Context ctx = getTiContext().getTiApp();
+                File dbPath = ctx.getDatabasePath(name);

         try {
-            SQLiteDatabase db = getTiContext().getTiApp().openOrCreateDatabase(name, Context.MODE_PRIVATE, null);
+            SQLiteDatabase db =
+                            SQLiteDatabase.openDatabase(dbPath.getPath(),
+                                                        null,
+                                                        SQLiteDatabase.NO_LOCALIZED_COLLATORS |
+                                                        SQLiteDatabase.CREATE_IF_NECESSARY);
             if (DBG) {
                 Log.d(LCAT, "Opened database: " + name);
             }
— asked May 3rd 2010 by Damien Elmes
  • android
  • database
0 Comments

2 Answers

  • Actually, this doesn't seem to be necessary. I was trying to open a corrupted file, and the trace message complained about the android_meta table being missing so the database would be closed. But when I replaced it with a non-corrupt file, I found that the existing code works fine - so there is no need for this patch.

    (the reason I thought it was working on iPhone is because ".sql" is appended to DBs on that platform, and I had another file shadowing the one I wanted)

    — answered May 3rd 2010 by Damien Elmes
    permalink
    0 Comments
  • Glad it worked.

    — answered May 3rd 2010 by Don Thorp
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.