Sha256: 26b7771fe43b00d728f7da34b3f8e3912cf4e9360fc4b3004876423967b967db

Contents?: true

Size: 754 Bytes

Versions: 242

Compression:

Stored size: 754 Bytes

Contents

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

    def initialize(query, context)
      @query = query.strip
      @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

242 entries across 242 versions & 1 rubygems

Version Path
forest_liana-9.11.1 app/services/forest_liana/live_query_checker.rb
forest_liana-9.11.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.6 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.5 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.4 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.3 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.2 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.1 app/services/forest_liana/live_query_checker.rb
forest_liana-9.10.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.9.1 app/services/forest_liana/live_query_checker.rb
forest_liana-9.9.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.8.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.7.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.6.4 app/services/forest_liana/live_query_checker.rb
forest_liana-9.6.3 app/services/forest_liana/live_query_checker.rb
forest_liana-9.6.0 app/services/forest_liana/live_query_checker.rb
forest_liana-9.5.7 app/services/forest_liana/live_query_checker.rb
forest_liana-9.5.6 app/services/forest_liana/live_query_checker.rb
forest_liana-9.5.5 app/services/forest_liana/live_query_checker.rb
forest_liana-9.5.4 app/services/forest_liana/live_query_checker.rb