Android Question Error running multiple query in sequence

antsab

Member
Licensed User
Longtime User
Hi i'm in trouble with sqllite and some querys i need to run in sequence (insert, update, delete no select statement) if i put a msgbox every 2 query (so i have a stop with the running code of some seconds) there's no trouble but if i try to run in sequence with no stop i've a malformed db or many errors on query.

I've tried with async query but problem is the same, there is a method for make app in waiting mode for 4 seconds every query?

Thanks in advance
 

LucaMs

Expert
Licensed User
Longtime User
Almost certainly the queries are in conflict, acting in the wrong order on the same records. The problem is not the method you use, even if you use an asynchronous method, you make things worse.

Without seeing the db and the code, we can not help you better.
 
Upvote 0

antsab

Member
Licensed User
Longtime User

Ok here 's the code, in sequence i've always error running query or malformed database if every two querys i pause with a messagebox and wait 3/4 second all is fine, please explain me what's my mystake.

Thank you

B4X:
SQL1.ExecNonQuery("DELETE FROM OrdiniNuovi")
SQL1.ExecNonQuery("REPLACE INTO OrdiniNuovi SELECT * FROM db1.Clientiexp")
SQL1.ExecNonQuery("INSERT INTO Clienti ([Note], DataAPP, Flag, Matricola, TNT, Telefono, Insegna, Tecnico, Cliente, Ordine, Problema, Ritardo, Equipment, CAP, Tipo, Nome, Codice, Via, Citta, DataInizio )Select OrdiniNuovi.Note, OrdiniNuovi.DataAPP, OrdiniNuovi.Flag, OrdiniNuovi.Matricola, OrdiniNuovi.TNT, OrdiniNuovi.Telefono, OrdiniNuovi.Insegna, OrdiniNuovi.Tecnico, OrdiniNuovi.Cliente, OrdiniNuovi.Ordine, OrdiniNuovi.Problema, OrdiniNuovi.Ritardo, OrdiniNuovi.Equipment, OrdiniNuovi.CAP, OrdiniNuovi.Tipo, OrdiniNuovi.Nome, OrdiniNuovi.Codice, OrdiniNuovi.Via, OrdiniNuovi.Citta, OrdiniNuovi.DataInizio FROM OrdiniNuovi LEFT JOIN Clienti ON OrdiniNuovi.Ordine = Clienti.Ordine WHERE Clienti.Ordine Is Null")
SQL1.ExecNonQuery("UPDATE Clienti SET Note=(select Note FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Tecnico=(select Tecnico FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Matricola=(select Matricola FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), TNT=(select TNT FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Telefono=(select Telefono FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Problema=(select Problema FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Equipment=(select Equipment FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Via=(select Via FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Ritardo=(select Ritardo FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine)")
SQL1.ExecNonQuery("DELETE FROM Clienti WHERE Tecnico NOT LIKE 'BAROLO'")
SQL1.ExecNonQuery("DELETE FROM db1.Carichi WHERE Tecnico1 NOT LIKE 'BAROLO'")
SQL1.ExecNonQuery("INSERT INTO Carichi (Codice,Quantita,ODL,Tecnico,Data,Elaborato)Select Codice1,Quantita1,ODL1,Tecnico1,Data1,Elaborato1 FROM db1.Carichi LEFT JOIN Carichi ON db1.Carichi.ODL1 = Carichi.ODL WHERE Carichi.ODL Is Null")
SQL1.ExecNonQuery("UPDATE Ricambi SET Qta=0 WHERE Qta IS NULL")
SQL1.ExecNonQuery("UPDATE Ricambi SET Qta = Qta + (Select (Carichi.Quantita) FROM Carichi WHERE Carichi.Codice = Ricambi.Codice) WHERE EXISTS (Select * FROM Carichi WHERE Carichi.Codice = Ricambi.Codice AND Carichi.Elaborato=0)")
SQL1.ExecNonQuery("UPDATE Carichi SET Elaborato = 1")
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Effettivamente, non vedo niente di strano (anche se leggere le query rinc... un bel po' )
Indeed, I do not see strange things (although, reading queries...)

Prova così (anche se in modo asincrono...!)
Test well (although the use asynchronously...!)
B4X:
    Private Query As String
        Query = "DELETE FROM OrdiniNuovi"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "REPLACE INTO OrdiniNuovi SELECT * FROM db1.Clientiexp"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "INSERT INTO Clienti ([Note], DataAPP, Flag, Matricola, TNT, Telefono, Insegna, Tecnico, Cliente, Ordine, Problema, Ritardo, Equipment, CAP, Tipo, Nome, Codice, Via, Citta, DataInizio )Select OrdiniNuovi.Note, OrdiniNuovi.DataAPP, OrdiniNuovi.Flag, OrdiniNuovi.Matricola, OrdiniNuovi.TNT, OrdiniNuovi.Telefono, OrdiniNuovi.Insegna, OrdiniNuovi.Tecnico, OrdiniNuovi.Cliente, OrdiniNuovi.Ordine, OrdiniNuovi.Problema, OrdiniNuovi.Ritardo, OrdiniNuovi.Equipment, OrdiniNuovi.CAP, OrdiniNuovi.Tipo, OrdiniNuovi.Nome, OrdiniNuovi.Codice, OrdiniNuovi.Via, OrdiniNuovi.Citta, OrdiniNuovi.DataInizio FROM OrdiniNuovi LEFT JOIN Clienti ON OrdiniNuovi.Ordine = Clienti.Ordine WHERE Clienti.Ordine Is Null"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "UPDATE Clienti SET Note=(select Note FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Tecnico=(select Tecnico FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Matricola=(select Matricola FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), TNT=(select TNT FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Telefono=(select Telefono FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Problema=(select Problema FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Equipment=(select Equipment FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Via=(select Via FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine), Ritardo=(select Ritardo FROM ordininuovi WHERE OrdiniNuovi.Ordine = Clienti.Ordine)"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "DELETE FROM Clienti WHERE Tecnico NOT LIKE 'BAROLO'"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "DELETE FROM db1.Carichi WHERE Tecnico1 NOT LIKE 'BAROLO'"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "INSERT INTO Carichi (Codice,Quantita,ODL,Tecnico,Data,Elaborato)Select Codice1,Quantita1,ODL1,Tecnico1,Data1,Elaborato1 FROM db1.Carichi LEFT JOIN Carichi ON db1.Carichi.ODL1 = Carichi.ODL WHERE Carichi.ODL Is Null"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "UPDATE Ricambi SET Qta=0 WHERE Qta IS NULL"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "UPDATE Ricambi SET Qta = Qta + (Select (Carichi.Quantita) FROM Carichi WHERE Carichi.Codice = Ricambi.Codice) WHERE EXISTS (Select * FROM Carichi WHERE Carichi.Codice = Ricambi.Codice AND Carichi.Elaborato=0)"
    SQL1.AddNonQueryToBatch(Query, Null)
        Query = "UPDATE Carichi SET Elaborato = 1"
    SQL1.AddNonQueryToBatch(Query, Null)
  
    SQL1.ExecNonQueryBatch("AllQueries")
  

Private Sub AllQueries_NonQueryComplete (Success As Boolean)
    If Success Then
        Log("Esecuzione completata perfettamente.")
    Else
        Log(LastException)
    End If
End Sub


(LIKE Barolo )
 
Upvote 0

antsab

Member
Licensed User
Longtime User
Ok grazie mille per la dritta, effettivamente fanno impressione le query viste cosi'
 
Upvote 0

antsab

Member
Licensed User
Longtime User
Can you upload a simple project that demonstrates this error?

Hi Erel i put all the querys on click event of a button (before i iniialize sql1 of course) now i try the LucaMas solution and then i write the result in this post so if anybody else has the same problem here's find solution (i pray for that)
 
Upvote 0

antsab

Member
Licensed User
Longtime User
Hi Erel i put all the querys on click event of a button (before i iniialize sql1 of course) now i try the LucaMas solution and then i write the result in this post so if anybody else has the same problem here's find solution (i pray for that)

Ok problem solved, no more malformed database for now i try many times to run the querys like LucaMs's example and seem fine. Thank you
 
Upvote 0

antsab

Member
Licensed User
Longtime User

Grazie mille adesso effettivamente non mi distrugge piu' il database e sembra anche molto piu' veloce nell'eseguire le query.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…