I'm creating an object with onDeviceReady
to create the connection to the application's SQLite database. It is being created as follows:
var app = {
initialize: function() {
this.bindEvents();
this.db = null;
},
...
onDeviceReady: function() {
app.db = window.sqlitePlugin.openDatabase({name:'4routes'});
...
However, there is a method called insertDailyServices
which is responsible for storing the information in the database and it is returning error.
insertDailyServices: function(service) {
app.db.transaction(function(tx){
tx.executeSql('INSERT INTO file_servico (id_servico,id_os,id_fornecedor,id_motorista,id_veiculo,origem,destino,inicio,termino,created_at) VALUES (?,?,?,?,?,?,?,?,?,?)',
[service.id_servico,service.id_file,service.id_fornecedor,service.id_motorista,service.id_veiculo,service.origem,service.destino,service.inicio,service.termino,moment().format('YYYY-MM-DD HH:mm:ss')],
function(tx,res){
$('#listServicos').append('Serviço de N° '+service.id_servico+' registrado localmente.<br>');
});
});
}
Error Displayed
08-31 01:54:03.100: E/Web Console(31269): Uncaught TypeError: Cannot call method 'transaction' of undefined at file:///android_asset/www/js/index.js:136
Call in file:
<script type="text/javascript">
app.initialize();
app.listOpenServices();
</script>
How to solve this problem ??? I just need to pass app.db
to be read from any method within the file.