Answer the question
In order to leave comments, you need to log in
How to do INSERT OR UPDATE?
Hello.
You need to do something like INSERT OR UPDATE.
Essence:
There are records of the form:
name = string (example - John)
age = number (example - 24)
type = string, can be one of ["employee", "employer", "both"]
So, you need to make a request for adding data, first checking whether there are similar ones in the database and update if there is.
Algorithm:
Suppose the database already has:
John, 24, employee
1st case:
We are trying to put:
John, 24, employee
Result - do nothing
2nd case:
We are trying to put:
John, 24, employer
Result - update the object to John, 24 , both
That's actually all. Are there any considerations?
Answer the question
In order to leave comments, you need to log in
Execute with 2 commands in the DBMS.
1) perform
select * from table where age=X and name=Y before your
operation name) - parse the returned type and then perform the necessary update or not.
I do not know the capabilities of sqlite - maybe you can make a stored procedure in it, where you can implement all the logic inside and call it with parameters.
To begin with, it would be good to designate the database and libraries that you use.
If it's a secret - then the most stupid and costly way: select-insert|update
in MS SQL
Merge
in My SQL
Insert into .... with duplicate key Update
try both options :)
I don't know exactly which one will work in SQL Lite
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question