db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: insert / update on duplicate key question...
Date Fri, 18 Feb 2005 07:00:50 GMT




Hi Aaron

I would guess that if you do not use an object cache,
(torque.useManagers=false, this is the default), the mere act of saving
should be no problem because the different object do not know of each
other. I d not know what happens if you use the cache.

What WILL be problematic is if you have one of the objects in memory which
gets its id updated, and save it afterwards. In my experience, it is never
a good idea to update an id after the object is created, because the id is
there to identify the object uniquely (and this is what Torque implicitly
assumes, so you might run in problems in unexpected places). If you need to
change that particular number in your row (because it has a special
meaning, I guess), do not use it as id but create a new id which never
changes once the object is created.

   Thomas

Aaron Loucks <aaronl@GardnerInc.com> schrieb am 17.02.2005 15:58:01:

> Is it possible to perform an update on a row with .doInsert() if the new
> record would cause a duplicate value for the primary key?
>
> Basically I want to do something like this:
>
> If you specify the ON DUPLICATE KEY UPDATE clause (new in MySQL 4.1.0),
and
> a row is inserted that would cause a duplicate value in a UNIQUE index or
> PRIMARY KEY, an UPDATE of the old row is performed. For example, if
column a
> is declared as UNIQUE and contains the value 1, the following two
statements
> have identical effect:
>
> mysql> INSERT INTO table (a,b,c) VALUES (1,2,3)
>     -> ON DUPLICATE KEY UPDATE c=c+1;
> mysql> UPDATE table SET c=c+1 WHERE a=1;
>
> http://dev.mysql.com/doc/mysql/en/insert.html
>
> - Aaron
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message