Sha256: 3abdb2ec5a24860b7b975f2c4777f007064aed725ee87ad096e657d5be2404bc

Contents?: true

Size: 978 Bytes

Versions: 14

Compression:

Stored size: 978 Bytes

Contents

module RailsDb
  class SqlController < RailsDb::ApplicationController
    if Rails::VERSION::MAJOR >= 4
      before_action :load_query, only: [:index, :execute, :csv, :xls]
    else
      before_filter :load_query
    end

    def index
    end

    def execute
      render :index
    end

    def csv
      send_data(@sql_query.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: 'results.csv')
    end

    def xls
      render xlsx: 'xls', filename: 'results.xlsx'
    end

    def import
    end

    def import_start
      @importer = SqlImport.new(params[:file])
      result    = @importer.import
      if result.ok?
        flash[:notice] = 'File was successfully imported'
      else
        flash[:alert] = "Error occurred during import: #{result.error.message}"
      end
      render :import
    end

    private

    def load_query
      @sql       = "#{params[:sql]}".strip
      @sql_query = RailsDb::SqlQuery.new(@sql).execute
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rails_db-1.6.0 app/controllers/rails_db/sql_controller.rb
rails_db-1.5.0 app/controllers/rails_db/sql_controller.rb
rails_db-1.4.1 app/controllers/rails_db/sql_controller.rb
rails_db-1.4.0 app/controllers/rails_db/sql_controller.rb
rails_db-1.3.4 app/controllers/rails_db/sql_controller.rb
rails_db-1.3.3 app/controllers/rails_db/sql_controller.rb
rails_db-1.3.2 app/controllers/rails_db/sql_controller.rb
rails_db-1.3.1 app/controllers/rails_db/sql_controller.rb
rails_db-1.3 app/controllers/rails_db/sql_controller.rb
rails_db-1.1.1 app/controllers/rails_db/sql_controller.rb
rails_db-1.1 app/controllers/rails_db/sql_controller.rb
rails_db-1.0 app/controllers/rails_db/sql_controller.rb
rails_db-0.9.9 app/controllers/rails_db/sql_controller.rb
rails_db-0.9 app/controllers/rails_db/sql_controller.rb