1

The app I'm writing needs to get information from a remote database and then store it in the SQlite database on the iphone for offline use. As of now I'm using a php script to query the database and then just basically scrapping the html data from the php echo calls.

My problem is that now that I'm moving away from test data I'm using database tables that are fairly large with complex dependencies. I would really like to not to have to write a parser for these complex files to manually put the data and dependencies into the iphone database.

My question is if there is any way to use a php script to pass to the iphone a copy the actual database file and then just dump that into the SQlite database on the iphone.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
E. Criss
  • 342
  • 4
  • 9

2 Answers2

0

While I'm not familiar with iphone development, it seems to me that you ought to be able to just construct the sqlite database file on the server, and then send it to the device (or have the device pull it down). Of course, this is only efficient if you need to send the whole database every time.

If you need to do things more incrementally (you're just adding some new data to the device's database) why not just have PHP write out SQL statements to make any necessary changes, send those to the device, and have the app execute them?

timdev
  • 61,857
  • 6
  • 82
  • 92
  • Well allow me to clarify a bit then. I need to get very large chunks of the database to do what I need to do. So incrementally is out of the question. I would love to just be able to dump a SQlite database on the iphone but thats exactly what I'm trying to ask about. How can I take a remote database and use a php script to move it to an iphone? – E. Criss Jun 22 '10 at 18:20
  • I don't see why not. Again, I can't answer on the iphone side, but I'd be surprised if you can't grab a file via HTTP and stick it somewhere on the device for use. On the PHP side, you could just construct the sqlite file, and stick it in some web-accessible directory, then have the phone app fetch it. If you're worried about having the file publicly available, you could have a PHP script that passes the data along using readfile(), after making sure the client in question is authorized to grab the data file. – timdev Jun 22 '10 at 18:32
  • Again that is what I'm asking. What do I need to do and what commands can I use to actually download a database file – E. Criss Jun 22 '10 at 18:44
  • Maybe this answer contains a good pointer: http://stackoverflow.com/questions/2066165/how-to-download-large-files-using-objective-c-on-iphone – timdev Jun 22 '10 at 18:51
  • if that answer's not right, try searching SO for "iphone download file". Another answer that looks promising: http://stackoverflow.com/questions/648275/best-way-to-download-large-files-from-web-to-iphone-for-writing-to-disk – timdev Jun 22 '10 at 18:53
0

Make the serverss response XML and bring it into core data that way.

http://code.google.com/p/touchcode/wiki/TouchXML will help you parse the response.

You could also make the server send its response in JSON and use this library, http://code.google.com/p/touchcode/wiki/TouchJSON

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95