Here you can find some SQLite queries to analyze Android databases that I wrote and that came in handy during my professional activity as a Mobile Forensics Examiner.
You can use them to understand how the msgstore.db database works, as a basis to modify according to your needs or to incorporate them into Python scripts.
Have fun!