Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

realberen

macrumors newbie
Original poster
Mar 12, 2008
7
0
One much-touted feature of the iPhone is SQLite. Super! I'd love to use it. Noob question, though: how do I use it? What classes do I use to access it? I have installed the iPhone SDK and sifted through the documentation, but I can't find any good documentation or samples on how to access it. The closest I get is "just like any other Mac application". Pointers, anyone? Perhaps even a little sample to write foo into the table bar and read it back again?
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
One much-touted feature of the iPhone is SQLite. Super! I'd love to use it. Noob question, though: how do I use it? What classes do I use to access it? I have installed the iPhone SDK and sifted through the documentation, but I can't find any good documentation or samples on how to access it. The closest I get is "just like any other Mac application". Pointers, anyone? Perhaps even a little sample to write foo into the table bar and read it back again?

SQLite on the iPhone is accessed via the standard SQLite C wrapper, the documentation for which can be found on http://www.sqlite.org

This, of course, assumes you have programmed before. If not, you're going to need to do a whole lot more reading before you mess with SQLite.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
Core Data can use SQLite as a data store as well, which is used by Cocoa.

There are prolly some Cocoa wrapper frameworks or better yet sample code (Apple says you can't link to third-party frameworks on iPhone OS) to wrap the procedural C api.
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
Core Data can use SQLite as a data store as well, which is used by Cocoa.

There are prolly some Cocoa wrapper frameworks or better yet sample code (Apple says you can't link to third-party frameworks on iPhone OS) to wrap the procedural C api.

I don't believe that Core Data is currently available on the iPhone.

The SQLite C wrapper is actually pretty simple, I don't think you would get much benefit from wrapping it in additional Objective-C code.
 

realberen

macrumors newbie
Original poster
Mar 12, 2008
7
0
Thanks a bunch, guys. I assumed SQLite would be wrapped in Cocoa on Apple's side, that's why I was confused when I found FMDB and nothing in i.e. Foundation.
 

Monkaaay

macrumors 6502
Jun 19, 2006
258
0
Richmond, VA
So, it seems that using the SQLite header files is "easy enough". Is there any information on how to actually use them in the context of an iPhone application? For example, do we need to have some code in our application that checks for an existing database and creates it on the first run if necessary? Or, is there a different approach suggested by Apple? As the original poster suggested, it would be really nice to see a sample iPhone application that does a simple insert and select against a SQLite database.
 

jalbro

macrumors newbie
Mar 12, 2008
2
0
Also, does the SQLite DB get backed up on the desktop by an iTunes sync?

Can you access it on the desktop, or is it locked up by iTunes?

-Jeff
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
Also, does the SQLite DB get backed up on the desktop by an iTunes sync?

Can you access it on the desktop, or is it locked up by iTunes?

-Jeff

At this point there is no way to sync any data from your own apps to a desktop machine. An SQLite database is just a standard file that will be saved in your applications documents directory on the phone.
 

realberen

macrumors newbie
Original poster
Mar 12, 2008
7
0
At this point there is no way to sync any data from your own apps to a desktop machine.

Right, this is actually my main problem. I would like to have a bunch of PDFs on the iPhone, but I have no idea how to sync it except through webservices (I have webservices working, so no problem there), and I would like to sync directly from the desktop. Hope Apple will fix this in june :)
 

mysticwhiskey

macrumors newbie
Mar 31, 2008
25
0
So, it seems that using the SQLite header files is "easy enough". Is there any information on how to actually use them in the context of an iPhone application? For example, do we need to have some code in our application that checks for an existing database and creates it on the first run if necessary? Or, is there a different approach suggested by Apple? As the original poster suggested, it would be really nice to see a sample iPhone application that does a simple insert and select against a SQLite database.

Apple has some example code for accessing SQLite from an iPhone application here (you'll need to log in with your iPhone developer credentials):

https://developer.apple.com/iphone/library/samplecode/SQLiteBooks/index.html

Like you mentioned, they do actually create the database on first run if it doesn't exist, by making a copy of an embedded database from within the application bundle. To embed the database in the bundle, just add the SQLite database file to the 'Resources' group in XCode.
 

stark

macrumors newbie
Jun 22, 2008
1
0
Hello.

I just started with with objective-c/cocoa/iPhone SDK and trying to get the FMDB wrapper working but when I try and compile a fresh project it says:

error: Cocoa/Cocoa.h not found

Any help would be greatly appreciated.
Thanks.
 

rastersize

macrumors member
Apr 9, 2008
38
0
Hello.

I just started with with objective-c/cocoa/iPhone SDK and trying to get the FMDB wrapper working but when I try and compile a fresh project it says:

error: Cocoa/Cocoa.h not found

Any help would be greatly appreciated.
Thanks.

That's because your supposed to import UIKit/UIKit.h ;)
 

levous

macrumors newbie
Oct 8, 2008
6
0
EntropyDB doesn't work...

There's also an object oriented database for the iPhone: http://code.google.com/p/entropydb/

Beware that this library does not install on the iphone device. The author hasn't yet responded to the reported issues on the google code project page. Be sure to check the issues and ensure he has (at least responded) resolved the issues. I built an entire iphone app against it, expecting the problems to be resolved, and now have to build the entire persistence layer after the fact. big disappointment :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.