Sync Sqlite database with iCloud? - iphone

I have an application which is already on app store and it use Sqlite Database. Now i want to make another version, which include iCloud sync, now ,the question is ,IS there any tutorial or third party code of syncing sqlite database with iCloud ,as i searched a lot but didn't get any useable answer??
Thanks in advance.

SQLite and iCloud do not mix well. Although it's possible to use the iCloud file APIs to put a SQLite file in iCloud, doing so is almost guaranteed to corrupt the file. SQLite wasn't designed with this kind of use in mind, and between external journal files, uncommitted transactions, etc, it's not even a question of whether the file gets corrupted, only of when (and the answer is "very soon").
Although Core Data can use both SQLite files and iCloud, it doesn't sync the SQLite file. Instead it has a scheme that uses transaction logs to send changes back and forth.
If you want to use your existing data with iCloud, you'll probably have to do something similar. I don't know of any good reference implementations. Basically, you'll need to export your data to some other format, and detect and import changes from other devices.

Related

how can I use same sqlite data on more than one iPhones

I have implemented an App which uses SQLite database, now if I run the App on a device then the database exist in that device only, now I want to use the same data on more than one device, can I do that?
You could use iCloud to copy your DB between devices. There are three ways you could do this.
Implement all the file presenter coordination code by hand. This would be difficult, but your existing read/write code would stay the same.
Wrap your DB in a UIDocument. This would be much easier, but your existing code to save and load your sqlite file would need to change. Conflicts would be resolved at a per-database level.
Port your DB code to use Core Data and use a UIManagedDocument. Your entire codebase would change, but conflicts would be resolved at a much lower level.
I heartily recommend Ray Wenderlich's tutorial series on iCloud, Beginning iCloud and iCloud and UIDocument: Beyond the basics
You need a Database Server to store your data & a Web service which should have the logic to store/fetch data from the Database-Server & Back to Database-Server. You can communicate between the DataBase Server & the Android Device using that Web Service.
On Android side you can use KSoap to consume the web service. See this example here.

Any FREE SQLite Manager for MAC OS X?

I am learning Core Data for iPhone application. I defined .xcdatamodel. But I have the following questions:
Is it possible to make .sqlite file
from the .xcdatamodel file ?
If not, what is the correct
procedure to prepare .sqlite ?
If it is necessary to use external
tool, is there any FREE tool to make
.sqlite ?
Thanks.
Your questions 1 & 2 have already been answered but here's a comprehensive overview for Q3:
http://www.barefeetware.com/sqlite/compare/?ch
I personally use a (free) Firefox add-on called SQLite Manager - you can download it from here https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Is it possible to make .sqlite file
from the .xcdatamodel file ?
Well, when you create a Core Data stack and set your store to an SQLite store, the persistent store coordinator will create a .sqlite file configured for the model attached to the store.
If not, what is the correct procedure
to prepare .sqlite ?
Before iOS 3.0, you couldn't use Core Data so there were several libraries out there for using SQLite. However, I don't think any of them have been updated because there is not much point when using Core Data.
If it is necessary to use external
tool, is there any FREE tool to make
.sqlite ?
SQLite comes standard as part of MacOS X so you can use the command line or scripting languages like Ruby, Python, Perl (also standard) to create any SQLite database you want.
But honestly, I wouldn't bother. Unless your app's data is very simple and largely static, you will end up reinventing the wheel and effectively reproducing most of Core Data just to interface SQLite with the rest of the app.
Core Data's SQLite structure really isn't designed to be handled by anything other than Core Data. Even if you have your persistent store use the SQLite data format, if you open it in a generic SQLite tool you're going to get a cryptic mash of nothing-you-can-reliably-mess-with.
I'm guessing your goal is to have pre-populated data in your database? The right way to do that is to write some “importer” code that reads in whatever existing data you have and creates objects in the persistent store corresponding to those. Keep a copy of that persistent store—maybe in your app bundle, to be copied out to a temporary directory for writing—and you've got yourself a starting data set.

How can I make permanent the custom data I have manually put into my core data database?

Ok, I am admittedly pretty new to core data, and am still not quite as knowledgeable as I would like to be. I am doing some pretty basic data retrieval from the database using values that I went in and added myself (using the sqlite editor Base).
I got everything working in my simulator, and I thought that life was just dandy but I went in and installed the app on my 2g iPod touch, and when my pickerview went to go get data...there wasn't anything there! I guess it's not terribly surprising, but I was thinking that the app build would just copy the db that I had setup??
What is going on? What do I need to do to make it so that the pre-loaded data is available for any and all downloaders of my app?
Thanks!
The core data persistent store won't get automatically added to your app. You will need to add this file to your project so that it becomes part of the app bundle when you build the app. You can see what will happen in xcode after you've added this file under your target settings.
Additionally apple discourages modification of the SQLite data store directly outside of core data. You may be better off just using SQLite in that case. If you feel you really need core data, you may want to make a default SQLite database that is part of your app. The first time the app is run (or the data is reset) you can then import that data into your user's custom core data persistent store. See this portion of apple's documentation on how to import an existing SQLite database into core data. This allows you to have default data but gives you the flexibility of being able to reset the database easily.

Creating .sqlite file from Core Data store?

I've seen tutorials in books and on websites that offer .sqlite files for download. The sqlite files are used for Core Data.
How do I get a .sqlite file FROM an app or core data store on TO my desktop?
If you are going to create a pre-populated sqlite file to be used with Core Data then you must create it with Core Data. It is trivial to create a basic desktop application for data entry and use that to create the file and then embed it in your iOS device.
Do not attempt to duplicate the data structure or linkage within the file by hand. You might get it to work but you will spend way more time trying to get it to work and it is going to eventually fail. The internal structure of a Core Data sqlite file should be considered like a private API. The structure is not public and can change without notice.
If you are specifically trying to create a Core Data store, you use this method:
NSPersistentStoreCoordinator
addPersistentStoreWithType:(NSString*)storeType
configuration:(NSString*)configuration
URL:(NSString*)storeURL
options:(NSDictionary*)options
error:(NSError**)error
You must have already associated a NSManagedObjectModel with your persistent store coordinator object. If the store at storeURL does not exist, it will be created; otherwise it will be opened.
These might help: http://www.sqlite.org/cvstrac/wiki?p=ManagementTools
I like to use this Firefox plugin:
https://addons.mozilla.org/en-US/firefox/addon/5817/
You can create a new .sqlite file, change existing databases, and browse through your data.
There's a command line program download-able from sqlite.org (in the standard download) that can be used to create a blank database with a schema. Usually the database file is compatible across operating systems and devices.

Are there good iPhone SQLite3 tutorials which really start from scratch?

I always find something that starts somewhere in the middle, where the database already exists or where some special classes or files have already been added to the project. I want to see the first steps, since they're crucial. i.e. somebody said the database has to be copied into a readwriteable dir on the iphone. Anyone knows a complete tutorial on this?
(no, I don't want to use Core Data or OS 3.0)
You might consult these other similar questions:
"iPhone create SQLite database at runtime?"
"Where’s the best sqlite3 tutorial for iPhone-SDK?"
"Add SQLite Database to iphone app"
Additionally, the SQLiteBooks sample code that Apple provides takes you step-by-step through the process of copying an existing database from the resources directory of your application bundle to the application's Documents directory. It is a little more complex when working with the database, however.
Mobile Orchard also has a list of resources for SQLite on the iPhone.
The source code to my iPhone application Molecules is available, and for now it uses SQLite as a data store (that will be changing to Core Data soon). You may be able to pick something up from that.
What about SQLite Persistent Objects? I used it on my last project and it was cake.
http://iphonedevelopment.blogspot.com/2008/08/sqlite-persistent-objects.html
http://www.galloway.me.uk/2009/02/sqlite-persistent-objects/