Module: ActiveRecord::Comments::ConnectionAdapters::MysqlAdapter
- Defined in:
- lib/active_record/comments/connection_adapters/mysql_adapter.rb
Instance Method Summary collapse
- #add_column_options!(sql, options) ⇒ Object
- #comment_sql(comment_definition) ⇒ Object
- #comments_supported? ⇒ Boolean
- #execute_comment(comment_definition) ⇒ Object
- #retrieve_column_comments(table_name, *column_names) ⇒ Object
- #retrieve_table_comment(table_name) ⇒ Object
- #set_column_comment(table_name, column_name, comment_text) ⇒ Object
- #set_table_comment(table_name, comment_text) ⇒ Object
Instance Method Details
#add_column_options!(sql, options) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 33 def (sql, ) super(sql, ) if .keys.include?(:comment) sql << CommentDefinition.new(self, nil, nil, [:comment]).to_sql end end |
#comment_sql(comment_definition) ⇒ Object
40 41 42 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 40 def comment_sql(comment_definition) " COMMENT #{escaped_comment(comment_definition.comment_text)}" end |
#comments_supported? ⇒ Boolean
3 4 5 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 3 def comments_supported? true end |
#execute_comment(comment_definition) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 44 def execute_comment(comment_definition) if comment_definition.table_comment? set_table_comment comment_definition.table_name, comment_definition.comment_text else set_column_comment comment_definition.table_name, comment_definition.column_name, comment_definition.comment_text end end |
#retrieve_column_comments(table_name, *column_names) ⇒ Object
27 28 29 30 31 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 27 def retrieve_column_comments(table_name, *column_names) result = select_rows(column_comment_sql(table_name, *column_names)) return {} if result.nil? result.inject({}){|m, row| m[row[0].to_sym] = (row[1].blank? ? nil : row[1]); m} end |
#retrieve_table_comment(table_name) ⇒ Object
22 23 24 25 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 22 def retrieve_table_comment(table_name) result = select_rows(table_comment_sql(table_name)) result[0].nil? || result[0][0].blank? ? nil : result[0][0] end |
#set_column_comment(table_name, column_name, comment_text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 11 def set_column_comment(table_name, column_name, comment_text) pk_info = pk_and_sequence_for(table_name) if pk_info && pk_info.first == column_name.to_s # change_column broken for :primary_key primary_col_def = native_database_types[:primary_key].sub(/ PRIMARY KEY/i, '') execute "ALTER TABLE #{quote_table_name table_name} CHANGE #{quote_column_name column_name} #{quote_column_name column_name} #{primary_col_def} COMMENT #{escaped_comment(comment_text)};" else column = column_for(table_name, column_name) change_column table_name, column_name, column.sql_type, :comment => comment_text end end |
#set_table_comment(table_name, comment_text) ⇒ Object
7 8 9 |
# File 'lib/active_record/comments/connection_adapters/mysql_adapter.rb', line 7 def set_table_comment(table_name, comment_text) execute "ALTER TABLE #{quote_table_name table_name} COMMENT #{escaped_comment(comment_text)}" end |