From: Chuck Hill <email@hidden>
To: Shravan Kumar. M <email@hidden>
Cc: WO Dev Group <email@hidden>
Sent: Sun, November 1, 2009 9:34:31 AM
Subject: Re: how to insert records in database in the order of insertion to EC
On Oct 31, 2009, at 8:46 PM, Shravan Kumar. M wrote:
> Thanks so much for your quick response Chuck.
>
> We use Frontbase. I have no FK issue here. It's just that the objects should be inserted to DB in the order I have created and inserted into EC.
>
> Why EC saveChanges() operation just not save the objects in the order of insertion??? Isn't it simple? I believe EC maintains an array insertedObjects(), so it should just follow that array order, unless otherwise any constraints as you have mentioned!!! Just trying to understand the mystery behind the complexity :)
For what you want, it would not matter if it did. The defined order of records in an un-ordered Select (a select with no Order By clause) is indeterminate. The database is free to change the order of such result sets to return the result set in the shortest amount of time or any other reason it might have.
> If there's no
built-in solution, then probably adding a "sortOrder" field to my table would fix this issue.
That is the ONLY solution you can depend on.
Chuck
> From: Chuck Hill <
email@hidden>
> To: Shravan Kumar. M <
email@hidden>
> Cc: WO Dev Group <
email@hidden>
> Sent: Sun, November 1, 2009 8:49:54 AM
> Subject: Re: how to insert records in database in the order of insertion to EC
>
>
> On Oct 31, 2009, at 6:57 PM, Shravan Kumar. M wrote:
>
> > Hi Group,
> >
> > Could any one please advise me how can I insert records in database in
a specific order or as per the order of insertion of objects to EditingContext
>
> AFAIK, you can't. The order of insertion is not tracked.
>
>
> > for eg:
> >
> > I have inserted objects to EC in the following order: A1, A2, A3, A4, A5 (and then saved the EC once - editingContext.saveChanges())
> > But, when these got saved to database the order is disturbed and is not guaranteed i.e., I see following order sometimes: A2, A5, A1, A3, A4, whereas I want the order of these objects as I have inserted to EC.
> >
> > I heard that we can do something with AdaptorOperations, but not sure of that exactly and am trying to see if we have an higher level API for that. (Just a note: We do not use Wonder to the fullest, of course we use Wonder API's as required.)
>
>
> If your problem is FK constraint violations, make the constraints DEFERRABLE INITIALLY
DEFERRED when you create them.
>
> If you are using MS SQL Server, then you are in a world of hurt. It includes not supporting deferrable constraints in its set of unsupported yet highly desirable features. There is a reason why people mock that "database". You can order the operations using EOF but (a) is isn't easy and (b) you can't expect to know the order of insertion and (c) I can't think of many useful examples to follow. You could start with the source for myhttp://www.global-village.net/chill/ms_sql_server_eof_plugin>
>
> Chuck
>
> --Chuck Hill Senior Consultant / VP Development
>
> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific
problems.
> http://www.global-village.net/products/practical_webobjects>
>
>
>
>
>
>
>
>
--Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects