Skip to content

Instantly share code, notes, and snippets.

@morrah
Created February 23, 2015 19:48
Show Gist options
  • Save morrah/0e1b252c7abb8779ff36 to your computer and use it in GitHub Desktop.
Save morrah/0e1b252c7abb8779ff36 to your computer and use it in GitHub Desktop.
-- sqlite >= 3.3.8 required due to 'create ... if not exists ...'
CREATE TRIGGER IF NOT EXISTS update_messages AFTER UPDATE ON Messages
BEGIN
INSERT INTO Messages
SELECT (SELECT CAST(max(id) AS INTEGER) from Messages)+1,
new.is_permanent,
new.convo_id,
new.chatname,
new.author,
new.from_dispname,
new.author_was_live,
new.guid,
new.dialog_partner,
new.timestamp,
new.type,
new.sending_status,
new.consumption_status,
new.edited_by,
new.edited_timestamp,
new.param_key,
new.param_value,
'edited: ' || old.body_xml,
new.identities,
new.reason,
new.leavereason,
new.participant_count,
new.error_code,
new.chatmsg_type,
new.chatmsg_status,
new.body_is_rawxml,
new.oldoptions,
new.newoptions,
new.newrole,
new.pk_id,
new.crc,
new.remote_id,
new.call_guid,
new.extprop_contact_review_date,
new.extprop_contact_received_stamp,
new.extprop_contact_reviewed
WHERE old.body_xml IS NOT new.body_xml AND old.id = new.id;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment