Reputation: 4585
I found this answer but I'm not sure it does what I want to. It looks like it updates ALL rows in the table, where I only want to update one.
My table is very simple:
MacAddress | Name
1C-6F-65-C6-20-0B | Logan-PC
DE-AD-BE-EF-F0-0D | PC1
...
MacAddress
is the PK and I want to simply be able to update Name if it exists or add a new row if it does not, given the MacAddress
as references and a Name
string.
This is the first time I'm using SQLite so I may just not be understanding Eric B's answer correctly.
Upvotes: 0
Views: 119
Reputation: 62831
The answer you posted seems to work well for me assuming your MacAddress is a primary key in your table.
insert or replace into yourtable (macaddress, name)
values ('1C-6F-65-C6-20-0B', 'Logan-PC');
insert or replace into yourtable (macaddress, name)
values ('1C-6F-65-C6-20-0B', 'Logan-PC-Updated');
This will result in a single row, with Logan-PC-Updated as the updated name.
NOTE: If your MacAddress is not your primary key, then this method will not work.
Upvotes: 1