Sqlite syntax error

lol I hadn’t even noticed the INSERT/WHERE SQL, I was up at 7am without coffee. Good catch.

I want to know what the where clause is intended to do here. I’ve never seen anything like that.

update data
https://www.sqlite.org/lang_update.html
very useful returning
https://www.sqlite.org/syntax/returning-clause.html

delete data
https://www.sqlite.org/lang_delete.html

I probably are trying to do somethings that’s not officially correct due to my inexperience still with programming. What I am trying to do is to connect text fields, popup menus etc to a single character in a listbox. The listbox that has the character names is correctly connected to a table (writing, deleting, reading and updating are working), but don’t know how to connect all the other fields to that specific character name in the listbox. So I am trying all kind of things here. I am sure there is a better/official way to do this.

You can’t use “insert” and “Where” together. Insert adds a new row. If you want to update a row you need to use “update”.

update tablename set colum1=value1, column2=value2 where column3=value3

etc. As others have said. Insert will always result in a new row in your table. It will never let you update an existing row.

1 Like

btw UPDATE OR INSERT INTO is a feature of Firebird Database :slight_smile:

by my laziness i usually insert a new record with default values, returning the id and
then update it by the ui input values. one method / sql statement with values from ui.

Actually, you can, but for a specific construct not near to his intentions, more like moving blocks of existing data like:

INSERT INTO table SELECT field, field, … FROM another_table WHERE condition;

No, that is the select statement that has a where, not the insert.

1 Like

The clause (statement) is INSERT using a sub select as data source. The clause is not a SELECT. So, technically, it validates the argument an INSERT and a WHERE can be used together in some specific cases in the same statement (that ends at the semicolon).

Congratulations, if you wish to totally confuse the original poster, who is just starting out. The statement you provide is effectively

insert into table (select… where …)

which is not an example of where being used with insert.

Please reread all I wrote. I hardly will confuse anyone because I always explain the contexts. But if you wish to feel the “winner of a debate” be it, I don’t care.

I would rather be helpful to the original poster.

I was, and to others learning more things about the subject and even curious facts.

Not only that, but if you had used the prepared statement approach as described, you would have avoided altogether the issue of the single quotes. The prepared statement approach is simpler to use, and has the useful side-effect of avoiding the SQL injection problem.

I see at least one curled quote in your SQL statement.
This will definitely lead to errors. Only use straight quotes ’ and ".