Class: MysqlWarning
- Inherits:
-
Object
- Object
- MysqlWarning
- Includes:
- DataMapper::Cutie::Tracker::Hook::Abstract, DataMapper::Resource
- Defined in:
- lib/dm-cutie-extras/hooks/mysql_warning.rb
Overview
Tracker Hook for recording mysql warnings
Constant Summary collapse
- STATEMENT =
"SHOW WARNINGS"
Class Method Summary collapse
- .hook_name ⇒ Object
- .supported_adapters ⇒ Object
- .supported_statements ⇒ Object
- .track(executed_query) ⇒ Object
Class Method Details
.hook_name ⇒ Object
16 |
# File 'lib/dm-cutie-extras/hooks/mysql_warning.rb', line 16 def self.hook_name; "MySQL Warnings" end |
.supported_adapters ⇒ Object
18 |
# File 'lib/dm-cutie-extras/hooks/mysql_warning.rb', line 18 def self.supported_adapters; [:mysql]; end |
.supported_statements ⇒ Object
17 |
# File 'lib/dm-cutie-extras/hooks/mysql_warning.rb', line 17 def self.supported_statements; [:select, :insert, :update, :delete]; end |
.track(executed_query) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dm-cutie-extras/hooks/mysql_warning.rb', line 20 def self.track( executed_query ) # Perform the show warings raw_warnings = repository( executed_query.generalized_query.primary_storage.repo_name.to_sym ).adapter.query MysqlWarning::STATEMENT % executed_query.statement #Store the MysqlWarning in the DM Cutie repo DataMapper::Cutie.repo do raw_warnings.each_with_index do |raw_warning, idx| next if raw_warning.attributes[:level] =~ /^note$/i attribs = raw_warning.attributes mysql_warning = MysqlWarning.new(attribs) mysql_warning.executed_query = executed_query mysql_warning.save end end end |