Sha256: 60c0074bd28ae201a64d90a66e9a863f6e7d863b290b3dd5ba8657e24f3f0c1d

Contents?: true

Size: 748 Bytes

Versions: 38

Compression:

Stored size: 748 Bytes

Contents

module ForestLiana
  class LiveQueryChecker
    QUERY_SELECT = /\ASELECT\s.*FROM\s.*\z/im

    def initialize(query, context)
      @query = query
      @context = context
    end

    def validate
      raise generate_error 'You cannot execute an empty SQL query.' if @query.blank?

      if @query.include?(';') && @query.index(';') < (@query.length - 1)
        raise generate_error 'You cannot chain SQL queries.'
      end

      raise generate_error 'Only SELECT queries are allowed.' if QUERY_SELECT.match(@query).nil?
    end

    private

    def generate_error message
      error_message = "#{@context}: #{message}"
      FOREST_LOGGER.error(error_message)
      ForestLiana::Errors::LiveQueryError.new(error_message)
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
forest_liana-2.13.5 app/services/forest_liana/live_query_checker.rb
forest_liana-2.13.4 app/services/forest_liana/live_query_checker.rb
forest_liana-2.13.3 app/services/forest_liana/live_query_checker.rb
forest_liana-2.13.2 app/services/forest_liana/live_query_checker.rb
forest_liana-2.13.1 app/services/forest_liana/live_query_checker.rb
forest_liana-2.13.0 app/services/forest_liana/live_query_checker.rb
forest_liana-2.12.0 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.13 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.12 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.11 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.10 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.9 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.8 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.7 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.6 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.5 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.4 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.3 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.2 app/services/forest_liana/live_query_checker.rb
forest_liana-2.11.1 app/services/forest_liana/live_query_checker.rb