Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-12-2009, 01:27 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 48
Default is sqlite overhead expensive?

I'm thinking of populating a UITableView where each cell is a row from a database table.

The way I learned to interact with the sqlite3 database is, for each call, I'd go through a series of steps including opening the database, doing the select, closing the database and releasing the things that need to be released.

Since each screen will show several rows (when things get populated) I was wondering if, instead of re-opening the database for each row (in the cellForRowAtIndexPath method), I were to get all the data in one go and save it in a dictionary.

The tradeoff is that, if things are edited and I'm using an intermediary dictionary rather than directly with the database, then I have to do the bookkeeping, sync it up with the database, etc.

I read the posting on the efficiency but I'm not referring to the size of the data or access speed, just the overhead of setting up and cleaning up for even the simplest call and whether those are considered expensive enough computationally so that batching them up and saving them in a low-overhead data structure would make sense.

Or, maybe I shouldn't do the opening/closing in cellForRowAtIndexPath but somewhere else (like viewDidLoad and viewDidDisappear)?

Any thoughts?
cybohemia is offline   Reply With Quote
Old 02-12-2009, 01:38 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 53
Default

I don’t know what the overhead is, but I can presume it’s less efficient than the method I use in my app. Here are my suggestions:
-Retrieve all of the data from the database when the view loads. Don’t do it individually; make a select for all of the information you need.
-Store the information in an array or a dictionary. When the table is being loaded, have the cells refer to the array instead of making queries to the database.
-Create a new type of object for your data. Instead of handling the edit/delete from the table view, send messages to the object and handle the database “stuff” there.

Hopefully that’ll get you started on the right foot.
-Chasen
rendezvouscp is offline   Reply With Quote
Old 02-12-2009, 12:50 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 48
Default

Thanks, Chasen - I was definitely thinking the technique I learned seemed a bit inefficient!
cybohemia is offline   Reply With Quote
Reply

Bookmarks

Tags
database, efficiency, sqlite3

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 264
20 members and 244 guests
2WeeksToGo, @sandris, AdamL, ADY, BrianSlick, Dani77, diyora, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,748
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0