Android手机屏幕应用程序在三星Galaxy设备上存在SQlite和本地存储问题

Tay*_*man 51 javascript sql sqlite android cordova

我遇到了一个针对Android和iOS构建的PhoneGap应用程序的问题.在iOS和大多数Android设备上,除三星Galaxy S3和S4外,它的功能完美.

在第一页加载时,应用程序会创建一个本地SQL数据库.此数据库用于存储整个应用程序中的问题和答案的值.

我在三星设备上遇到的问题是,第一次运行应用程序时数据库无法正常加载,但是如果用户完全关闭应用程序并重新打开它,则会创建没有错误的数据库.由于第一页要求用户输入其年龄,然后将值存储在SQL数据库中,因此用户会得到应用程序此时已冻结的印象.

数据库的初始化代码:

的index.html

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    populateDB(); 
}
Run Code Online (Sandbox Code Playgroud)

main_js.js

function populateDB() {
    var db = window.openDatabase("Database", "1.0", "My Database", 20000);
    db.transaction(populate_DB, errorCB, successCB);
}

function populate_DB(tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS Options (ID INTEGER UNIQUE NOT NULL, Name TEXT NOT NULL, Value INTEGER NOT NULL)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS Questions (ID INTEGER UNIQUE NOT NULL, Question TEXT NOT NULL, Answer TEXT)');
    tx.executeSql('INSERT OR IGNORE INTO Options (ID, Name, Value) VALUES (1, "License", 0)');

    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (0, "Age","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (1, "two","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (2, "three","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (3, "four","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (4, "five","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (5, "six","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (6, "seven","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (7, "eigth","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (8, "nine","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (9, "ten","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (10, "eleven","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (11, "twelve","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (12, "thirteen","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (13, "fourteen","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (14, "fifteen","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (15, "sixteen","")');
    tx.executeSql('INSERT OR IGNORE INTO Questions (ID, Question, Answer) VALUES (16, "seventeen","")');
}
Run Code Online (Sandbox Code Playgroud)

age_button_pressed

function age_save() {
    var db = window.openDatabase("Database", "1.0", "My Database", 20000);
    loc = "q_sex.html";
    db.transaction(age_query, errorCB);
}

function age_query(tx) {
    var age = document.getElementById("a_age").value;
    tx.executeSql('UPDATE Questions SET Answer = "' + age + '" WHERE ID="0";', [], q_querySuccess, errorCB);
}
Run Code Online (Sandbox Code Playgroud)

之后age_button_pressed,没有任何事情发生,数据库不会更新结果.

这只是三星Galaxy S3和S4的一个问题,我想知道三星的WebKit是否与它有关?

Kyl*_*yle 1

这可能是因为您打开数据库两次。仅打开一次并在该单个实例上执行所有事务。在开始另一笔交易之前,还要确保您的上一笔交易已完成。您不必担心这一点,但根据我的经验,Cordova 的 (PhoneGap) WebSQL 有点挑剔。