mardi 6 janvier 2015

Cordova Android SQLLIteplugin.open exception

I am trying to use SQLLItePlugin for Android but its not working. I will list my steps: 1. I have installed cordova pjhonegap from phonegap. I am developing my mobile app Phonegap, html5, javascript, css3 using Netbeans as IDE. 2. Downloaded plugin from http://ift.tt/1gnjybT. 3. Added SQLitePlugin.js to js folder of project. 4. Added com.brodysoft.sqlitePlugin.file=http://ift.tt/1s13J1g in plugin.properties. 5. Am opening database on deviceready as



var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent('deviceready');
var db = window.sqlitePlugin.openDatabase('gdata.db');
console.log('ready');


db.transaction(function (tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');

// demonstrate PRAGMA:
db.executeSql("pragma table_info (test_table);", [], function (res) {
console.log("PRAGMA res: " + JSON.stringify(res));
});

tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function (tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");

db.transaction(function (tx) {
tx.executeSql("select count(id) as cnt from test_table;", [], function (tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
});

}, function (e) {
console.log("ERROR: " + e.message);
});
});



},
// Update DOM on a Received Event
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
console.log('Received Event: ' + id);
}
};
app.initialize();



  1. Running the build on android devvice directly.


It keeps on throwing the error Uncaught TypeError: Object # has no method 'exec' (13:52:13:450 | error, javascript) at SQLitePlugin.open (www/js/libs/SQLitePlugin.js:112:15) at SQLitePlugin (www/js/libs/SQLitePlugin.js:54:10) at (anonymous function) (www/js/libs/SQLitePlugin.js:425:14) at (anonymous function) (www/js/libs/SQLitePlugin.js:30:20) at createandpopulatedb (www/js/dborarray.js:30:30) at onDeviceReady3 (www/dborarray.html:96:33) at onload (www/dborarray.html:16:155) SQLitePlugin openargs: {"name":"gdataenter code here.db"} (13:52:19:609) at www/js/libs/SQLitePlugin.js:39


Can somebody help.


Aucun commentaire:

Enregistrer un commentaire