module RailsSqlViews4::ConnectionAdapters::Mysql2Adapter

Constants

REQUIRED_METHODS

Public Class Methods

included(base) click to toggle source
# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 6
def self.included(base)
  base.class_eval do
    def self.method_added(method)
      public(method) if REQUIRED_METHODS.include?(method) && !self.public_method_defined?(method)
    end
  end
end
method_added(method) click to toggle source
# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 8
def self.method_added(method)
  public(method) if REQUIRED_METHODS.include?(method) && !self.public_method_defined?(method)
end

Public Instance Methods

structure_dump() click to toggle source
# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 36
def structure_dump
  structure = ""
  base_tables.each do |table|
    structure += select_one("SHOW CREATE TABLE #{quote_table_name(table)}")["Create Table"] + ";\n\n"
  end

  views.each do |view|
    structure += select_one("SHOW CREATE VIEW #{quote_table_name(view)}")["Create View"] + ";\n\n"
  end

  return structure
end
supports_views?() click to toggle source

Returns true as this adapter supports views.

# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 15
def supports_views?
  true
end
tables_with_views_included(name = nil) click to toggle source
# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 32
def tables_with_views_included(name = nil)
  nonview_tables(name) + views(name)
end
view_select_statement(view, name=nil) click to toggle source

Get the view select statement for the specified table.

# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 50
def view_select_statement(view, name=nil)
  begin
    row = execute("SHOW CREATE VIEW #{view}", name).each do |row|
      return convert_statement(row[1]) if row[0] == view
    end
  rescue ActiveRecord::StatementInvalid => e
    raise "No view called #{view} found"
  end
end

Private Instance Methods

convert_statement(s) click to toggle source
# File lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb, line 61
def convert_statement(s)
  s.gsub!(/.* AS (select .*)/, '\1')
end