3

I'm using Sencha Touch 2.0.1 and am trying to open a SQLite Database using:

var db = window.openDatabase("mydatabase", "1.0", "mydatabase", 2000000);

On the iPhone/IOS Simulator this works. On an Android device or emulator I get an exception:

TypeError: Object[object DOMWindow] has no method 'openDatabase'

I'm using Sencha to build native apps (though am rapidly losing faith...) so am not using PhoneGap.

Sencha's packaging creates and AndroidManifest.xml file but I can't see permissions set for

android.permission.WRITE_EXTERNAL_STORAGE

I'm not sure if this is the problem though!

Any help greatly appreciated as this is driving me quietly nuts.

Edit: Here's the JS - it's part of a Sencha Touch generated app:

Ext.application({
name: 'MyApp',

requires: [
    'Ext.MessageBox'
],

views: ['Main'],

icon: {
    '57': 'resources/icons/Icon.png',
    '72': 'resources/icons/Icon~ipad.png',
    '114': 'resources/icons/Icon@2x.png',
    '144': 'resources/icons/Icon~ipad@2x.png'
},

isIconPrecomposed: true,

startupImage: {
    '320x460': 'resources/startup/320x460.jpg',
    '640x920': 'resources/startup/640x920.png',
    '768x1004': 'resources/startup/768x1004.png',
    '748x1024': 'resources/startup/748x1024.png',
    '1536x2008': 'resources/startup/1536x2008.png',
    '1496x2048': 'resources/startup/1496x2048.png'
},

launch: function() {
    // Destroy the #appLoadingIndicator element
    Ext.fly('appLoadingIndicator').destroy();

    // Initialize the main view
    Ext.Viewport.add(Ext.create('MyApp.view.Main'));
    //

    try {

        var db = window.openDatabase("mydatabase", "1.0", "mydatabase", 2000000);

        if ( !db ) {
            var m3 = new Ext.MessageBox(); 
            m3.alert("db test!", "openDatabase failed!");

        } else {
           var m3 = new Ext.MessageBox(); 
           m3.alert("db test!", "openDatabase ok!");
        }
    }
    catch(err){

        var m2 = new Ext.MessageBox(); 
        m2.alert("db test!", "exception caught: " + err.name + ":" + err.message);


    }

}

});

MattD
  • 73
  • 2
  • 6
  • does this question help? http://stackoverflow.com/questions/2474475/how-do-i-call-window-opendatabase-from-a-webview-hosted-in-an-android-applicatio/2474524#2474524 – gsb Jul 23 '12 at 19:04
  • I saw this but assumed it was Java rather than Javascript (WebSettings settings = myWebView.getSettings(); ). – MattD Jul 23 '12 at 19:32
  • @Nerd this would explain why his DB calls would be blocked, but not why `openDatabase` doesn't even exist. – jbabey Jul 23 '12 at 19:38
  • i feel the error is with the `context` that is being referenced. could you post your JS if you can? – gsb Jul 23 '12 at 20:50
  • I've added the code snippet - it's part of a wider sencha touch generated app (the openDatabase call is my addition). – MattD Jul 25 '12 at 18:59

1 Answers1

1

Doesn't look like it's available on your environment. Here's a simple way to check:

if (window.openDatabase) {
    // available
} else {
    // not available
}

Offline SQL is currently available in Safari, Google Chrome, on the iPhone and Palm’s WebOS (both for its applications and browser-based content).

http://creativepark.net/1191

jbabey
  • 45,965
  • 12
  • 71
  • 94
  • If I run the app in the browser (Chrome) it's ok (as in it can open the database). I'm pretty certain that sqlite is available in Android - I think the problem is more around Sencha. – MattD Jul 23 '12 at 19:36