Prev | Current Page 331 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

We covered this situation in more
detail within our discussion of data validations previously.
Since this error is primarily raised because of locking issues, it??™s a bit difficult to show
a reliable example you can duplicate. The basic idea would be if you were attempting to do an
update to something like a page-count field without using transactions but were at least using
the proper save! method. In the event that two or more users hit the update code at the exact
same time, one would likely get the RecordNotSaved error rather than both getting the wrong
number.
StatementInvalid
This error is raised when the SQL statement that is eventually passed to your database engine
by Active Record is incorrect or has syntax errors. The error generally provides specific details
about what part of the SQL statement is thought to be invalid for your database.
In the following example, we raise a StatementInvalid error with our find_by_sql method,
because our account table has no field named Kevin (our SQL query has the field name and
value swapped in the where clause).


Pages:
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343