8
Guys, I have a little problem... I’m making an application and I’m using the sqlite on android to save a copy of my database, so far it’s okay, is working, is copying the data the only problem I found is the following.
To make it clearer I’m putting the snippet of my code that "populates" my sqlite database.
var _db;
var DataBase = {
url : 'http://192.168.1.26:9075/',
//construtor
init: function(){
try{
_db = window.sqlitePlugin.openDatabase(
{
name: "Banco29.db",
location: 0 //1
});
}catch(e){
Funcoes.alerta(e,'Erro');
}
},
popularTabela: function(tbl,unidade){
var nome = tbl.split('.');
myApp.showPreloader('Atualizando a tabela: '+nome[1]+ ', Isso pode levar alguns minutos, não feche o aplicativo');
console.log("Populando: "+tbl);
$.ajax({
type: "GET",
url: DataBase.url+"procDataBase.php?acao=PopularDados&tabela="+tbl+"&unidade="+unidade,
complete:function(){
// myApp.hidePreloader();
},
success: function (json) {
var json = JSON.parse(json);
if(json.result == true){
var tamanho = json.dados.length;
//if(nome[1] === 'ocupacao'){ console.log(JSON.stringify(json)); }
for (var i = 0; i < tamanho; i++) {
if(json.dados[i] !== null && json.dados[i] !== 'null' && typeof(json.dados[i]) !== 'object'){
//console.log(json.dados[i]);
_db.executeSql(json.dados[i], [], function (tx, res){
}, function (t,e){
Funcoes.alerta('Error: '+nome[1]+' '+e.message,'Aviso');
});
}
};
}
myApp.hidePreloader();
},error: function(){
Funcoes.alerta('Erro para atualizar tabela: '+nome[1]+ ' atualize manualmente a mesma.','Erro');
myApp.hidePreloader();
}
},"json");
}
}
I make a requisition $.ajax
on my server and it returns me an array of Insert, these Insert are the data I am copying from my online database, have table for example that has 5 thousand records, here that enters the problem, at the time that starts a request $.ajax
i place a "loading" message displaying for the user and within the "success" function of the $.ajax
I put it to enter the query that my request returned and in the end I put to hide the message myApp.hidePreloader();
, and here is my problem, at the time the request with the server ends it already hides the Loading message but the application keeps working and inserting the query, logically it should hide the loading message only after it finishes all the processes isn’t it?
And my problem is being at this point, because I need the message only "hide" after finishing, as said has a table that has 5 thousand records and until finished inserting the application gets stuck and the person can not move.
I appreciate the help.
Take a look at my post http://answall.com/questions/84194/chain-de-requisi%C3%A7%C3%B5es-ass%C3%Adncronas
– NilsonUehara
I may be wrong, but I think you’re making your app a little insecure. Even as a mobile app, there’s debugging via Chrome://Inspect and anyone will be able to see the requests being made, so know exactly how your database works and even change data manually. I advise you to save only trivial data and not an entire table to the customer
– LF Ziron
Also what other suggestion do you have to improve security? Thanks for the tip!
– Crazy