在模拟器上工作的SQLite命令不在设备上

时间:2013-12-25 10:06:18

标签: android cordova

我正在运行一个应用程序,通过使用sql lite并完美运行,可以将一些细节保存到数据库中 但是当我在我的三星galaxy s2上运行它时,任何数据库查询都没有执行 我不知道这个问题是什么...请帮帮忙

// Query the database
//
function queryDB_once(tx) { 
    tx
    .executeSql('CREATE TABLE IF NOT EXISTS users (id integer primary key, name text, email text, mobile integer, sex text, center text, city text)');

    tx.executeSql('select * FROM users', [], querySuccess_once, errorCB);
}

// Query the database
//
function queryDB(tx) {
    alert("users query execute");
    tx.executeSql('select * FROM users', [], querySuccess, errorCB);
}

// Query the success callback
//
function querySuccess_once(tx, results) {
    var name, email, mobile, sex, center, city;
    var len = results.rows.length;
    console.log("LENGTH of Users DB for first Time Visit:" + len);

    if (len == 0) {
        // do something
        window.location = "resources/pages/registereduser.html";
        alert("Welcome! You are a new User");
    } else {
        console.log("Your profile already activated, so enjoy app");
    }
}

// Query the success callback
//
function querySuccess(tx, results) {
    var name, email, mobile, sex, center, city;
    var len = results.rows.length;
    alert("GETTING DB LENGTH:" + len);
    if (len == 0) {
        // do something
        alert("LENGTH: IS NULL OR ZERO: "+len);

    } else {
        alert("Data will be refresh");
        console.log("TABLE: " + len + " rows found.");
        for ( var i = 0; i < len; i++) {
            name = results.rows.item(i).name;
            email = results.rows.item(i).email;
            sex = results.rows.item(i).sex;
            mobile = results.rows.item(i).mobile;
            city = results.rows.item(i).city;
            center = results.rows.item(i).center;
            console.log("Name: "+ name + " EMAIL: " + email + " city: " + city
                    + " MOBILE: " + mobile + " SEX: " + sex+ " CENTER: "+center);
            document.getElementById('name').value = name;
            document.getElementById('email').value = email;
            document.getElementById('sex').value = sex;
            document.getElementById('mobile').value = mobile;
            document.getElementById('city').value = city;
            document.getElementById('center').value = center;
            $("#sex").selectmenu('refresh', true);
            $("#center").selectmenu('refresh', true);

        }
    }

}

// Transaction error callback
//
function errorCB(err) {
    console.log("Error processing SQL: " + err.code);
}

// Wait for device API libraries to load

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

// device APIs are available

// function onDeviceReady() {
// alert("VIP GREAT");
// var db = window.openDatabase("aakash_db", "1.0", "Aakash Database",
// 1000000);
// db.transaction(populateDB, errorCB, successCB);
// }
// Populate the database

// function populateDB(tx) {
// tx.executeSql('DROP TABLE IF EXISTS users');
// tx
// .executeSql('CREATE TABLE IF NOT EXISTS users (id integer primary key, name,
// email, mobile, sex, city)');
// tx
// .executeSql('INSERT INTO users (name, email, mobile, sex, city) VALUES
// ("vipin", "mr.vipintyagi@gmail.com", 7503473012,"male","Ghaziabad")');
// tx
// .executeSql('INSERT INTO users (name, email, mobile, sex, city) VALUES
// ("rahul", "vipin.mgr@gmail.com", 98343748324,"male","hapur")');
//
// }

// Transaction error callback
//
function errorCB(tx, err) {
    alert("Error processing SQL: " + err);
}

// Transaction success callback
//
function successCB() {
    console.log("success!");
}

// this method is for 1st time used for if user has no database
function checkingExistsData() {
console.log("Checking Existing Data");
    var db = window
            .openDatabase("aakash_db", "1.0", "Aakash Database", 1000000);
    db.transaction(queryDB_once, errorCB, successCB);
}

// getting data for profile page
function checkingExistingData() {
    var url = window.location.href;

    alert("You are redirected to profile");
//  if (index == null) {
        var db = window.openDatabase("aakash_db", "1.0", "Aakash Database",
                1000000);
        db.transaction(queryDB, errorCB, successCB);
}

1 个答案:

答案 0 :(得分:0)

您是否在清单中添加了权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />