Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 31, 2009, 12:24 PM   #1
cromestant
macrumors member
 
Join Date: Apr 2006
CoreData SQLite questions

Hello, i m fiddling with CoreData now, with bindings and such, and its quite interesting to have all done for you ( used to coding with much less help form IDE and frameworks...)

Now my question is in regards to sqlite and the modeling tool.

First of all i limited the type of storage to sqlite, so i m sure its that.

Now i need to create a field in my entities that is autonumerical, which means it automatically increments itself on each insert , is this possible? how would i go about doing this?

Because i m confused as to how this works, i have this set up :
Client entity, with name, telephone and IdNumber.
then i have a Bill entity
which has :
client ( relationship), date, control number

now this works fine, with an interface i am able to add new clients and on another interface i m able to add new bills and list the clients etc..

the question is , how does Coredata manage the relationship? what exactly does he put in the client relationship on the Bill entity? there is no ID, nothing unique.

What i 'd like is to be able to define certain fields as unique keys and even autonumeric.

there is the "indexed" box, but i m still not sure about exactly what the means.

well if you' ve gotten this far, thanks for reading, and hope you can clear this up for me.

Charles.
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.

Last edited by cromestant; Feb 1, 2009 at 10:55 AM.
cromestant is offline   0 Reply With Quote
Old Feb 2, 2009, 04:08 PM   #2
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
Ok, so looking directly into the sqlite file created i can see that there is an index, i am wondering as to how to access it programatically,

something along the lines of finding the next index or something...

I need to be able to see the index and set the starting number etc..
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.
cromestant is offline   0 Reply With Quote
Old Feb 4, 2009, 11:37 AM   #3
Bakerman
macrumors member
 
Join Date: Jan 2005
Location: Sweden
The 'indexed' property just means that the field is indexed. It has nothing to do with autoincremented attributes, which Core Data sadly lacks.

To emulate that feature you can override 'awakeFromInsert' and perform a fetch to find the highest existing value. Take care not to fetch anything that might include 'self', because this may or may not cause your program to behave unreliably.
Bakerman is offline   0 Reply With Quote
Old Feb 4, 2009, 01:30 PM   #4
ChrisA
macrumors G4
 
Join Date: Jan 2006
Location: Redondo Beach, California
Quote:
Originally Posted by Bakerman View Post

To emulate that feature you can override 'awakeFromInsert' and perform a fetch to find the highest existing value.
I don't know much about Core Data but do watch out for concurrency. Think about if two copies of your program are running at the same time. The querry and insert needs to by done as an atomic operation.

In SQL one would use a sub-query like this fragment: "insert ... values( 1+select max(foobar).."
ChrisA is offline   0 Reply With Quote
Old Feb 4, 2009, 02:47 PM   #5
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
Yes, thanks to both of you.

First off, no need to worry about concurrency this program might be used, but it will not be used in a big environment, its mostly a favour to my brother so that he can maintain his clients inorder.

Thanks for the awakeFromInsert i ll give it a try i d though maybe to calculate the value on the awake from Nib method so that i could fill it in directly with the bindings.

i ll give this a try
too bad there is nothing like autonumeric in coredata... sucks..
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.
cromestant is offline   0 Reply With Quote
Old Feb 5, 2009, 03:24 PM   #6
cromestant
Thread Starter
macrumors member
 
Join Date: Apr 2006
how can I do to make a fetch to get the highest value?

I ve tried to find it online but can t seem to find the way to do it.

thanks again

charles.
__________________
unibodyMacbook, 4gb ram, 20gb 4th gen ipod photo, 2d gen ipod shuffle, AEBS, 40gb tv,g4-mini, like 4 keyboards,mighty mouse, 1stgen Iphone.
cromestant is offline   0 Reply With Quote
Old Feb 5, 2009, 03:50 PM   #7
BorgCopyeditor
macrumors newbie
 
Join Date: Jan 2009
Check out NSSortDescriptor's initWithKey:ascending: and then setSortDescriptors: on your fetch request.

Quote:
Originally Posted by cromestant View Post
how can I do to make a fetch to get the highest value?

I ve tried to find it online but can t seem to find the way to do it.

thanks again

charles.
BorgCopyeditor is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
coredata doesn't support iOS7 manga iPhone and iPod touch Apps 1 Sep 25, 2013 11:37 AM
Slow SQLite Query Starfox Mac Programming 3 Sep 10, 2012 12:04 PM
unrecognized selector sent to instance with Coredata and Category of NSMangedObject roeik iPhone/iPad Programming 5 Sep 5, 2012 05:40 AM
Coredata has App base and text files as backend for syncing mraheel iPhone/iPad Programming 0 Aug 8, 2012 10:59 PM
AirPrint CoreData Advice? truehybridx iPhone/iPad Programming 1 Jun 17, 2012 09:50 PM

Forum Jump

All times are GMT -5. The time now is 04:49 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC