当在角度工厂中调用opendatabase时,它会导致security_err dom异常18错误

时间:2022-06-28 19:02:38

I am developing Angularjs app in vs2015. I want to open database in websql through factory function. While testing app in ripple emulator it works perfectly(also works perfectly in android OS version 4.4 and higher) but while testing app in android OS version 4.2 and lower it throws security_err dom exception 18. One more strange is that when same database, I open in simple java script file it works perfectly in ripple and in all devices also.

我在vs2015开发Angularjs应用。我想通过factory函数在websql中打开数据库。在ripple模拟器中测试应用程序时,它工作得很好(在android OS版本4.4及更高版本中也很好),但在android OS版本4.2中测试应用程序时,它抛出了security_err dom异常18。更奇怪的是,当我在简单的java脚本文件中打开同一个数据库时,它在ripple和所有设备中都能完美地工作。

Here is my factory code :

这是我的工厂代码:

angular.module('InnkeyAlert.services', ['InnkeyAlert.config'])

// DB wrapper

.factory('DB', function ($q, DB_CONFIG) {

try {
    var self = this;
    self.db = null;

    self.init = function () {
        alert("DB init start!");
        // Use self.db = window.sqlitePlugin.openDatabase({name: DB_CONFIG.name}); in production
        self.db = window.openDatabase(DB_CONFIG.name, '1.0', 'database', -1);
        alert("DB open!");
        angular.forEach(DB_CONFIG.tables, function (table) {
            var columns = [];

            angular.forEach(table.columns, function (column) {
                columns.push(column.name + ' ' + column.type);
            });

            var query = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + columns.join(',') + ')';
            self.query(query);
            //console.log('Table ' + table.name + ' initialized');
        });
        alert("table created !");
    };

    return self;

} catch (e) {
    //alert("Db factory: "+e.message);
}

})

Here is my index.js file code :

这是我的指数。js文件代码:

    var app = {

        // Application Constructor
        initialize: function () {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function () {
            alert("hi");
            document.addEventListener('deviceready', this.onDeviceReady, false);        
        },

        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicitly call 'app.receivedEvent(...);'
        onDeviceReady: function () {
            app.receivedEvent('deviceready');
            alert("Device ready end...");
            try {
                angular.injector(['InnkeyAlert']).get('DB').init();
                alert("inti db called...");
            } catch (e) {
                alert("index 101: " + e.message);
            }
        },
        // Update DOM on a Received Event
        receivedEvent: function (id) {

        }
    };

1 个解决方案

#1


0  

That's a problem in Android versions lower than 4.4. It has been answered here:

在低于4.4的Android版本中,这是一个问题。有人回答说:

You can use Web SQL from a file:// URL in WebView. The Cordova folks managed to do it. There are just three things you must do:

您可以在WebView中使用来自文件:// URL的Web SQL。科尔多瓦的人设法做到了。只有三件事你必须做:

1) Call setDatabaseEnabled() (duh):

1)调用setDatabaseEnabled()(咄):

2) Set the database file path. Yes, this is deprecated in Android 4.4, but it is required if you want to avoid the DOM Exception 18 in pre-Kitkat:

2)设置数据库文件路径。是的,这在Android 4.4中是不赞成的,但是如果您想避免在kitkat之前出现的DOM异常18,就必须这样做:

3) Set the onExceededDatabaseQuota handler. Yes, it's deprecated in Android 4.4, blah blah blah.

3)设置onExceededDatabaseQuota处理器。是的,Android 4.4已经弃用了,等等。

#1


0  

That's a problem in Android versions lower than 4.4. It has been answered here:

在低于4.4的Android版本中,这是一个问题。有人回答说:

You can use Web SQL from a file:// URL in WebView. The Cordova folks managed to do it. There are just three things you must do:

您可以在WebView中使用来自文件:// URL的Web SQL。科尔多瓦的人设法做到了。只有三件事你必须做:

1) Call setDatabaseEnabled() (duh):

1)调用setDatabaseEnabled()(咄):

2) Set the database file path. Yes, this is deprecated in Android 4.4, but it is required if you want to avoid the DOM Exception 18 in pre-Kitkat:

2)设置数据库文件路径。是的,这在Android 4.4中是不赞成的,但是如果您想避免在kitkat之前出现的DOM异常18,就必须这样做:

3) Set the onExceededDatabaseQuota handler. Yes, it's deprecated in Android 4.4, blah blah blah.

3)设置onExceededDatabaseQuota处理器。是的,Android 4.4已经弃用了,等等。