0
I am trying to create a connection to an Sqlite database created within my application and returns the following error.
SQLitePlugin.executeSql[Batch](): Error=no such table: fornecedor_motorista (code 1): ,
while compiling: INSERT INTO fornecedor_motorista
(id_fornecedor,nome,email,telefone,celular,cnh,validade,usuario,senha,created_at) VALUES
(?,?,?,?,?,?,?,?,?,?)
This error occurs on the following line of code...
File: navigation.js # Included in index.html
$(this).on('click','.submit_login',function(){
var usuario = $('.login').val();
var senha = $('.senha').val();
$.getJSON(
"<minha-api>",
function(data){
teste.innerHTML = data.nome;
var db = window.sqlitePlugin.openDatabase({name: "meu-db.db"});
db.transaction(function(tx){
tx.executeSql("INSERT INTO fornecedor_motorista (id_fornecedor,nome,email,telefone,celular,cnh,validade,usuario,senha,created_at) VALUES (?,?,?,?,?,?,?,?,?,?)",
[data.id_fornecedor,data.nome,data.email,data.telefone,data.celular,data.cnh,data.validade,data.usuario,data.senha,'0000-00-00 00:00:00'],function(tx,res){
teste.innerHTML="Os dados foram inseridos com sucesso";
});
});
}
);
});
I did the tests, put the inclusion of the table directly in the index.js file and called it in onDeviceReady, in case the connection and the creation of the tables, but the error persists...
onDeviceReady: function() {
app.receivedEvent('deviceready');
var db = window.sqlitePlugin.openDatabase({name: "4routes.db"});
db.transaction(function(tx){
$('#teste').append("A conexão foi criada.<br>");
/* Minhas tabelas... */
tx.executeSql("CREATE TABLE IF NOT EXISTS fornecedor_motorista (id_motorista INT(11) primary key,id_fornecedor INT(11),nome VACHAR(60),email VARCHAR(255),telefone VARCHAR(20),celular VARCHAR(20), cnh VARCHAR(20), validade VARCHAR(10),usuario VARCHAR(20), senha VARCHAR(100), created_at DATETIME)");
tx.executeSql("CREATE TABLE IF NOT EXISTS persistencia (id INT(11) primary key, id_motorista int(11),ativo TINYINT(1), created_at DATETIME);");
tx.executeSql("SELECT * FROM fornecedor_motorista",[],function(tx,res){
$('#teste').append("Conseguimos realizar uma consulta<br>");
$(res).each(function(){
console.log();
$("#teste").append($(this));
});
});
});
},
These texts appear, however, when I include the data in another file, being one that gave the name of navigation.js that is the one that has the above query, gives the same error as the above question...
Adding some additional information.
1. O banco de dados foi criado dentro de assets/www
2. A aplicação aparentemente abre a conexão, pois não retorna erro e as mensagens que eu coloco dentro de db.transactions retornam normalmente
3. Ocorre o retorno do JSON do servidor
4. Aparece a mensagem dizendo que os dados foram inseridos com sucesso, porém, quando coloco uma consulta logo abaixo pra retornar os dados, não retorna nada.
Ewerton, how the tables are created?
– Wakim
I did it directly through the terminal.
– Ewerton Melo
Only one add-on, q data needs to be recovered by JSON, are recovered normally, I have JSON returned from Server normally, however, the problem is in saving the data in DB Sqlite...
– Ewerton Melo
I don’t know Phonegap, but the problem is that in the device you are testing, the tables were not created. Or he is trying to insert into a different database from which he created the tables by the terminal. Shouldn’t the tables be created within the code? So when this app is installed the tables will be created automatically.
– Wakim
Got it... I’ll do their creation by Phonegap directly... Already put a response.
– Ewerton Melo
I left an answer with amendment I made...
– Ewerton Melo
I added a few more things about the problem.
– Ewerton Melo
Ewerton, I don’t have much idea what it could be, as I said I don’t usually use Phonegap. The fact that in the two files you reference different databases, is copy error or this even in your application?
– Wakim
So, I solved the problem by changing pro Storage... As the application is not great, I believe Storage solves the problem.
– Ewerton Melo
Did you find a solution? Poste as an answer to help other people.
– Maniero