Android & Database.readTransaction

I have learned that a SqlLite Database.readTransaction is just not working on Android. If you rely heavily on databases like my app does, it's a big problem. So, you have to use Database.transaction.

I did not however want to lose the slight boost of readTransaction for those that support it, so I found a way around the problem:

	FlashCards.Database = window.openDatabase("FlashCards", "1.0", "FlashCards Database",500000);

	if (FlashCards.fetchAppInfo.os == "android"){
		FlashCards.Database.safeTransaction = FlashCards.Database.transaction;
		FlashCards.Database.safeTransaction = FlashCards.Database.readTransaction;
FlashCards.fetchAppInfo.os is my personal way of configuring the OS deployment. I had to store the transaction object inside the Database namespace in order for it to work (FlashCards.safeTransaction throws Illegal invocation error).

Then I just did a global find/replace on FlashCards.Database.readTransaction to change it to FlashCards.Database.safeTransaction.

Credit goes to Philip Davis for realizing it needs to be in the Database namespace.


  • About how much of a benefit do you experience from using readTransaction instead of just transaction?
  • BTW, you should really log this bug at -- I didn't see any readTransaction-related bugs in their DB right now. If it also occurs in the browser, the appropriate bug tracker is
  • @GlitchTech, not too much of a performance boost on most devices. I did see a good performance spike back on the old Pre when I started using it. Since then, I kept using it. On devices like iPad and such, it's not so much a bout speed but minimizing resources. Already getting memory warnings.

    @unwiredben Had not tested in the Android browser, but it seems to work fine. Looks like an issue with PhoneGap or the webview it's using. I'll do some more testing and get a good bug report ready.
  • Thanks erupnu. I will look into adding that into my app then. I get some nasty performance at times with the 1.0 virtual list & repeated DB calls.
  • edited February 2012
    I'm seeing this, not using Database, commented out all references to localStorage as well. Something in Phonegap is throwing an error. Using Phonegap 1.3.0 and Enyo 2.0b, Android 2.2 & 3.x. I get this:
    02-08 21:47:59.101: I/SqliteDatabaseCpp(376): 
    sqlite returned: error code = 14, msg = cannot open file at line 27603 
    of [a586a4deeb], db=/data/data/com.translunardesigns.amtrak/databases/webview.db
    But I'm still confused, not using WebView or Database at this point.
  • You can safely ignore that error.
Sign In or Register to comment.