views:

19076

answers:

6

Hi all, i am trying to learn SQLite and i am building an iphone app. but i would like to add SQLite database to my building app. i have got three tutorial but i am not clear on that code. pls send some ideas how i can add SQLite database to my building app. it would be more help if i get code for this.

+8  A: 

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.

AidenMontgomery
Note that, while creating a database on a desktop machine and then copying it into the iPhone app may be an expedient thing to do, it is not necessary. You can create a database, initialize the schema, and initialize data from within the iPhone app.
Kristopher Johnson
+6  A: 

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.

Tony

Tony Lambert
The QuickLite link above takes you to an annoying website that tries to charge you $29 to give you a recommendation about what SQL wrapper to use. The link is a waste of time, avoid it.
Dan J
it never used to.... I'm removing it now.
Tony Lambert
and it's gone forever.
Tony Lambert
A: 

http://sqlite.org/docs.html is a good place to start.

You might get more useful help if you are more specific about what you are trying to do, and what obstacles you are encountering.

Kristopher Johnson
A: 

CoreData should help, but I can't find it anywhere in the list of importable Frameworks.

You could take a peek at the iPhone examples, especially the SQLite Book List example.

jopes
CoreData isn't available on the iPhone.
Daniel H
CoreData is available with the SDK 3.00 beta.
Tony Lambert
+4  A: 

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.

Daniel H
A: 

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.

How do you find the sqlite database and all tables?

HOW do you "include" them into my app?

What folder inside my bundle should they be put into?

HelenJ