const kSQL = "INSERT INTO Characters (Character_Information) VALUES (?) WHERE Character_Name = ?"
db.ExecuteSQL(kSQL, txtCharacterInfo.Text, TextFieldCharacterName.Text)
The SQL with ?s in it is called a prepared statement, and this prevents you from suffering effects of SQL injection or having to sanitize the user input yourself.
Also, you can make code on the forum readable as code by using the </> button above the post editor or surrounding the code in three backticks ```
Thanks all, I did read the chapters on the preferred statements to avoid problems, but didn’t practise it yet. I first want to understand the basic use of sqlite commands.
Using a prepared statement is basic use of SQLite commands and might even solve your problem here. If it were a whole extra thing to learn like they used to be in API 1.0, I might not have suggested it. API 2.0 makes all of your queries prepared, so you should take advantage of that.
For example, if your characters name just happened to be McLovin' then everyone’s suggestions here will fail. Prepared statements would handle the value correctly for you.
I tried the above solutions, but kept on getting the same syntax error. However after tearing my eyes out and randomly making changes I got this to work:
db.ExecuteSQL("INSERT INTO Characters (Character_Information) VALUES ('" + txtCharacterInfo.text + "’ WHERE Character_Name = " + TextFieldCharacterName.text + "')")
You also have a parenthesis in the wrong place. That last one that’s inside the quotes needs to be just after the values like this:
db.ExecuteSQL(“INSERT INTO Characters (Character_Information) VALUES ('” + txtCharacterInfo.text + "’) WHERE Character_Name = '" + TextFieldCharacterName.text + “’”)
But more importantly… INSERT statements don’t normally have WHERE clauses on them. An UPDATE would, but when you are adding brand new rows to a table there’s no need for a WHERE statement.
Yes, I am aware of that, but I am trying to get text field info placed in the same record as a new character I added before that. Right now, that info is placed at a new last record row. So by using the WHERE command I am trying to get that info with the correct Character name. Not working still though... Yes, it’s a mess…
My advice about using a SQL_Cmd string and reporting it using System.DebugLog will aboid loosing your vision because you will be able to read exactly what the SQLite Plugin receive.
Please, follow the advice, then judge if it was pertinent.
First, that must be in a transaction (chaining interdependent instructions isolated).
Second, all records must have a ROWID (another concept you must learn)
Third, to reference and get the last ROWID inserted, use the function last_insert_rowid() in that transaction
Fourth, to change a previous inserted record, use UPDATE and not INSERT.