Prev | Current Page 347 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

COLUMNS cols
WHERE cols.TABLE_NAME = 'accounts'
If we search through the Active Record source code, we find that this query is, in fact,
unique to the SQL Server adapter (though each adaptor does have its own query to gather column
information and that would be executed here in your log as well).
Active Record uses this information to populate the various instance and class variables,
such as the columns collection. It also uses the information from these queries to determine
what attributes a given object should have.
The next thing we see in our log is the execution of the actual query the find method built,
as well as the details we said to manually log:
[4;36;1mSQL (0.071729)[0m [0;1mSELECT * FROM accounts WHERE (accounts.[id] = 1)
[0m
found a record with username: Kevin
The interesting thing about the preceding result is that it shows you both the exact query
that was executed and the time required to execute that SQL statement. As your application
CHAPTER 6 ?–  ACTIVE RECORD TESTING AND DEBUGGING 157
grows and performance becomes a concern, you may want to use this as a way to compare
performance between using the default find methods and executing the SQL directly via
find_by_sql methods or other less friendly ways.


Pages:
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359