I need to make some mass updates to an existing squirrelmail solution.
Table:
describe userprefs;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| user | varchar(128) | NO | PRI | | |
| prefkey | varchar(64) | NO | PRI | | |
| prefval | blob | NO | | | |
+---------+--------------+------+-----+---------+-------+
example values
+-------------------------+-------------------+---------+
| user | prefkey | prefval |
+-------------------------+-------------------+---------+
| dave@example.com | show_html_default | 1 |
| laura@example.com | show_html_default | 0 |
+---------+--------------+------+-----+---------+-------+
========================
I need to set prefval=1 where prefkey="show_html_default"
Difficulty: not every user appears in the "user" column, but I have external list of all users that I need to populate
So I need to manage three cases:
1) no match on "user" + "prefkey" (either user or prefkey could be missing from table) then I need to insert the record with the desired prefval
2) match on "user" + "prefkey" but prefval=0, then I need to set prefval to "1"
3) where the user exists with the desired prefval, I can leave that value alone.
If this a suitable use for a "replace into" statement?
can I do (pseudocode)
(for each user as thisuser)
replace into userprefs(user,prefkey,prefvalue) values ("$thisuser","show_html_default","1")
I just want to make sure I'll hit all three cases.
Thanks!
D.E.R. Management - IT Project Management Consulting
Table:
describe userprefs;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| user | varchar(128) | NO | PRI | | |
| prefkey | varchar(64) | NO | PRI | | |
| prefval | blob | NO | | | |
+---------+--------------+------+-----+---------+-------+
example values
+-------------------------+-------------------+---------+
| user | prefkey | prefval |
+-------------------------+-------------------+---------+
| dave@example.com | show_html_default | 1 |
| laura@example.com | show_html_default | 0 |
+---------+--------------+------+-----+---------+-------+
========================
I need to set prefval=1 where prefkey="show_html_default"
Difficulty: not every user appears in the "user" column, but I have external list of all users that I need to populate
So I need to manage three cases:
1) no match on "user" + "prefkey" (either user or prefkey could be missing from table) then I need to insert the record with the desired prefval
2) match on "user" + "prefkey" but prefval=0, then I need to set prefval to "1"
3) where the user exists with the desired prefval, I can leave that value alone.
If this a suitable use for a "replace into" statement?
can I do (pseudocode)
(for each user as thisuser)
replace into userprefs(user,prefkey,prefvalue) values ("$thisuser","show_html_default","1")
I just want to make sure I'll hit all three cases.
Thanks!
D.E.R. Management - IT Project Management Consulting