简体   繁体   English

在Android 4.4.2中使用SQLite

[英]using SQLite in android 4.4.2

I'm making an application for android using apache cordova tools for visual studio. 我正在使用用于Visual Studio的Apache Cordova工具为android编写应用程序。 But I'm facing a problem, when I execute my application on android 5.1.1+ everything works perfectly and when I run it on android 4.4.2 (can't try on lower version) there is an issue. 但是我遇到了一个问题,当我在android 5.1.1+上执行我的应用程序时,一切工作正常,而当我在android 4.4.2上运行它时(不能尝试使用较低版本),出现了问题。

I've created an app to try to resolve the problem. 我创建了一个应用来尝试解决该问题。 I start by creating the Database using : 我首先使用创建数据库:

function openDB() {
    try {
        if (!window.openDatabase) {
            $("#error").text("Not supported");
        } else {
            var shortName = 'TestDataBase20';
            var version = '1.0';
            var displayName = 'TestDataBase';
            var maxSize = 2048; // in bytes
            db = window.openDatabase(shortName, version, displayName, maxSize);

        }
    } catch (e) {
        // Error handling code goes here.
        if (e == 2) {
            // Version number mismatch.
            $("#error").text("Invalid database version.");
        } else {
            $("#error").text("Unknown error " + e + ".");
        }
        return;
    }


    createTables();
}

Then I create the table and try to retrieve the name of the table I've created : 然后创建表并尝试检索已创建表的名称:

function createTables() {
    db.transaction(
        function (transaction) {

            /* The first query causes the transaction to (intentionally) fail if the table exists. */
            transaction.executeSql('CREATE TABLE IF NOT EXISTS settings (id INTEGER PRIMARY KEY AUTOINCREMENT, login TEXT NOT NULL);', [], nullDataHandler, errorHandler);
            /*Select the name of the table called settings*/
            transaction.executeSql('SELECT name FROM sqlite_master WHERE type="table" AND name="settings";', [], initialize, errorHandler);
        },
        /*Executed if there is a problem during the execution of db.transaction*/
        function(error){
            $("#error").text(function () {
                var text = $("#error").text() + " createTables : " + error.message;
                return text;
            });
        }
    );
}

And finally I display the data retrieved : 最后,我显示检索到的数据:

function initialize(transaction, results) {

    if (results.rows.length != 0) {
        $("#result").text(function () {
            var text = $("#result").text() + " " + results.rows[0].name;
            return text;
        });
    } else {
        $("#result").text(function () {
            var text = $("#result").text() + " No elements in results";
            return text;
        });
    }
}

When I launch it on android 4.4.2 here is the error : 当我在android 4.4.2上启动它时,这是错误:

createTables : the statement callback raised an exception or statement error callback did not return false

This error comes from db.transaction in the function createTables that couldn't be executed properly. 此错误来自无法正常执行的函数createTables中的db.transaction。

I really don't understand why it works on android 5.1.1+ and not on 4.4.2(I've tried it on a smartphone and a tablet). 我真的不明白为什么它可以在android 5.1.1+而不是4.4.2上运行(我已经在智能手机和平板电脑上尝试过了)。

我已经通过使用results.rows.item(0).name而不是results.rows[0].name解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JS If语句不适用于android 4.4.2或iphone - JS If statement not working on android 4.4.2 or iphone 调试Samsung Android 4.4.2本机浏览器 - Debug Samsung Android 4.4.2 native browser React不适用于Android 4.4.2 Web视图浏览器 - React Not working on Android 4.4.2 web view browser Android 4.4.2 html文件上传正常吗? 需要解决方案而不是解决方法 - Android 4.4.2 html file upload working or not ? Need a solution not a workaround window.open事件侦听器在Android 4.4.2中不起作用 - window.open event listeners not working in Android 4.4.2 android 4.4.2的webview中的navigator.geolocation返回未定义 - navigator.geolocation in webview of android 4.4.2 returning undefined 用于Android 4.4.2股票浏览器的选择和上传文件的页面 - Webpage to choose and upload file for Android 4.4.2 stock browser 在nodeJs v4.4.2中使用ES6模板文字 - Using ES6 Template Literals in nodeJs v4.4.2 android webview可以使用JavaScript访问Android sqlite数据库内容吗? - Can android webview access the Android sqlite database content using JavaScript? React(0.14.0)/ Cordova应用在Android 4.4.2上崩溃但在Android 5+上运行时无法找到原因 - React(0.14.0)/Cordova app Crushing on Android 4.4.2 but working on Android 5+, can't figure the reason
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM