Skip to content

Commit

Permalink
Check server version appropriately for Postgres/JRuby.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jan 20, 2012
1 parent 8b025dc commit 4dce929
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/thinking_sphinx/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def concatenate(clause, separator = ' ')
end

def group_concatenate(clause, separator = ' ')
if connection.raw_connection.server_version >= 80400
if server_version >= 80400
"array_to_string(array_agg(COALESCE(#{clause}, '0')), '#{separator}')"
else
"array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
Expand Down Expand Up @@ -109,11 +109,9 @@ def execute_command(command, output_error = false)
end

def create_array_accum_function
if connection.raw_connection.respond_to?(:server_version) &&
connection.raw_connection.server_version >= 80400
if server_version >= 80400
return
elsif connection.raw_connection.respond_to?(:server_version) &&
connection.raw_connection.server_version > 80200
elsif server_version > 80200
execute <<-SQL
CREATE AGGREGATE array_accum (anyelement)
(
Expand Down Expand Up @@ -175,5 +173,16 @@ def create_crc32_function
SQL
execute function, true
end

def server_version
if RUBY_PLATFORM == 'java'
(connection.raw_connection.connection.server_major_version * 10000) +
(connection.raw_connection.connection.server_minor_version * 100)
elsif connection.raw_connection.respond_to?(:server_version)
connection.raw_connection.server_version
else
0
end
end
end
end

0 comments on commit 4dce929

Please sign in to comment.