views:

533

answers:

2

Hey!

How do I add the LIMIT 1 clause to an update when using Zend Framework?

I'm kind of forced not to use Zend_Db_Table_Abstract::update() since it executes itself unlike the sweet Zend_Db_Select-classes.

The reason to do this is just precaution and I think Zend_Db_Table_Abstract::update()'s syntax makes more sense when found in code than the more allround Zend_Db_Adapter_Abstract::query().

+2  A: 

You can not.

There is an issue created for this exact problem at the issue tracker. But this feature is still not implemented.

Goran Jurić
Thanks for searching the issue tracker better than me.
chelmertz
+1  A: 

Why would you want to do that??? If you want to update a single record you should use the records' primary key and use an

UPDATE <table> SET field=<newvalue>, ... WHERE key = <keyvalue>;

query.

wimvds
1) It's valid SQL, 2) As the `Zend_Db_Select`, it can contain dynamic input to which `LIMIT 1` is an extra safety check (if, say, the usual filters/validation fails or is poorly written by another programmer), 3) It should be faster since it should stop searching after having updating one row
chelmertz
1). In MySQL only, any other RDBMS will not accept this syntax, so your code will not be portable (that's probably one of the reasons why it's not available in the Zend Framework). 2). Then why don't you check whether more then one record will be impacted in your business logic before actually performing the update/delete?
wimvds
1) When porting to another DBMS, `LIMIT` on `update()` would be a very small issue to handle compared to everything else that has to run smoothly. Besides, since it's allowed in MySQL, maybe `update()` doesn't fit where it is now (outside of configurability). Thanks for mentioning it's MySQL only though, I didn't know that. 2) Valid point of course, but I'll take any extra security measures I can. 3) goes uncommented but I believe the speed could have a big impact on queries updating a large amount of rows.
chelmertz