I'm trying to insert record in sqlite my code is :
tr.ExecNonQuery("INSERT INTO gl (fdesc) VALUES ('" & desc & "')")
fdesc has value = VASANT'S THE SUPER SHOP
Log is : android.database.sqlite.SQLiteException: near "S": syntax error (code 1): , while compiling: INSERT INTO gl (fdesc) VALUES ('VASANT'S THE SUPER SHOP')
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
mSQL.Initialize(File.DirInternal, "test.db", True)
End If
Dim desc As String = "Vasant's the super shop"
mSQL.ExecNonQuery("CREATE TABLE IF NOT EXISTS Table1 (ID INTEGER, Name TEXT)")
mSQL.ExecNonQuery2("INSERT INTO Table1 VALUES (?, ?)", Array As Object(1, desc))
Log(mSQL.ExecQuerySingleResult("SELECT Name FROM Table1 WHERE ID = 1"))
End Sub
This code logs "vasant's the super shop" with no issue parsing the '. You should either clean the string of any invalid character or disallow the user to input them or change:
tr.ExecNonQuery("INSERT INTO gl (fdesc) VALUES ('" & desc & "')")
TO
tr.ExecNonQuery2("INSERT INTO gl (fdesc) VALUES (?)", Array As Object(desc)