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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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-10-2011, 10:40 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default Sqlite design approach

Hey, to make it clear this is not about how to make a sqlite file. It's more about what steps to take to make the SQL backed app future proof

To make my question simple, an example I wana use is to make a todo app. (it's not that actually) Here's what I want to do: Add new todos, Edit todos Share todos via(email , social sites) Import todos Export/backup todos

Every new added todo wil have primarykey or ID in sqlite. Resetting or deleting todos. I don't want the pkey to auto increment. If a new todo with pkey 2 is created and the deleted, then the 2 pkey will remain unused and over a long period, there may be IDs in 3 digits.

I need a way to make IDs with fixed number of digits and kinda unique to the device.

I'm confused what mechanism should I work out. Any help is appreciated.
raheel is offline   Reply With Quote
Old 02-11-2011, 04:28 AM   #2 (permalink)
@alexeckermann
 
alexeckermann's Avatar
 
Join Date: Jan 2011
Posts: 36
alexeckermann is on a distinguished road
Default

Not sure why using an incrementing key is bad. Why do you also want to also make it unique to the device?

Just sounds like maybe its just a requirement that is just a bit over the top?
alexeckermann is offline   Reply With Quote
Old 02-11-2011, 05:18 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default

If you consider that alot of entries will be added and many can be potentially deleted, i wanted the pkeys not reach big numbers unnecessarily.

example, if a row with primarykey 91 was deleted, i'd want the new entry to fill that spot and then proceed further.

Your right though, the requirement is kinda over the top. I tell myself that too.
raheel is offline   Reply With Quote
Old 02-11-2011, 05:41 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

Sqlite uses a 32 bit integer to store Pk's. That's VERY large. If you ever reach this number, sqlite automatically finds an empty (previously deleted) PK and use it.
nobre84 is offline   Reply With Quote
Old 02-11-2011, 06:09 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

Our you could use GUID, they are unique.
__________________
If my answer helped you, you might want to help me.
Make a donation via PayPal.
TUX2K is offline   Reply With Quote
Old 02-11-2011, 11:52 AM   #6 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

SQLite actually uses a 64 bit signed int for row ids. So if a user were to create and delete a record every second, 24 hours a day, 365 days a year (and even 366 days a year on leap years) it would take many billions of years before SQLite would need to try to reuse old row ids.

However, if you tack AUTOINCREMENT onto the end, SQLite doesn't ever reuse old rowids. So you might want to keep that in mind; otherwise you might have some very angry users a few hundred billion years from now. They would likely change their five star reviews to 1 star reviews and demand their money back.

I am curious about your comment about wanting ids to be unique to the device. Are you planning on doing some sort of migration/syncing (that is, where you need to always remember where a certain record originated)? If so, you could just pair the rowid with the device UUID for cross-device uniqueness. If you just want to share records but don't need to forever track where they came from, then this won't matter, though.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 02-13-2011, 05:33 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 109
raheel is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
SQLite actually uses a 64 bit signed int for row ids. So if a user were to create and delete a record every second, 24 hours a day, 365 days a year (and even 366 days a year on leap years) it would take many billions of years before SQLite would need to try to reuse old row ids.

However, if you tack AUTOINCREMENT onto the end, SQLite doesn't ever reuse old rowids. So you might want to keep that in mind; otherwise you might have some very angry users a few hundred billion years from now. They would likely change their five star reviews to 1 star reviews and demand their money back.

I am curious about your comment about wanting ids to be unique to the device. Are you planning on doing some sort of migration/syncing (that is, where you need to always remember where a certain record originated)? If so, you could just pair the rowid with the device UUID for cross-device uniqueness. If you just want to share records but don't need to forever track where they came from, then this won't matter, though.
thanks for the explanation. I guess this is what im looking for.

UUID seems interesting. I want to todos to be shared across devices via sync or export via email or just share it with friends. However, im not sure if i'd want to track where it came from. Its just a question of "if i'd have a use for it some time in the future with more added features".
i know of some apps that do use this UUID.
they store it like {appname}XXXXXX-XXXX-XXXX-XXXXXXX where XX=UUID
They do have a rowid.

Gotto look into this more.
raheel is offline   Reply With Quote
Reply

Bookmarks

Tags
sqlite

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: 373
14 members and 359 guests
blasterbr, buggen, Clouds, dre, EvilElf, jeroenkeij, jimmyon122, Mah6447, n00b, nyoe, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,900
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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