Sha256: a84ea078134b375f032026d634fcbc78b26d5adeb83d59e28626e5c1fb992054

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

class ThinkingSphinx::Connection::Client
  def close
    close! unless ThinkingSphinx::Connection.persistent?
  end

  def close!
    client.close
  end

  def execute(statement)
    check_and_perform(statement).first
  end

  def query_all(*statements)
    check_and_perform statements.join('; ')
  end

  private

  def check(statements)
    if statements.length > ThinkingSphinx::MAXIMUM_STATEMENT_LENGTH
      exception           = ThinkingSphinx::QueryLengthError.new
      exception.statement = statements
      raise exception
    end
  end

  def check_and_perform(statements)
    check statements
    perform statements
  end

  def close_and_clear
    client.close
    @client = nil
  end

  def perform(statements)
    results_for statements
  rescue => error
    message           = "#{error.message} - #{statements}"
    wrapper           = ThinkingSphinx::QueryExecutionError.new message
    wrapper.statement = statements
    raise wrapper
  ensure
    close_and_clear unless ThinkingSphinx::Connection.persistent?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/connection/client.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/connection/client.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/connection/client.rb