Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an SQLite database to an iPhone app

I am trying to learn SQLite, and I am building an iPhone app. But I would like to add an SQLite database to my building app. I have got three tutorials, but I am not clear on that code.

How can I add an SQLite database to my building app? What would sample code look like?

like image 903
ashish Avatar asked Jan 28 '09 11:01

ashish


People also ask

How do I access SQLite database on Iphone?

Step 1 − Open Xcode -→ Single View Application -→ Let's name is DBSqlite. Step 2 − Let's develop our UI, Open Main. storyboard and add one text field and two buttons as shown below. Step 3 − Create @IBAction for both the buttons and @IBOutlet for text field and name them btnInsert, btnShowData and name respectively.

Does SQLite work on Iphone?

The database that can be used by apps in iOS (and also used by iOS) is called SQLite, and it's a relational database. It is contained in a C-library that is embedded to the app that is about to use it.

How do you access SQLite using iOS mobile application explain with suitable application?

Let's create a single-view iOS application as SQLiteDemo to start with SQLite operations. Once we are done creating the project, open the Main. storyboard file and add a table view to the View Controller as shown in the below image. To use the table view, we also need to create its outlet in the ViewController.

Is SQLite good for mobile apps?

SQLite is very good for testing. Zero-configuration: SQLite doesn't need any complex set up to store the data. When you build Native applications with Java, it comes integrated with the platform.


3 Answers

First of all you need to create your database.
From the command line create your db file.

sqlite3 mydb.db

Then create the tables within your database

CREATE TABLE tags (id int(5), name varchar(255), created_at datetime, updated_at datetime);

Repeat that for any tables that you want in your database.

Then you need to include the database file in your project. Add the existing database file to your project as you would any other existing file.

Next you will have to link in the framework to interact with the database. This can be found under you current iPhone SDK folder.

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/lib/libsqlite3.0.dylib

Finally you have to include the header file sqlite3.h from

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk/usr/include/sqlite3.h

It should now be possible to write code to access your sqlite database from within your iPhone application.

like image 56
AidenMontgomery Avatar answered Sep 24 '22 08:09

AidenMontgomery


There is lots of information on the web.

Have you looked at the demo application? SQLite Book List This shows examples of common database functions under SQLite. This is effectively using the standard SQLite C APIs.

There are Objective C wrappers which may suite you more. EntropyDB, SQLitePersistenceObjects and FMDB.

I found this Tutorial and this list of resources which may help.

Recently I've been using an ORM SQLite.net It is the way to go for me but then I'm developing in MonoTouch C#.

Tony

like image 36
AnthonyLambert Avatar answered Sep 24 '22 08:09

AnthonyLambert


I'd also recommend looking at FMDB. It makes using SQLite slightly more Objective-C/Cocoa-like. It's not a full ORM wrapper or anything though; it just wraps the C API into something a bit more flavoursome.

like image 6
Daniel Hill Avatar answered Sep 25 '22 08:09

Daniel Hill