Working with Sqlite Database reader in iOS

Swarnendu De September 4, 2015

When it comes to iOS development, almost everyone is familiar with the term Core Data. Being an essential storage mechanism for sensitive data, everyone needs to know how to work with it, whether it comes to storing, filtering, searching or deleting the information. But there are times when you want to actually see the data that has been stored. This can be done easily by SQLPro for SQLite Read-Only, a sqlite database reader in iOS that is available in the iTunes store for free. It is only for readable purpose.

PS. For editing purposes you can also refer to SQLPro for SQLite. It will cost you a few of those hard earned bucks šŸ™

In this blog we will show you how to check the data that is being stored in a .sqlite file.

Before starting, you are going to need a project that has core data implemented in it. If you donā€™t have one, you can download this sample project.

Lets startā€¦

Open your Xcode project and run it on your simulator(at least once) so that some data gets stored in the database.

Now download the SQLPro for SQLite Read-Only from app store.

Open the SQLPro. After you open it you will see something like this

SQLPro window

Basically, it prompts you to open the sqlite file whose data you want to view.

For finding the file, open ā€˜terminalā€™ and type in the following command

find ~ -name YourProject.sqlite

As soon as you press enter, it will print the path for required file, in a matter of seconds.

Now click on ā€œOpen Otherā€ option on SQLPro window. After that go to ā€˜finderā€™ window and press Cmd+Shift+G and in the Go field. You will get a path which you need to paste in the field. Press enter and you will be redirected to your sqlite file.

Now open the .sqlite file and you will see SQLPro window like in below image(in case you are running my sample project)

SQLPro Home window displaying fields

In the tables section you will see 4 options :

  1. ZDATE : part of my core data model
  2. ZLOCATION : part of my core data model
  3. Z_METADATA : It refers to information about the data or we can say data about the data. It is used to define different characteristics of data like type, name, source, access, etc. For more detailed information refer to this link.
  4. Z_PRIMARYKEY : Primary key in a database refers to the unique column that has different values for each row and is never null. For more information refer to this link.

If you click on any of the core data models you will get to see their various fields. The fields with name Z_PK, Z_ENT, Z_OPT are ones that we will not be emphasizing on for now. What we really need to care about are the fields that we have already been working on. In our case those fields are ZDATE for ZDATE model and ZLATITUDE, ZLONGITUDE and ZLOCATIONFORDATE for ZLOCATION model.

See the below image for reference.

ZLOCATION Model

ZLOCATION Model

ZDATE Model

ZDATE Model

Now, in the SQLPro window above you will see an another option called Data, situated just beside Schema.

Clicking on this option will let you see the data that has been stored in the database, till now. It will look somewhat similar to this.

ZLOCATION Data

ZLOCATION Data

ZDATE Data

ZDATE Data

This is it. Hope the blog was easy to understand and implement.

Feel free to comment if you face any problems or have any suggestions for improvement.