views:

627

answers:

2

Hi,

I want to use core data in my application with back end Sqlite store.

But I need the Primary key (auto inc Integer) value after an insert which I want to send this primary key value to a web server.

Is there any way to get the primary key of the record from sqlite database through the core data feature ?

I don't want the unique ID of NsmanagementObject ObjectID

Thanks, Sridhar

A: 

use sqlite3_last_insert_rowid(sqlite3*) function ))

oxigen
Core Data abstracts the back end away. It doesn't allow you to get the underlying database because (1) there may not be one and (2) even if there is, its schema is a Core Data implementation detail anyway.
Peter Hosey
+1  A: 

You can't get the primary key of the Core Data table - it is abstracted away on purpose.

If you need some kind of externally addressable identity attribute, you could roll your own, though it's not clear why you don't want to use the NSManagedObjectID, which is the closest thing to an 'ID' column in Core Data-land. There is a category that allows it to be easily transformed into a URI that can be stored external to the application.

If you want to roll your own, plug into the NSManagedObject lifecycle methods like willSave, etc...

Hunter