Pages

Some Important commands of Core Data

Viewing the Core Data Database on the Terminal:

    Well guys as we create our Core Data Model in our projects that supports Core Data && then storing the data into Core Data, there should be a question in your mind, where is our Data in Core Data && How to view it.
    As you know that an Entity that you create in your Data Model of your Application, behaves like a Class which is a subclass of "NSObject" && this entity can be seen like a table in the actual Database. As you know that Core Data at back end uses Sqlite database. So how to view the data that your application create && store in the database.....Here is an answer.....some commands that will be helpful.

1. finding the database on the terminal with an extension "(.sqlite)" that is created && stored in your app's document directory.

------->>>>   find ~ -name '<database name>.sqlite' ;   <<<<-------





   Here in the above figure my database name is <newassignment5+++.sqlite>. Remember the database name is in single quotes. This command will return the complete path of the directory containing the database that you specified. Now go to the Document directory of your app by "cd" command as shown in figure :


2. Now that we are in the directory where the database is, do the "ls" command as shown in figure:

   As you can see in above figure the result of the "ls" command is all the databases that the Document directory of your app is containing.

3. Now run the command "sqlite3" with the database name that you want to open like...:

------>>>>>  sqlite3 newassignment5+++;   <<<<<--------

   Just after you run this command you will see the "sqlite" prompt as shown in  the figure:


4. Now rum following two commands to turn on your header && making the turning on column mod :

----->   .header on    <-----
----->   .mod column   <-----

5. Now run ".schema" command to see the entities you declared in your app model && you will see all the entities with prefix "Z" in capital letters....as shown in figure:


6. Now select the attributes of the entity that you want to which is represented by table in Sqlite database with the following command:

---->>>>   select * from <entity_name>;  <<<<----   as shown in the figure:



So this is how you see what data your data model's entities contains...

I hope this was of good use to you guys...

No comments:

Post a Comment