Use native SQL in Core Data applications

Source: Internet
Author: User

InCore DataUse native in applicationsSQLThe function is the content to be introduced in this article. Apple providesCore DataFunction, which greatly improves convenience for common database application development.

When creating a Window Base Application, select the upper and lowerCore DataThe template is automatically created and used in the delegate file.Core DataAll the methods used to access data can be used to call the methods in delegate in other View controllers.

Modifying the Data Model and creating Entity definitions based on the Model also provides visualized operations. Once an instance is defined, you only need to create a new instance in the program and assign a value to the variable, call the save method in delegate to add a new record. This method is especially useful for fields that are more difficult to process in SQL such as long text and time. It is also convenient to retrieve the list of saved records. (For details, refer to the Core Data getting started tutorial provided by apple ).

However, when I needed the aggregation function, it was completely silly. Although Core Data also provides simple sum and avg operations, however, the sum under ralationship cannot be found at all, or even the solution is not found on the forum. Do I need to retrieve the list and manually summarize it one by one? In this way, the efficiency is lower when the data volume is large.

Of course, if you can directly useSQLStatement. However,Core DataThe encapsulation is complete and I don't know where it stores the data. What should I do? Do you want to useSqliteTo rewrite the entire program, you need to make significant unnecessary changes to the existing functions such as addition and details.

Today, we finally found a solution: Core Data is an sqlite-based encapsulation, so its underlying layer is still using sqlite to store Data, and the database it uses, in the delegate file. It is usually the sqlite file named by the program name under the program Documents directory. If the program has been run in the Simulator, you only need to enter the Library/Application Support/iPhone Simulator/User/Applications/in the User directory. Here is the program that has been run in all your simulators, find the one you need and enter the Documents Directory, which is the automatically generated sqlite database file. Copy it and use the sqlite3 command to directly view the database structure.

By default, the name of the generated data table is your Entity name, which starts with a letter Z. The field name is also the Instance name you defined, and starts with a letter Z, the primary key is a self-increasing int type. With this database structure, addLibsqlite3.0.dylib framework, and then you can use the nativeSqlite3.

With easeCore dataSolve simple data operations with fully customizedSqliteFunction. Now you can develop powerful database applications as you like.

Summary: InCore DataUse native in applicationsSQLI hope this article will be helpful to you.

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.