News for hackers. Stuff that matters.
Re:Worst Bug Ever by Erwin on Monday January 21, 2013 @11:13AM (#5092055)
A good practice there is to do tricky DELETE/UPDATE inside a transaction. In e.g. Postgres, executing DELETE/UDPATE tells you number of affected rows, so if you see 1243 rows were updated rather than 1 as you expected, you can ROLLBACK.
Re:Worst Bug Ever by bartonfink on Monday January 21, 2013 @11:28AM (#5092137)
Another good approach is to replace 'delete' with 'select count(1)' or something similar. The where clause can remain the same, you know how many rows will be affected and there's less overhead of remembering to set up a transaction, writing an update statement, rolling back, etc.
Re:Worst Bug Ever by CodeCube on Tuesday January 22, 2013 @10:53AM (#5097656)
Yeah, if I ever did have to troubleshoot in SQL directly, I definitely started doing this ... only changing it to update or delete when I was 100% sure it was affecting only what I wanted to affect.