B4J Question SQLite error or missing database

Peter Lewis

Active Member
Licensed User
Longtime User
I have been running my program for about 10 loops around this sub without changing anything, all of a sudden it comes up with this error.

B4X:
sub ChangeEntry(SearchPath As String, Newidone As Int)
   ' Try
   ' sql1.InitializeSQLite(File.DirApp, "data/DJ.db", True)
' Catch
  '      Log("ERROR init SQLite Database: " & LastException.Message)
   '     End Try

    sql1.ExecNonQuery("UPDATE `Playsongs` SET " & "iDone" & "='" & Newidone & "' WHERE `songName` LIKE '" & SearchPath & "'")
    'Log(SearchPath)
End Sub

I checked the integrity of the database and everything is ok.

I changed NO code.

Is there some sort of a timeout with SQLite ?

or do i have to close the database after each read /change /insert ?

I put in the Try command to see if that would help but it did not

The error is

java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near "s": syntax error)

UPDATE: I just deleted the database and recreated it then went again about 6 loops and the same error occurred.
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
The error is because you are not escaping the values correctly.

for instance:

B4X:
 sql1.ExecNonQuery("UPDATE `Playsongs` SET " & "iDone" & "='" & Newidone & "' WHERE `songName` LIKE '" & SearchPath & "'")
'may become this: 
sql1.execNonQuery2("UPDATE Palysongs SET iDone = ? WHERE `songName` LIKE ?",array as string(Newidone,searchpath))
 
Upvote 0
Top