我正在尝试创建一个Sqlite数据库,然后创建一个包含一列的表并插入,从中读取值。我已经从CLI添加了用于Cordova的sqlite插件,我可以在插件下看到com.brodysoft.sqlitePlugin
section.Now on onDeviceReady
我正在尝试创建数据库。这就是代码..
function onDeviceReady() {
var databaseName = "techDB";
var databaseVersion = "1.0";
var databaseDisplayName = "TTDatabase";
var databaseSize = 25;
var myDB = "";
//Accessing with HTML5 local database
myDB = window.openDatabase(databaseName, databaseVersion , databaseDisplayName, databaseSize);
//Using SQLite plugin
myDB = window.sqlitePlugin.openDatabase({name : databaseName});
}
并且在按钮上单击“我正在尝试使用相应的功能名称执行操作”。
创建表
function CreateMobileTable() {
myDB.transaction(function(transaction) {
transaction.executeSql('CREATE ' +
'TABLE IF NOT EXISTS ' +
'Mobile_Table (device_PhoneNumber integer)', [],
function(tx, result) {
alert("Mobile_Table created successfully.");
},
function(error) {
alert("Error occurred while creating the table.");
});
});
}
插入数据。
function InsertMobileData(){
myDB.transaction(function(transaction) {
// Define insert query
var executeQuery = "INSERT INTO " +
"Mobile_Table" +
"(device_PhoneNumber) "+
"VALUES(?)";
Helper.log(executeQuery);
transaction.executeSql(executeQuery, ['+callingNo+']
, function(tx, result) { // On success
alert("Mobile Number Inserted Successfully");
},
function(error){ // On error
alert("Error while inserting data");
});
});
}
});
和读表数据
function GetMobileNumber() {
myDB.transaction(function(transaction) {
transaction.executeSql("SELECT device_PhoneNumber FROM Mobile_Table WHERE business_id =?", ['1234'],
function(tx, result) {
var dataLength = result.rows.length;
console.log(dataLength);
if(dataLength > 0){
var no = result.rows.item(0).business_name;
alert(no);
}else{
alert("No Result Found");
}
},
function(error) {
alert("Error while fetching the data");
});
});
}
问题是,我无法创建数据库,无法获取任何警报消息..此外,我的应用程序的其他功能也无法正常工作... 请帮帮我..谢谢..