brianleroux/lawnchair

webkit-sqlite with 2 collections/lawnchairs on Phonegap Android not possible

pwntr opened this issue · 2 comments

I ran into a nasty problem with Lawnchair 0.6.1, downloaded straight from the website. I want to have 2 globally accessible collections/Lawnchairs, both with the webkit-sqlite adapter. This is how I declare them, after loading Lawnchair and the adapter:

var clientStore = Lawnchair({name: 'clients'}, function () {});
var companyStore = Lawnchair({name: 'companies'}, function () {});
// other global variables
...

In Safari and Chrome on my desktop everything is smooth sailing, same for my iPad and other iOS devices in the emulator using Phonegap (3.0.0). No problems at all, both databases show up in the web inspector and in Weinre. I can use them in any of my JQuery Mobile events (version 1.3.2 and 1.4.0 beta). Manually checking the database objects in Weinre confirms that they are indeed using the webkit-sqlite adapter.

But if run the Phonegap app on Android (4.3 on a Galaxy S4 Google Play Edition, 4.2.2 in the emulator), only the clientStore is accessible and usable. Trying to access the companyStore gives me the following error:

companyStore.all(function (allEntries) {
    console.log(allEntries);
...
> TypeError: Cannot call method 'all' of undefined

The only database that shows up in Weinre on the Android device is the clients database. Manually initializing the companies database from the Weinre inspector console after everything loaded up doesn't show any effect on the list of databases on the 'Resources' tab or change anything else (except for the above error "visually disappearing"). Changing it around only enables me to create the companyStore, so in essence I can only have one store/lawnchair at a time.

Trying to access the 'undefined' companyStore programmatically, say when someone switches to a page where all the companies shall be listed, 'crashes' the UI on the Android device. Nothing even gets printed on the console anymore after that, but I can still use weinre to play around on the device. As said, all other platforms work just fine.

Am I just doing something stupidly wrong or did I encounter a bug/feature?

Using the standard DOM adapter works for me on every platform so far. I guess I'll stick to that one for now (the size limit of that is a bummer though, but that's by design).

The problem can also be found and answered on stackoverflow: http://stackoverflow.com/questions/19148723/lawnchair-storage-with-2-collections-on-phonegap-android

P.S.: thanks so much for all your work on lawnchair, phonegap and the like :)!

Hi,

0.6.1 is a bit old, have you tried trunk? There are quire a few improvements to the sqlite adapter there.

Hm, I blindly relied on the assumption the website would have the latest release... Thanks for pointing me to the trunk. I just tried trunk (master), the makefile still says 0.6.1 but somewhere down the repo I saw 0.6.3 pop up, what's up with that? Anyway, I included 'dom' and 'webkit-sqlite' in the minified file (adjusted the makefile's primary and secondary adapter), ran make and make release, tried it out, and got the same error and behavior. What's different though is the layout of the created tables in web inspector under Web SQL (both on desktop and mobile).

The dom adapter still works fine everywhere with multiple lawnchairs. webkit-sqlite works only on desktop and iOS with multiple lawnchairs, Android seems to be limited to 1 webkit-sqlite lawnchair at a time.