class ThinkingSphinx::Connection::Client

Public Class Methods

new(options) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 4
def initialize(options)
  if options[:socket].present?
    options[:socket] = options[:socket].remove /:mysql41$/

    options.delete :host
    options.delete :port
  else
    options.delete :socket

    # If you use localhost, MySQL insists on a socket connection, but in this
    # situation we want a TCP connection. Using 127.0.0.1 fixes that.
    if options[:host].nil? || options[:host] == "localhost"
      options[:host] = "127.0.0.1"
    end
  end

  @options = options
end

Public Instance Methods

close() click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 23
def close
  close! unless ThinkingSphinx::Connection.persistent?
end
close!() click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 27
def close!
  client.close
end
execute(statement) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 31
def execute(statement)
  check_and_perform(statement).first
end
query_all(*statements) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 35
def query_all(*statements)
  check_and_perform statements.join('; ')
end

Private Instance Methods

check(statements) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 41
def check(statements)
  if statements.length > ThinkingSphinx::MAXIMUM_STATEMENT_LENGTH
    exception           = ThinkingSphinx::QueryLengthError.new
    exception.statement = statements
    raise exception
  end
end
check_and_perform(statements) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 49
def check_and_perform(statements)
  check statements
  perform statements
end
close_and_clear() click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 54
def close_and_clear
  client.close
  @client = nil
end
perform(statements) click to toggle source
# File lib/thinking_sphinx/connection/client.rb, line 59
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