• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Looking for an update foo set bar = bar + 1 solution for WO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking for an update foo set bar = bar + 1 solution for WO


  • Subject: Re: Looking for an update foo set bar = bar + 1 solution for WO
  • From: Sam Barnum <email@hidden>
  • Date: Fri, 17 Aug 2007 14:07:01 -0700

You might consider using a trigger. I personally have never used them, but this sounds like a reasonable place to do so.

On Aug 17, 2007, at 10:36 AM, Chuck Hill wrote:

Hi Pierre,

On Aug 17, 2007, at 5:38 AM, Pierre Bernard wrote:

Hi Chuck!

You might want to simulate this using an attribute with write format that contains SQL to do this. E.g. something along the lines of "COLUMN + %V"
In your code you would set the special attribute's value to the increment you want. On the next commit it would do the stuff.


The problem is that your real attribute would go out of sync and that your fake attribute would apply the increment on each commit.

I am not so worried about that. It will go out of sync any way as other instances are also updating the database.

You could also try dynamically adding the attribute in an editor to the editing context and remove it once saveChanges went trough.

I considered this, but I see a potential problem. In the update would be both set foo = 367, foo = foo + 1. I am not sure if that is legal SQL (same column twice) and even if it is, the order of execution is probably undefined. I guess I could just not update the foo attribute so that it would not appear in the update and just set fooOffset. Still the idea makes me uncomfortable and then there is the problem of adding / removing this attribute. Hmmm, there is maybe another problem here too. After the first update, EOF would have a value of 1 cached for fooOffset in the snapshot. That would make it not generate that attribute in the update if I again tried to increment by 1. I would need to invalidate the object after saving.


I think what I really want is to get the offset into the row diffs that are in EODatabaseOperation. These diffs are used by EOSQLExpression when adding the attributes to the update statement. I could easily do that with an EODatabaseOperation subclass, but there is no easy way to get EODatabaseContext to use my sub-class. I could create an EODatabaseContext.Delegate and implement

databaseContextWillOrderAdaptorOperations(EODatabaseContext dbCtxt, NSArray databaseOps)

And substitute my own EODatabaseOperation subclass. I would then need to get EOF to use my EOSQLExpression sub-class as well. That will also be an annoyance as it is DB specific so I would need one for each database. This path is looking less promising.

I think what I will end up doing is creating a method like

public static void applyOffsetToAttribute(EOEditingContext ec, String entityName, String attributeName, Number offset)

or perhaps finding one in Wonder.  I wonder....

When foo is updated, I would set an instance variable to snapshot value - current value. Then, using the CooperatingEditingContext, implement the didSave() method to check this instance variable and, if not null, call applyOffsetToAttribute and set it to null.

Much fun.

Chuck



On Aug 16, 2007, at 11:53 PM, Chuck Hill wrote:

I recall someone making something that did this, but now I can't find it. I don't even recall how it worked. What it did was allow WO to update an attribute of a entity using bar = bar + 1 instead of bar = 7 so that updates from multiple sources would not step on each other.

Does this sound familiar to anyone?

Thanks!

Chuck

--

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






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden

- - - Houdah Software s. à r. l. http://www.houdah.com

HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend





--

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






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40360works.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Looking for an update foo set bar = bar + 1 solution for WO
      • From: Chuck Hill <email@hidden>
References: 
 >Looking for an update foo set bar = bar + 1 solution for WO (From: Chuck Hill <email@hidden>)
 >Re: Looking for an update foo set bar = bar + 1 solution for WO (From: Pierre Bernard <email@hidden>)
 >Re: Looking for an update foo set bar = bar + 1 solution for WO (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Looking for an update foo set bar = bar + 1 solution for WO
  • Next by Date: Re: Looking for an update foo set bar = bar + 1 solution for WO
  • Previous by thread: Re: Looking for an update foo set bar = bar + 1 solution for WO
  • Next by thread: Re: Looking for an update foo set bar = bar + 1 solution for WO
  • Index(es):
    • Date
    • Thread