Comparison of SQLite and CoreData databases

Source: Internet
Author: User
Tags sqlite sqlite database

1. SQLite database
    • The basic process of SQLite database operation is to create a database, and then define some fields to define the structure of the table, you can use SQL statements to insert records into the table, delete records, modify records, and also establish links between tables.

    • These operations need to be implemented using SQL statements, and it feels straightforward to operate. If you had a little database and a SQL base, it would be nice to write, and it would be a statement of some database operations. But when the operation becomes more and more, the statement is more and more, it is annoying, the code is more, it seems to be confusing some.

    • If you want to learn more, you can see the SQLite database of iOS learning 36 data processing
2. CoreData Database
    • CoreData.framework:iOS provides an encapsulation of the original SQLite database API access, which is much simpler and more convenient to manage the data cache and persistent data through this framework than using SQL statements to manipulate the SQLite database.

    • Mechanism: Using the framework to store and query data requires only the classes provided by the framework, you can manage your data and the relationship between data in the form of objects, and the framework has nicely encapsulated database tables and fields into objects and properties. A one-to-many, many-to-many relationship between tables is encapsulated as a containment relationship between objects.

    • By means of relationship:

One-to-one: set to Properties Select Optional, Plural option To-many relationship selected;

When a many-to-one inverse relationship occurs: The properties item is selected Optional, the Count entry selects Minimun and Maximun and sets its value to 1 respectively;

  If you want to learn more, you can see the CoreData of iOS learning 37 data processing

3. Compare

The 1> CoreData class corresponds to the text description in the SQLite database:

Nsentitydescription-- table Structure
Nsmanagedobjectmodel ---all tables in the database and their contacts
Nspersistentstorecoordinator-- How to store your database
Nsmanagedobjectcontext-- database Operations
Nsfetchrequest--- query Statements
Nsmanagedobject ---Table records

2> below we can look at the CoreData class in detail

    • Nsentitydescription, Nsmanagedobjectmodel

Nsentitydescription is used to define the structure of the table, so you can understand the setentities in Nsmanagedobjectmodel: (Nsarray *) entities function probably what's the use of it. In general, the model is defined, which is coredata.xcda*****odel with the file and can be graphically manipulated. This is similar to creating an interface with NIB.

    • Nspersistentstorecoordinator

Objects of this class are usually initialized with Nsmanagedobjectmodel objects, which abstract different ways of storing, most often using Nssqlitestoretype.

    • Nsmanagedobjectcontext

The object of this class is initialized with Nspersistentstorecoordinator object, it has some methods to add, delete Nsmanagedobject

    • Nsfetchrequest

You typically use nsentitydescription to construct a query, you specify the query for that table, and you can specify a sort.

    • Nsfetchedresultscontroller

  Nsfetchedresultscontroller just again sealed, and nsfetchrequest together to use, easy to fetch data, and nsmanagedobjectcontext associated, Receive notifications when the database changes.

Comparison of 3> features

    • The power of CoreData is that this relationship can occur when an object is updated, its associated object is updated as you update a table, and the other tables associated with it are updated.

    • Another feature of Core data is that it provides simpler performance management mechanisms, such as the use of the Nsfetchedresultscontroller class, Instead of using the limit of SQL, you can limit the total number of query records by using the Setfetchbatchsize () of the Nsfetchrequest class. The magic of the Nsfetchedresultscontroller class is that when more records are needed, the class automatically updates its cache.

    • For multi-table query on the relatively speaking, CoreData no SQL intuitive, but the function of CoreData can still complete the relevant operation, but for similar external connection, left connection and other operations, in the CoreData appear powerless.

Comparison of SQLite and CoreData databases

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.