tags:

views:

3870

answers:

3

I'm developing an iphone app that uses the built in sqlite db. I can view the db when running the simulator but how do i access the db instance on the physical device?? Any help is greatly appreciated.

FYI: i'm trying to view the open the db via the sqlite3 command line so I can execute arbitray sql against it. For the simulator, I can view the .sqlite file at: ~/Library/Application\ Support/iPhone\ Simulator/User/Applications/ ... but how can I see that file on the physical iphone?

FYI2: I'm trying to profile a db running on the physical device. The simulator does not work for me as this app uses Core Location data to run.

+1  A: 

Exactly in the same way you do on the simulator. There are very few (important) differences between the device and simulator, and file access and library loading are for the most part not part of them.

millenomi
thanks millenomi ... i updated my question to better express my problem. any ideas?
Keith Fitzgerald
+7  A: 

In Xcode select window->organizer and expand the node next to your application in the applications section on your phone. Select the black downward pointing arrow next to application data and save the file anywhere on your desktop. Your sqlite database should be in there somewhere.

As for how to go about getting it back on the phone once your done i have no clue.

Lounges
A: 

Your question remains a little vague. "See" in what sense? Do you create the SQLite database? How? Have you placed it manually in the Simulator's filesystem area? Are you perhaps asking how to do that on the iPhone?

The easiest way is to precreate an empty database with the sqlite3 command-line tool, have it as a resource in your application, then copy it in your application sandbox's documents folder. You can get the path to your resources folder via NSBundle's pathForResource:ofType: method, then grab the path to your Documents folder via NSSearchPathForDirectoriesInDomains() for the NSDocumentsDirectory folder in the NSUserDomainMask, then copy the file via NSFileManager's methods.

Otherwise, you can use SQLite's functions to create a new database from scratch by supplying appropriate SQL commands to define its schema.

millenomi
added another comment. thanks again for getting back to me.
Keith Fitzgerald