Skip to Content
Beginning iOS 5 Application Development
book

Beginning iOS 5 Application Development

by Wei-Meng Lee
January 2012
Beginner content levelBeginner
655 pages
16h 35m
English
Wrox
Content preview from Beginning iOS 5 Application Development

BUNDLING SQLITE DATABASES WITH YOUR APPLICATION

Although programmatically creating a SQLite database and using it during runtime is very flexible, most of the time you just need to create the database file during the designing stage of your development, and bundle the database with your application so that it can be used during runtime. Therefore, rather than create the database file using code, you need to create it in Mac OS X.

Fortunately, you can easily create a SQLite database file in Mac OS X by using the sqlite3 application in Terminal. Figure 11-5 shows the command that you need to create a database named mydata.sql, containing a table named Contacts with two fields: email and name. It also inserts a row into the table and then retrieves it to verify that it is inserted properly.

image

FIGURE 11-5

The commands are as follows:

  • sqlite3 mydata.sql
  • CREATE TABLE IF NOT EXISTS Contacts (email TEXT PRIMARY KEY, name TEXT);
  • INSERT INTO Contacts (email, name) VALUES (‘weimenglee@gmail.com’, ‘weimenglee’);
  • SELECT * FROM Contacts;

image NOTE Remember to end each command with a semicolon (;). Also, by default, when you launch Terminal, you are in your home directory. Hence, running the sqlite3 application will save your database file in your home directory.

Even though you could use the sqlite3 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering iOS 12 Programming - Third Edition

Mastering iOS 12 Programming - Third Edition

Donny Wals
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9781118144251Purchase book