How to Create Sqlite database for IOS Application in efficient way? - iphone

I have built an android app and now its time to built an IOS app. I am very new to IOS App development. I managed to done all the UI design parts and i am coding the backend part. In my application i am using Sqlite database and has many View Controllers each View talks to database. So i would like to have one Class(Java) which take care about the creating,inserting,deleting etc. If i need to get data from database then i have to call that class to access the database. Is there any way to do like this.
Or
I would like to know how to create sqlite database in a efficient way. Because my app fully based on database.
Thanks for your help guys.

There are two main ways to create a database:
Use CoreData. In this case you should read manuals on CoreData, it is pretty complicated. But if you plan to use iCloud in future, I recommend you to use CoreData.
Create db manually and not use CoreData.
The most efficient way in second case is to use a database manager for SQLite. For example, SQLite manager extension for Firefox.
There are more programs for this, but this is free one, that I use myself.
To work with database use FMDB wrapper over SQLite.
Nice tutorial for second approach.

Related

Storing and retrieving data from MySQL or other databases

I've been researching now for couple of days about this matter but with no luck.
I am learning iOS development with the plan of developing iPhone app mainly. Now this app will mimic the behaviour of my PHP site.
The question: Can I interact from my iPhone app directly with my tables to load and/or insert new data? if not mySQL then which database is used to host the data for CRUD operations? JSON objects? if yes, then how?
As you can see I am really unaware of the way and hope that some light should be shed on storing and retreving data from existing database or what I need to host new database to use with iPhone.
The "best" and easiest way (for me anyway) is to use CoreData.
CoreData is a data management system. You set up some objects and relationships in it and then interact with those (use fetch requests to retrieve them and stuff).
CoreData then manages a datastore (most often a SQLite DB) which it uses to store the objects and relationships etc...
Using CoreData removes the necessity of a DBA and a lot of the complex DB logic and stuff.
A good tutorial to look at is this one...
http://mobile.tutsplus.com/tutorials/iphone/iphone-core-data/
I bought this book though...
http://www.amazon.co.uk/Pro-Core-Data-Professional-Apress/dp/1430236566/ref=sr_1_2?s=books&ie=UTF8&qid=1358773284&sr=1-2
and found it extremely useful for everything from starting out to the more advanced stuff.
When used properly, CoreData makes it VERY easy to use and manipulate persistent data.
YES, You can interact from your iPhone app directly with your tables to load and/or insert new data; Check the next tutorial - interact with your MySQL/PHP server http://www.scott-sherwood.com/ios-5-uistoryboards-a-practical-example/
CoreData is good but limits to access to just iDevices.
I use couchdb, means a copy is stored in the cloud with auto syncing between cloud and devices allowing for web updates and also Android

Using SQLite on the iPhone: do I have to read the entire database and store it into an array?

Hi I am a newbie to iPhone programming. I have been looking at some tutorials online for using SQLite on the iPhone.
From what Iv'e seen, one has to read the entire database in the app delegate method and then store the contents in an array. This is then used to populate a UITableView.
I was wondering how this can be efficient? I mean, if you are going to store the contents of your entire database in memory why have a database?
Is this standard practice?
Instead of this, if I use Core Data, I can set the paging size and it will optimize how much data is stored in memory and only read whats being shown within the visible cells.
Is there anyway, In can have the same functionality using SQLite? so its easy on memory. I mean my database has only 300 entries now, but what if in the future it has 3 million?
Can some one please assist me in understanding this....
Are there any tutorials for SQLite that show how to do it in an optimized way?
Thanks
I would suggest using Core Data. It's extremely powerful, better supported than a SQLite table, and not as complicated as it looks, it just uses a lot of "managed object" jargon which can be daunting at first. Check out the CoreDataHelper class, and a few tutorials. I was able to get Core Data working in a few days (in my first ever app) using the links in my comment
If you're familiar with SQL, basically Core Data works like this: the Persistent Store IS a SQLite table, but you never access it directly; the managedObjectContext is where you do all the data work in your program (and don't forget to save it to the persistent store!), while an Entity is a table, attributes of that entity are your columns, and a managed object is a row.
Further Reading:
Core Data Tutorial - YouTube
Core Data Tutorial: Getting Started | Ray Wenderlich
iPhone Core Data: Your First Steps
Here is some tutorial that may help you:
iPhone Programming Tutorial.
I recommend you consider using core data instead of sqlite.

CoreData or Sqlite which should be used in iphone application for local storage of data

I want to develop an iPhone application. On which i have to use DB to store data locally.But i am confused about whether i should use Sqlite or Coredata.My application has a centralised database and i am taking data from that DB using Web service.
Well, sqllite works quite well and is what CoreData uses behind the scenes anyway. But if you don't already know SQL, it can be complex to use.
CoreData is sort of easier to start, but complex to figure out how to work. It performs better though.
In the end you are probably better off learning CoreData and proceeding that way. Just don't do ANYTHING with CoreData in background threads until you are comfortable with how it works already, as that is a whole added layer of complexity fraught with peril.

Which database should you use to program an iPhone/iPad application?

I am new to iPhone development and want to know which database you use to program an iPhone/iPad?
I have heard its SQLite, are there any alternatives to this?
The application I am programming is like an online shop however you can't buy products, only view their details.
You should use CoreData for that. CoreData is a database abstraction layer which uses SQLite to store your data. Or you could use SQLite directly. But I would prefer CoreData.
Core Data Programming Guide
Core Data Overview
If you have any plan to use the database file outside iPhone e.g. in other computer, or data input program to populate data, then SQlite is the best choice. CoreData modify the fields name when you create the database inside XCode. But if the data is only accessed by your app in the iPhone, best choice is CoreData.
If you want to run complex sql query then sqlite is better. Read about NSPredicate, what type of query you can do there.
SQLite is the master choice here!
As an alternative, I would suggest you the simplicity of an XML file.
You can also use NSUserDefaults if u have less data to be stored in your database.
http://icodeblog.com/2008/10/03/iphone-programming-tutorial-savingretrieving-data-using-nsuserdefaults/
If the data to be stored is more then go for sqlite

How to write Data Base application in iPhone

Hi I am create an iPhone app, which will use SQLite as database. This database is synchronized by websever by XML HTTP request. The problem is, I don't have pre-build architecture for creating database app.
Is there any tutorial which will guild me how to write Data Access Layer(DAL) or how to import SQLite file with iPhone in secured way.
I dont want to open database connection again and again, its like creating a single class which will handle all database related part.
Please suggest me.
Thanks
You just described something that Apple calls Core Data. See this link for some more details
http://cocoadevcentral.com/articles/000086.php
It does describe Core Data on the desktop but it is essentially the same.
Core Data is a pretty light wrapper for SQLite written by apple. Core data once you have your base code in place you will find it pretty easy to work with.
The other big win with Core Data is that it has a small memory foot print which is important to make sure your application performance optimal.
I would first start with some sample code, core data is going to take a few hours to get started and few days to weeks to learn but once you are past this you should find it very handy and powerful.
John.