SUMMARY

This chapter provided a brief introduction to the SQLite3 database used in the iPhone. With SQLite3, you can now store all your structured data in an efficient manner and perform complex aggregations on your data. To learn more about SQLite, visit its official page at www.sqlite.org.

EXERCISES

  1. Explain the difference between the sqlite3_exec() function and the three functions sqlite3_prepare(), sqlite3_step(), and sqlite3_finalize().
  2. How do you obtain a C-style string from an NSString object?
  3. Write the code segment to retrieve a set of rows from a table.

    Answers to the exercises can be found in Appendix D.

image WHAT YOU LEARNED IN THIS CHAPTER

TOPIC KEY CONCEPTS
Using a SQLite3 database in your application Add a reference to the libsqlite3.dylib library to your project.
Obtaining a C-style string from an NSString object Use the UTF8String method of the NSString class.
Creating and opening a SQLite3 database Use the sqlite3_open() C function.
Executing a SQL query Use the sqlite3_exec() C function.
Closing a database connection Use the sqlite3_close() C function.
Using bind variables Create a sqlite3_stmt object.

Use the sqlite3_prepare_v2() C function to prepare the statement.

Use the sqlite3_bind_text() (or sqlite3_bind_int(), and so on) C function to insert the values into the statement.

Use the sqlite3_step() C function to execute the statement.

Use the ...

Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.