我是新手,你做过任何项目的例子吗?
这是我的代码:
这会在访问数据时抛出错误
function createDB(){
mui.alert('create');
db = window.sqlitePlugin.openDatabase({name: 'my.db', location: 'default'}, requestSQL('User'), errorcb);
mui.alert('pase');
function successcb(){
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS MyTable');
tx.executeSql('CREATE TABLE MyTable (SampleColumn)');
mui.alert('cree tabla');
tx.executeSql('INSERT INTO MyTable VALUES (?)', ['test-value'], function(tx, resultSet) {
mui.alert('resultSet.insertId: ' + resultSet.insertId);
mui.alert('resultSet.rowsAffected: ' + resultSet.rowsAffected);
}, function(tx, error) {
mui.alert('INSERT error: ' + error.message);
});
}, function(error) {
mui.alert('transaction error: ' + error.message);
}, function() {
mui.alert('transaction ok');
});
}
function errorcb(error){
mui.alert('SELECT error: ' + error.message);
}
db.executeSql("SELECT SampleColumn FROM MyTable", [], function (resultSet) {
mui.alert('got stringlength: ' + resultSet.rows.item(0).SampleColumn);
}, function(error) {
mui.alert('SELECT error: ' + error.message);
});
}