Thursday 28 December 2017

Exploring Core Data database with sqlite3 on command line

Core Data abstracts a lot of the low level details of storage away for programmers, and that’s a good thing however sometimes it’s useful to lift the lid and see what’s happening beneath. For this post I’ll be specifically looking at the SQLite persistent store, I’ll assume you already have an app using Core Data and want to glean more insight into the inner workings. Fortunately the mac comes with a command utility to open and explore sqlite databases (sqlite3), but before we can delve into the database file, we must first find the file.

Finding the database file for an iOS App
The easiest way to look inside the database file is by running your app within the iOS Simulator for Xcode. The simulator stores all of its file structure within a directory on your mac. The trick is finding it. By default the simulator will store its files in Home Directory ▷ Library ▷ Developer ▷ CoreSimulator ▷ Devices. Normally the Library folder is hidden to prevent users mucking things up, however you can access Library from the Go menu in Finder by holding the option key down while displaying the menu.



However since we’re starting to perform some advanced techniques it may be easier to perform these actions on the command line, therefore open Terminal and type the following to perform a search of all the simulator devices for a file with a given name (you can substitute the file name for your own):
find ~/Library/Developer/CoreSimulator/Devices -name CoreDataDemo.sqlite

This will print a list of all the files found with the given name. However if you have been running your app on multiple simulators then multiple files will be displayed. It may not be obvious which file is for which simulator as the folders are named after the device identifier rather than a human readable name, additionally the files are not sorted therefore the first file may not be the most recent one.


To find out the Identifier for the simulated device, we can get it in Xcode by going to the Windows menu and selecting Devices and Simulators. This will open a new window, switch tabs to Simulators and select the simulator that your interested in. The Identifier will be displayed along with the summary information.


Since this can be rather painstaking, I've written as script that will search for a given database file and display the top 5 most recently modified files and the ability to directly open them. As well as listing a human understandable version of the simulator. The findcoredata.py script can be found on GitHub.


You’ll notice that the sqlite database file may not be alone. You may also have a file with ‘wal’ suffix, this is the Write-ahead log and a file with ‘shm’ for the Shared-Memory file. If you intend to copy the database then it is important that you copy these files also.

Look, but don’t touch
It is important to remember that you should avoid making modifications to the sqlite data file as Core Data will manage that. The sqlite3 command line tool can be used to execute commands against the database.


Perhaps I'll blog more on the internal structure of the database, but for now since you know how to find and open the database happy exploration.

74 comments:

  1. Dominant part of our mentors are graduated class of IIT, ISB and IIM and a couple of them are PhD experts. data science course in pune

    ReplyDelete
  2. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    machine learning courses in Bangalore

    ReplyDelete
  3. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
    Data science course in mumbai

    ReplyDelete
  4. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!
    Data science course in mumbai

    ReplyDelete
  5. Such a very useful Blog. Very interesting to read this article. I have learn some new information.thanks for sharing. know more about

    ReplyDelete
  6. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. I curious more interest in some of them hope you will give more information on this topics in your next articles.
    Data Scientist course

    ReplyDelete
  7. Took me time to understand all of the comments, but I seriously enjoyed the write-up. It proved being really helpful to me and Im positive to all of the commenters right here! Its constantly nice when you can not only be informed, but also entertained! I am certain you had enjoyable writing this write-up.

    data science course
    360DigiTMG

    ReplyDelete

  8. The information provided on the site is informative. Looking forward more such blogs. Thanks for sharing .
    Artificial Inteligence course in Thiruvananthapuram
    AI Course in Thiruvanantapuram

    ReplyDelete

  9. This information is very impressive, I feel happy by reading your blog about Data Science and and I am interested learning more about this topic.
    Data Science Training In Hyderabad

    ReplyDelete
  10. Great post i must say and thanks for the information.


    Data Scientist Course

    ReplyDelete
  11. Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.
    Data Science Certification in Bangalore

    ReplyDelete
  12. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.

    Data Science Certification in Bangalore

    ReplyDelete
  13. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. buy 30 instagram likes uk

    ReplyDelete

  14. This post is really helpful for us. I certainly love this website, keep on it.
    Data Science Course in Hyderabad

    ReplyDelete
  15. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing
    best data analyst courses in mumbai

    ReplyDelete
  16. This is my first time visit here. From the tons of comments ExcelR Machine Learning Course Pune on your articles.I guess I am not only one having all the enjoyment right here!

    ReplyDelete
  17. I just wanted to thank you for the excellent reading!! I really enjoy every little bit of it that I have bookmarked for you to check out new stuff that you publish.https://360digitmg.com/course/certification-program-in-data-science

    ReplyDelete
  18. Great blog found to be well written in a simple manner that everyone will understand and gain the enough knowledge from your blog being more informative is an added advantage for the users who are going through it. Once again nice blog keep it up.

    360DigiTMG Python Course

    ReplyDelete
  19. I am really happy with your blog because your article is very unique and powerful for new reader.data science course in Hyderabad

    ReplyDelete
  20. Data Science Courses Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

    ReplyDelete
  21. Data Scientist Courses Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! Cool stuff you have and you keep overhaul every one of us

    ReplyDelete
  22. I think this is the minimum value to earn more than just commit
    artificial intelligence course in noida

    ReplyDelete
  23. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. data science training in Hyderabad

    ReplyDelete
  24. A Data Scientist starts his work by asking good questions and understanding the problem. data science course syllabus

    ReplyDelete
  25. Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work.data science course in Hyderabad

    ReplyDelete
  26. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.data scientist course in pune

    ReplyDelete
  27. Attend The Business Analytics Courses From ExcelR. Practical Business Analytics Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Business Analytics Courses.
    Business Analytics Courses

    ReplyDelete
  28. wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.

    Data Science Course in Pune

    ReplyDelete
  29. You totally coordinate our desire and the assortment of our data.
    data science course in noida

    ReplyDelete
  30. You totally coordinate our desire and the assortment of our data.
    data scientist course

    ReplyDelete
  31. Standard visits recorded here are the simplest strategy to value your vitality, which is the reason why I am heading off to the site regularly, looking for new, fascinating information. Many, bless your heart!
    data science courses in noida

    ReplyDelete
  32. Standard visits recorded here are the simplest strategy to value your vitality, which is the reason why I am heading off to the site regularly, looking for new, fascinating information. Many, bless your heart!
    best data science courses

    ReplyDelete
  33. I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
    Data Science course in Hyderabad

    ReplyDelete
  34. Thankyou for this wondrous post, I am happy I watched this site on yippee. ExcelR Data Analytics Course

    ReplyDelete
  35. This post is very simple to read and appreciate without leaving any details out. Great work!
    data scientist course

    ReplyDelete
  36. Want to leave a little comment to support and wish you the best of luck.we wish you the best of luck in all your blogging endeavors.
    Business Analytics Course in Bangalore

    ReplyDelete
  37. I see some amazingly important and kept up to length of your strength searching for in your on the site
    data scientist certification

    ReplyDelete
  38. Thanks for the information about Blogspot very informative for everyone
    machine learning courses in aurangabad

    ReplyDelete
  39. Good Post! it was so good to read and useful to improve my knowledge as an updated one, keep blogging. After seeing your article, I want to say that also a well-written article with some very good information which is very useful for the readers.... thanks for sharing it and do share more posts like this.
    Data Science Training in Hyderabad
    Data Science Course in Hyderabad

    ReplyDelete
  40. Really well-written and informative blog. I liked it. I appreciate your effort in this blog. Keep sharing some more blogs again quickly. Thanks alot!
    Data Science Course in Hyderabad

    ReplyDelete
  41. Thanks for Sharing this Valuable Information with us: this is very useful for me. Keep it Up.
    best data science course online

    ReplyDelete
  42. Nice and very informative blog, glad to learn something through you.
    machine learning course aurangabad

    ReplyDelete
  43. Your work is very good and I appreciate you and hopping for some more informative posts
    data scientist certification malaysia

    ReplyDelete
  44. Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work.
    data science course fee in hyderabad

    ReplyDelete
  45. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one.
    cyber security certification malaysia

    ReplyDelete
  46. It is extremely nice to see the greatest details presented in an easy and understanding manner.
    data science course in hyderabad

    ReplyDelete
  47. Informative blog and knowledgeable content. Keep posting more blogs like this. Thank you.
    Data Scientist Course in Hyderabad

    ReplyDelete
  48. This is the first time I visit here. I found such a large number of engaging stuff in your blog, particularly its conversation. From the huge amounts of remarks on your articles, I surmise I am by all accounts not the only one having all the recreation here! Keep doing awesome. It has been important to compose something like this on my site and you have given me a thought.
    business analytics course in hyderabad

    ReplyDelete
  49. Nice Blog! such informative things you are sharing,I really liked your content. Get the best Data Science online course in the comfort of your home. Flexible timings, Best industry trainers, and meticulously crafted curriculum.business analytics course in chennai

    ReplyDelete
  50. There are also varieties of options available to choose a career in data science, like you can become a data scientist, developer, data engineer, analyst, database administrator, and many more.

    data science training in patna

    ReplyDelete
  51. wonderful article...keep up with your writing skills...Thanks for sharing...
    Data science training in Pune

    ReplyDelete
  52. Data Science Course in Nasik Best Training Institute Fees, Duration, Certification Online Classes Available There are no limitations to learning courses and one can indeed get multiple certificates provided he she completes the courses and clears the exam. PassedB.Sc. Degree from a honored University as defined by UGC, with at least 45 marks( 40 marks in case of candidates belonging to reserved order) and passed 10 2 examination with Mathematics as a subject. Curated by Hadoop experts, this Big Data Analytics course covers everything you need to gain proficiency in this field.data science course training in faridabad

    ReplyDelete
  53. "Your detailed guide to exploring Core Data's SQLite database using the sqlite3 command line tool is incredibly informative. Your step-by-step instructions, along with the script to find and open the database file, make it easy for readers to delve into the inner workings of Core Data. Your emphasis on not modifying the database file directly and your plans to potentially blog more about the database's internal structure show your commitment to thorough exploration. Thanks for sharing such valuable insights!"
    Data Analytics Courses In Bangalore

    ReplyDelete
  54. Hello,
    The article serves as a guide for developers who wish to gain deeper insights into the inner workings of Core Data's SQLite database through the use of command-line tools, while also emphasizing the importance of avoiding unauthorized modifications to the database. I enjoyed reading through this.
    Data Analytics Courses in Pune

    ReplyDelete
  55. This is a really useful post! Thank you for providing the procedures for investigating Core Data's SQLite database. It's ideal for developers who want to have a better knowledge of their app's data storage.
    Data Analytics Courses in Delhi

    ReplyDelete
  56. This post is quite helpful! I appreciate you sharing the steps to investigate the SQLite database of Core Data. It's perfect for developers who want to understand more about how your app stores data.
    Data Analytics Courses in Agra

    ReplyDelete
  57. Thanks for sharing the valuable content and its really useful and helpful for everyone.
    Data Analytics Courses In Chennai

    ReplyDelete
  58. nice blog
    Data Analytics Courses In Vadodara

    ReplyDelete
  59. love how you draw parallels between everyday life and your subject matter. It makes it relatable and engaging.

    ReplyDelete
  60. such a well written & informative blog. Keep up the great work.
    financial modelling course in melbourne

    ReplyDelete
  61. Thank you for providing in depth knowledge and excellent tutorial on Finding the database file for an iOS App.
    Digital Marketing Courses In Bhutan

    ReplyDelete
  62. The inclusion of practical examples and commands for interacting with SQLite3 showcases a hands-on approach that is immensely beneficial. The blog's clarity and attention to detail make it accessible for developers at various skill levels, from beginners looking to grasp the fundamentals to seasoned developers aiming to fine-tune their database management skills. Digital Marketing Courses In Norwich

    ReplyDelete

  63. "This blog is a treasure trove for developers delving into Core Data within iOS. The exploration of accessing and exploring the Core Data database using sqlite3 on the command line is incredibly insightful. The step-by-step guide and practical examples empower developers to understand the database structure and perform direct queries efficiently. It's a must-read for iOS developers seeking a deeper understanding of how Core Data operates at its fundamental level. A valuable resource that demystifies the Core Data database interaction!"

    Investment banking jobs in Mumbai

    ReplyDelete
  64. A must-read for iOS developers. Great blog post. Thanks for sharing.

    Investment banking courses in Germany

    ReplyDelete
  65. This article provides a clear and insightful guide on exploring Core Data databases using sqlite3. The step-by-step instructions make it easy to understand. Thanks for sharing this valuable information!
    Investment banking courses syllabus

    ReplyDelete
  66. Hey there! Exploring Core Data database with sqlite3 on the command line is a great way to dive into the inner workings of your app's data storage. It allows you to interact directly with the database and gain insights into your data structure. This can be super useful for debugging and analyzing your app's data flow. Thanks for sharing this cool technique!
    Data analytics courses in Rohini

    ReplyDelete