Sha256: de85be8589d029c3bee6a723797c5ce83afbd494818f1b521022bc4d33dc3490

Contents?: true

Size: 999 Bytes

Versions: 5

Compression:

Stored size: 999 Bytes

Contents

module SchemaPlus::Views
  module ActiveRecord
    module ConnectionAdapters
      module Mysql2Adapter

        def views(name = nil)
          views = []
          select_all("SELECT table_name FROM information_schema.views WHERE table_schema = SCHEMA()", name).each do |row|
            views << row["table_name"]
          end
          views
        end

        def view_definition(view_name, name = nil)
          results = select_all("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
          return nil unless results.any?
          row = results.first
          sql = row["view_definition"]
          sql.gsub!(%r{#{quote_table_name(current_database)}[.]}, '')
          case row["check_option"]
          when "CASCADED" then sql += " WITH CASCADED CHECK OPTION"
          when "LOCAL" then sql += " WITH LOCAL CHECK OPTION"
          end
          sql
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schema_plus_views-0.2.3 lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb
schema_plus_views-0.2.2 lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb
schema_plus_views-0.2.1 lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb
schema_plus_views-0.2.0 lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb
schema_plus_views-0.1.0 lib/schema_plus/views/active_record/connection_adapters/mysql2_adapter.rb