how to fetch data from webserver and store to our database through SQLite - iphone

i want to fetch data from web server and save it in my local database through sqllite.How is it possible.

You can fetch data from webserver using JSON and webservice and then parse the JSON Response string.
Then you may create insert statements from the data obtained and execute it to insert in your database using executeNonQuery method of SQLite.
Best option is to do all this on appDidFinishLaunching so that there would be initial delay but then whole app after that would not face any performance issues i.e. No delays
Hope this helps you.

Well,
it depends on what kind of data you want to fetch. If you want to fetch XML from the webserver, you will get a nice list of xml parsers on this site: http://www.raywenderlich.com/553/how-to-chose-the-best-xml-parser-for-your-iphone-project
Another nice option for fetching any kind of data from the webserver is curl. You can find static libraries on this page: http://code.google.com/p/ios-static-libraries/
Well, there's always the option to use the iOS native libraries, which are documented (with examples) in the iOS SDK.

I would not recommend using "raw" SQLite these days unless you have an exceptional reason to do so. Core Data is the way forward.
I'm not really sure what your question is; it's so broad. But, in general, you'd create an NSURLConnection, download the data, parse the data and store it in your database. Each stage is pretty well documented and there are lots of questions here on each stage.
If you use Core Data there are also some open source projects, such as RestKit, that might give you a good starting point.

Related

Stream coredata to remote REST end-point

There are several apps that I use on my Mac that store their data in core data. I can see the data I want in CoreDataPro. I want that data - specifically I want to send changes in that to some remote end points (such as Zapier, or some other REST service).
I was thinking of piggybacking something like RestKit - such that I provide a configuration file saying where the app is and what end points the data needs sending to. I need only to scrape the data and send to REST, not a two-way sync.
I'd prefer a utility that I could configure rather than having to code a Mac application.
I noted http://nshipster.com/core-data-libraries-and-utilities/ - RestKit still seemed the most capable, but in https://github.com/RestKit/RestKit/issues/1748 I was advised that coredata projects should only be opened by a single application at a time, and really RestKit is designed for baking into the source app (rather than for database scraping and sending).
What approach would you take?
I also noted:
http://www.raywenderlich.com/15916/how-to-synchronize-core-data-with-a-web-service-part-1
Thanks, Martin.
First, Core Data is an object store in memory. What is written to disk from Core Data can be in one of several formats. One of those formats happens to be SQLite. If the application is writing to SQLite then it is possible to sample that same file and push it somewhere else.
However, each application will have its own data structure so you would need to be flexible in the structure you are handling.
RestKit has no value in this situation as you are just translating objects into JSON and pushing them to a server. The built in frameworks do that just fine.
There is no utility to do this at this time. You would need to write it yourself or hire someone to write it.
If I were going to do something like this, I would write it using Core Data itself interrogate the model from the application that wrote the data in the first place and then translate the database into JSON and push it. You won't be able to tell what is new vs. old so the server will need to sort that out.
Another option, since you can't diff anyway, is to just push the sqlite file to the server and let the server parse through it.
Other answers might include:
use a middleware platform e.g. using rssbus.com (only) sqlite connections are free to send the events
as my target system (http://easy-insight.com) actually has a transmitter that sends new records it sees from MySQL abd PostgreSQL, I could https://dba.stackexchange.com/questions/2510/tools-to-migrate-from-sqlite-to-postgresql or use an ETL such as http://www.easyfrom.net (I did ask the vendor for SQLite support a long time ago, but SQLite is just not a priority for them).
I'm wondering whether a good answer (where good excludes Objective-C and includes languages that I do know, such as - to a limited extent - Ruby) is to use MacRuby and its Core Data libraries.
Core Data seemingly can be exposed as an Active Record. https://www.google.com/search?q=macruby+coredata , notably http://www.spacevatican.org/2012/1/26/seeding-coredata-databases-with-ruby/
However, MacRuby seems to have faded - https://github.com/MacRuby/MacRuby/issues/231 - it won't even compile on Mavericks.

Fetch data from JSON server and automatically store in sqlite

I want to fetch data from JSON and store it automatically to sqlite whatever updated on server automatically updates to database whenever program runs.
Can anyone help me out in it. And if my question is not sufficient to answer please ask anything required.
Thanks in advance.
I would look into the RestKit framework. It takes care of the low-level API calls, object mapping, SQLite persistence, etc. It's well documented and maintained.
You can start here http://www.raywenderlich.com/5492/working-with-json-in-ios-5
After reading this, you can user this Class, https://github.com/AFNetworking/AFNetworking. It's easy and usefull!
Download JSON data with AFNetworking and decode with JSONKit, then you can save to SQLite with this wrapper FMDB.
If your supporting iOS 5+ then JSON is added for you by default and can use it using the method given here and after getting the dictionary of objects , you can follow the normal procedure of adding them to sqlite or use core data as said by #Paras Joshi.

Centra DB to IPhone App / Objective-C

I'm trying to find some reading materials on how to connect an IPHONE app to a central DB-Server such as SQL-Server.
I know about SQLite, and the other methods of storing Data in the device itself. What I'm really interested is for the application to interact with a central database server. Are there any sort of objects such as SQLClient in .net or do I need to go through sending off HTTP-Requests and deserializing json/xml?
i dont know the answer to your question, but even if you find that it would be not recommended to do so, since its always better to use an httprequest solution,
Encapsulating the database implementation is always the way to go, since database implementation could change rather quickly adding a layer over it is recommended
That goes without saying that you will not be able to do caching by accessing the database directly, which is also a drawback
am sorry this is not the answer you are looking for, but you should re think on how you are going to implement your solution,
Preform a httprequest to a php script or similar and parse JSON or XML.
You would have to make a REST interface to bridge the 2 together, and as you said deserialize responses depending on the format, if it's json or xml.
From Device side, make GET/POST requests to your script, which responds the query results back to the app and handle them accordingly.

Database in iPhone app development

I'm creating an app for iPhone, and I want it to load data from an external file (from an URL in a server), to display the hints.
I have read several tutorials, but I don't know yet what is more convenient for me:
Do I use CoreData?
Do I create a .sql file and I try to do queries inside the code of my app?
Do I use a .txt file and try to parse it?
Do I use a .xml file?
I have to say I'm quite lost at this point, and I really don't know what would be more effective, easy to write (code). And I don't how to access to a file that is in a server and not in the folder of the app itself.
If your loading data from an external server take a look at Rest Kit. It allows you to map an API to objects that are backed by Core Data. http://restkit.org/
Personally I would use CoreData simply because you get a lot of power out of the box right from Core Data, instead of trying to deal with raw sql queries or parsing data.
Another option if your looking for the simplest way to grab a file from a server and map it to an object is to look at .plists for example:
NSDictionary *data = [dict initWithContentsOfURL:[NSURL URLWithString:#"http://server.com/data.plist"]];
Although be careful with that call though because its not asynchronous, and if the file is large and call is made from the Main thread it will block the application.
The best way to implement database on iPhone SDK is to use CORE Data.
- It prevents you to write long sql scripts to fetch & write data in db.
- Easy Implementation.
- Excellent UI to simulate.
- portable
- Can upgrade later if any enhancement required after some time.
So I would like to suggest you to save your data using Core Data. you need to fetch your data from server & call simple methods to save it into App DB using Core data. You even dont need to do much manipulation into it.
Following are some Nice Links for some tutorials:
http://mobile.tutsplus.com/tutorials/iphone/advanced-restkit-development_iphone-sdk/
http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/

Getting data from remote sql table on iphone

I am a beginner at both iPhone programming and SQL, yet I have basic knowledge of them.
I am planning to do an application that would plot a graph from data taken from a database of the server of my company. I know how to plot, I know how to extract data from an sql table, but what I don't know is how to access the server.
So do I have to go through some kind of oracle-like application ?
This may seem like a very stupid question because it might not even be possible but any answer will be appreciated.
Thanks !
Go through a web service for example a PHP page that returns JSON (or XML, but JSON is easier to parse).
I can highly recommend this tutorial
Once you have your web service, you can use NSURLRequest/NSURLConnection to download the data and use a JSON framework to parse it. Or, if you're using XML you can use NSXMLParser.
See this apple code for more info on downloading using NSURLConnection.
The best way for this will be, using APIs at server end that handle the client request and perform database interaction, so transfer of data among device and server, take place through XMLs that will be secure as well as fast.
It is definitely possible to contact a server (I can't imagine what would happen without that!). What you are looking for is NSURLConnection. Have a look at the example provided by Apple.