sqlite table:
CREATE TABLE IF NOT EXISTS INFO
(
uri TEXT PRIMARY KEY,
cap INTEGER,
/* some other columns */
uid TEXT
);
INFO
table has 5K+ rows and is run on a low power device (comparable to a 3 year old mobile phone).
I have this task: insert new URI with some values into INFO
table, however, if URI is already present, then I need to update uid
text field by appending extra text to it if the extra text to be appended isn't found within existing uid
string; all other fields should remain unchanged.
As an example: INFO already has uri=
"http://example.com" with this uid
string: "|123||abc||xxx|".
I need to add uri
="http://example.com" and uid
="|abc|". Since "|abc|" is a substring within existing field for the uri, then nothing should be updated. In any case, remaining fields shouldn't be updated
To get it done I have these options:
- build some sql query (if it's possible to do something like that with sqlite in one sql statement),
- Do everything manually in two steps: a) retrieve row for uid, do all processing manually and b) update existing or insert a new row if needed
Considering this is constrained device, which way is preferable? What if I omit the the extra requirement of sub-string match and always append uid to existing uid field?