Opening connection to SQLITE database on iPhone too slow - iphone

I have created a simple iPhone/iPad app which reads some data from a SQLITE database and shows it on the screen. The database is added to the Xcode project and only needs to be read (not written). In the simulator all this works fine, but when I run this app on my iPhone it is too slow.
I have added some performance profiling to the app, so I was able to determine which part of the app was slow. It appears that opening the connection to the database takes about 0.8 - 0.9 second on the iPhone and about 0.004 second on the iPad. I tested with the SQLLITE framework and also with the FMDB wrapper, but the results were the same.
Why is it so slow on the iPhone? Is there a way to improve the performance?
Thanks,
Danny

How often are you opening it? If you can open it once, and just keep that handle open and reuse it, that would likely solve your problem.
Or is it that this single instance of it opening is too great of a burden?

Related

NSUserDefaults Inconsistency or device inconsistency? - iPhone

I have developed a server based app for iPhone. But according to client requirements and to avoid overloading on server side, i am required to store data on local end. It is all text and typically 2-4 MB in size.
For this i'm using NSUserDefaults instead of sqlite or CoreData.
The app has been tested successfully for around 2-3 months during it's development as well as post development testing and never shown any type of inconsistency in data storage, updation or deletion on any sort of iphone device from iphone 3G - iphone 4S.
Now there is an incosistency issue in the live app, when user leave the app idle on a screen for around 15-20 minutes and doesn't press home button means app is not in the background.
In this case, data seems to be lost.
But as soon as refresh app, in that case data appears again & app starts functioning normal again.
Here lies the main problem that when i'm refreshing, i'm doing nothing but only fetching fresh data from the server it can be simply one to five records or nothing at all.
Then app is refreshed, all of the records are shown & it functions normally.
I have been trying to spot the issue for around 3 days, and it's not happening on my device (iPhone 4S). As far as i can think, it seems to be problem with the old devices.
Previously in testing, none of this happened on old or new devices.
My questions are -
a) Is this an incosistency in my coding?
b) Are NSUserDefaults not trustworthy for database management for live apps?
c) Is it a device version specific problem related to NSUserDefaults?
Anybody faced/facing the problem with NSUserDefaults??
Please suggest me something i can do for this or tell me i have to do all the database work again for the next version using sqlite or CoreData.
Anyhow this is critically important and needs to be fixed.
Any help is appreciated in advance.
As my suggestion for you please introduce the Sqlite database integration because of the when the short size of the data store and of cause it's good rather then the Sqlite but it's not working into large number of the data that time must use the Sqlite or coredata.
so i suggest to use the Sqlite data and coredata.

iPhone Application universal app

I am working on one application and in which I am downloading 2000 images and store some data in SQlite database using connection from server.This works fine in simulator but crash in iPhone device.I am using try..catch for handel error but it simply crash and not display any error.So please help me to run this application in device also.
I have developed an app in which i used to download more than 600 images n each of the image was about 700kb and more, the app was working perfect in the simulator but the performace was poor in the device. As the App was for IOS3, Shark tool helped me out, and the only reason was leakage of memory which i had never expected. To my knowledge, the reason of memory leakage must be the main reason. And do try to have a deep look on how the things are working in the main thread, try to run most og the things in backend.
Regards,
Suhail
But i can help you out for showing the processes taking place in the main thread. and if i am not wrong do go through this post iPhone: Existence of a Memory Leak Profiler?

database in iphone apps

I am new to iphone development. I am currently doing a restaurant app which takes data from a database. How can we store the data in a DB on iphone through our app so that it would even work offline?
You should use SQLite. Since the database is just a file, you can add the 50 MB file to your application, and that's it. SQLite's performance on the iPhone is good, in my experience, although YMMV depending on your exact table layout and indexes.
Just remember to keep a keen eye on how much data you fill it with:
Although 50 MB is way below the limit, be aware that a 50 MB application will take some time to download for people, and people cannot install it from the AppStore without either a WiFi connection or iTunes.
Also, applications that "grow" in size too rapidly after you install them can become unpopular on the smaller devices.
Here is a tutorial
Yes, SQLite is your best bet. Apple uses SQLite a lot in iOS 'internally' (DB for text messages.etc), so Apple must've put a lot of effort into optimising SQLite on iOS.
For Restaurant app, you can also use plist as a database. This is because you will only have a primitive datatypes and will be easy to handle with plist.

How to insert 30,000 record in SQLite database in iPhone it is possible in iPhone simulator not in Device it will crash

Currently i have facing one problem i have to call web service and download the data from the server it is around 30,000 record, it is downloaded via server but when i am inserting record into SQLite
but when start the inserting record in database it will increase the memory to 20 to 150 mb in instrument control and crash the application..
So please give me the solutions for the same..
30,000 sounds like a lot. I'd Do the work in chunks.
Would have to see your code to see what's going on. Run using Allocations or Leaks tool and maybe just run it for 5000 records. See what is using up memory.
Post your code.

Where is the proper place to initialize data in a core data store?

For an iPhone app that has to have a bunch of data inserted before the user can do their thing on first launch, where is the correct place (in the code) to insert that data? I'm looking at between 700 - 800 records total between a few tables.
I initially tried doing it in applicationDidFinishLaunching:. This worked fine for the iPhone 3gs, but caused a consistent first-launch crash on the 3g. After digging into the problem, i found that on the 3g, the app wasn't responding fast enough (presumably because it was busy dumping loads of data into the persistent store), so the OS was killing it under the assumption it was unresponsive.
To fix this problem, I moved the data initialization process out of appdidfinishlaunching and spawned another thread from the first view controller that shows upon launch. This works most of the time, but every once in a while the app crashes with a 134030 error in core data, which according to the apple constants reference, is:
NSPersistentStoreSaveError
Error code to denote that a persistent store returned an error for a save operation. This code pertains to errors such as permissions problems.
This error pops up when calling save: on the managedObjectContext.
Ideally towards the end of development you would populate this data into a Core Data store and add that to your project. On first run, you then copy that store from the app bundle over as the user's Core Data store. This should work for your case.
In the case where this is not possible, one would perform the import on a background thread.