Using UUID as pkey in sqlite db

Discussion in 'iPhone/iPad Programming' started by mraheel, Aug 2, 2011.

  1. macrumors regular

    Joined:
    Apr 18, 2009
    #1
    Hey guys,

    I wanted to know more about this UUID for iOS.

    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. :)
     
  2. macrumors regular

    Joined:
    Sep 11, 2008
    #2
    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.
     
  3. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    UUID is a 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. 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.
     
  5. macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #5
    There is no benefit in using a UUID or GUID as a key compared to an autoincrement integer.
     
  6. macrumors regular

    Joined:
    Sep 11, 2008
    #6
    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.

    Code:
       CFUUIDRef    newUniqueID    = CFUUIDCreate (kCFAllocatorDefault);
       CFStringRef  newUniqueIDStr = CFUUIDCreateString (kCFAllocatorDefault, newUniqueID);
    
     
  7. thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #7
    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 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!
     
  8. macrumors 68040

    Joined:
    Apr 22, 2005
    #8
    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.
     
  9. thread starter macrumors regular

    Joined:
    Apr 18, 2009
    #9
    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?
     
  10. macrumors newbie

    Joined:
    Dec 2, 2011
    #10
    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.
     

Share This Page