Module: ActiveRecord::Comments::ConnectionAdapters::AbstractSQLiteAdapter

Included in:
SQLite3Adapter, SQLiteAdapter
Defined in:
lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb

Instance Method Summary collapse

Instance Method Details

#add_column_options!(sql, options) ⇒ Object



53
54
55
56
57
58
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 53

def add_column_options!(sql, options)
  super(sql, options)
  if options.keys.include?(:comment)
    sql << CommentDefinition.new(self, nil, nil, options[:comment]).to_sql
  end
end

#column_for(table_name, column_name) ⇒ Object



40
41
42
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 40

def column_for(table_name, column_name)
  columns(table_name).detect{|col| col.name == column_name.to_s}
end

#comment_sql(comment_definition) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 44

def comment_sql(comment_definition)
  if comment_definition.nil? || comment_definition.comment_text.blank?
    ""
  else
    " /*#{escaped_comment(comment_definition.comment_text)}*/"
  end

end

#comments_supported?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 3

def comments_supported?
  true
end

#inline_comments?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 7

def inline_comments?
  true
end

#retrieve_column_comments(table_name, *column_names) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 29

def retrieve_column_comments(table_name, *column_names)
  if column_names.empty?
    return columns(table_name).inject({}) { |m, v| m[v.name.to_sym] = v.comment if v.comment.present?; m }
  end
  result = select_rows(lookup_comment_sql(table_name))
  result[0][0] =~ /^CREATE (?:TEMPORARY )?TABLE "\w*" [^\(]*(?:\/\*.*\*\/ )?\((.*)\)[^\)]*$/
  col_defs = $1
  comment_matches = col_defs.scan(/"([^",]+)"[^,]*\/\*(.+?)\*\//)
  comment_matches.inject({}){|m, row| m[row.first.to_sym] = row.last; m}
end

#retrieve_table_comment(table_name) ⇒ Object



22
23
24
25
26
27
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 22

def retrieve_table_comment(table_name)
  result = select_rows(lookup_comment_sql(table_name))
  if result[0][0] =~ /CREATE (?:TEMPORARY )?TABLE #{quote_table_name table_name} [^\(]*\/\*(.*)\*\/ \(/
    $1
  end
end

#set_column_comment(table_name, column_name, comment_text) ⇒ Object



15
16
17
18
19
20
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 15

def set_column_comment(table_name, column_name, comment_text)
  sql_type = primary_key(table_name) == column_name.to_s ?
      :primary_key :
      column_for(table_name, column_name).sql_type
  change_column table_name, column_name, sql_type, :comment => comment_text
end

#set_table_comment(table_name, comment_text) ⇒ Object



11
12
13
# File 'lib/active_record/comments/connection_adapters/abstract_sqlite_adapter.rb', line 11

def set_table_comment(table_name, comment_text)
  alter_table(table_name, :comment => comment_text)
end