Created
August 14, 2012 12:45
-
-
Save calo81/3349024 to your computer and use it in GitHub Desktop.
monkeypatch activerecord execution of SQLs to log them out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$number_of_executed_sqls = 0 | |
$file = File.open('/tmp/sql.sql', 'w') | |
module ActiveRecord | |
module ConnectionAdapters | |
class MysqlAdapter | |
def execute(sql, name = nil) | |
$number_of_executed_sqls += 1 if sql != 'BEGIN' and sql != 'COMMIT' | |
$file.puts sql + ";" | |
$file.flush | |
if name == :skip_logging | |
@connection.query(sql) | |
else | |
log(sql, name) { @connection.query(sql) } | |
end | |
rescue ActiveRecord::StatementInvalid => exception | |
if exception.message.split(":").first =~ /Packets out of order/ | |
raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings." | |
else | |
raise | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment