SQL to extract messages from backup
Solution 1:
The following will add a column indicating whether the phone user was sending or receiving each message:
SELECT datetime(message.date, 'unixepoch', '+31 years', '-6 hours') as Timestamp, handle.id, message.text,
case when message.is_from_me then 'From me' else 'To me' end as Sender
FROM message, handle WHERE message.handle_id = handle.ROWID;