Android Question parallel key for "

Kiran Raotole

Active Member
Licensed User
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')
 

Kiran Raotole

Active Member
Licensed User
Im using this command :
tr.AddNonQueryToBatch("INSERT INTO gl (fdesc) VALUES (?)", "111111111")
But its not add any record

whats problem?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Kiran Raotole

Active Member
Licensed User
sorry i dont understand by this. I have to just insert record in my sqlite table where value store in variables

i have no problem with : tr.ExecNonQuery("INSERT INTO gl (fdesc) VALUES ('" & desc & "')")

but only problem is desc variable contain ' symbol
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have to just insert record in my sqlite table where value store in variable
B4X:
Dim MyName As String = "O'Riley"
    tr.ExecNonQuery2("INSERT INTO gl (fdesc) VALUES ?", Array As String(MyName))
or use this:
B4X:
tr.ExecNonQuery2("INSERT INTO gl (fdesc) VALUES ?", Array As String("O'Riley"))
 
Upvote 0

JLock

Member
Licensed User
B4X:
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)
 
Upvote 0
Top