PDA

View Full Version : Using UUID as pkey in sqlite db




mraheel
Aug 2, 2011, 02:34 PM
Hey guys,

I wanted to know more about this UUID for iOS.

UUID’s are 128-bit values which are guaranteed to be unique – typically the value is based on a machines ethernet address combined with the current time since October 15, 1582.
UUID’s are string values separated by hyphens, for example, here is how a UUID may look: 13222F23-C76A-7781-0C12-0293E3B34398.

I know some todo app that uses it as a task ID. perhaps suffixing it with their own tag or something.

I wanted to know what are the advantages of using such identifiers in SQLite instead of say a normal integer based / autoincrementing primarykey.

Apparently they are guaranteed to be unique, Can I trace a UUID to something? say date/time created or attach it to some device?

My intention is to use it in an app that has to do with Storage purposes using Sqlite and no, its not another todo app.

any any comment is appreciated. :)



idelovski
Aug 2, 2011, 06:23 PM
I am not sure what is the real question here, but let's assume it was "what are the advantages of using such identifiers in SQLite instead of say a normal integer...?"

Well, for example this comes handy if you need to combine records from two or more sources into a single centralized database.

PhoneyDeveloper
Aug 3, 2011, 07:15 AM
The UUID is unique for each device. Each device has one and only one and no other device has the same one.

I don't see why you would use it for a sqlite db on the device.

It is used by some to identify data sent from users to a server-based db. Some security professionals consider using the UUID in this manner to be an invasion of privacy. Many analytics and ad-servers etc do send the UUID off the device and use it as a unique identifier, behind the back of the user.

chown33
Aug 3, 2011, 10:01 AM
The UUID is unique for each device. Each device has one and only one and no other device has the same one.

UUID is a Universally Unique IDentifier (http://en.wikipedia.org/wiki/Universally_unique_identifier). It's a generated value, and changes each time it's generated. It has a statistically low probability of being generated by another device, or at another time (practically unique).

UDID is the device's Unique Device IDentifier (http://bjango.com/help/iphoneudid/). It's a stored immutable value, that is always the same on each device, but different across devices (guaranteed unique). It's effectively the device's unique serial number.

bbarnhart
Aug 3, 2011, 02:11 PM
There is no benefit in using a UUID or GUID as a key compared to an autoincrement integer.

idelovski
Aug 3, 2011, 03:29 PM
Now I'm lost - are we talking about device id here or about the value returned by CFUUIDCreate() function? At first I was sure it's the later.

CFUUIDRef newUniqueID = CFUUIDCreate (kCFAllocatorDefault);
CFStringRef newUniqueIDStr = CFUUIDCreateString (kCFAllocatorDefault, newUniqueID);

mraheel
Aug 3, 2011, 03:53 PM
Thanks for the input guys.

@PhoneyDeveloper, I got you confused, i should have stressed it. I'm referring to UUID and not UDID as chown33 pointed out.

I don't see why you would use it for a sqlite db on the device.

I know a todo app that uses this UUID with a custom 5 letter suffix.
A UUID is assigned to each task created. Which can be shared via email with another app. They have pushnotification reminders etc.

This app kinda inspired me to ask the utility of UUID.

Im in the process of making similar app with enduser storage management using sqlitedb. Just wanted to make things "future proof" if and when i decide to add certain features. The presence of UUID should make things easier.

I have no clue as to what those features might be!

admanimal
Aug 3, 2011, 05:03 PM
There is no benefit in using a UUID or GUID as a key compared to an autoincrement integer.

There is if you want the keys to be unique across devices, although I'm not sure if it's technically more efficient to use a regular integer as the primary key and have the UUID be another column that you only use when you need to find/compare things across devices.

mraheel
Aug 3, 2011, 06:32 PM
although I'm not sure if it's technically more efficient to use a regular integer as the primary key and have the UUID be another column that you only use when you need to find/compare things across devices.

Thats what I wana find out. I guess it wouldnt be efficient. But how bad could it be?
And again, the benefit? apart from its uniqueness across devices; practically what are its applications?

siggimoo
Dec 2, 2011, 01:28 PM
There is no benefit in using a UUID or GUID as a key compared to an autoincrement integer.

This is untrue. The main point of UUIDs is the lack of a need to consult a central authority in order to generate an identifier. Each party can just make up their own whenever they need to. Sequential values, on the other hand, have to be coordinated. Now whether or not this capability is a benefit to a given system system depends on the needs of that system.