Skip to content

Commit 914c512

Browse files
committed
[mysql] adapter.version (server version) that works with non-official driver(s) as well
1 parent f67415f commit 914c512

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/arjdbc/mysql/adapter.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,20 @@ def version
586586
return @version ||= begin
587587
version = []
588588
java_connection = jdbc_connection(true)
589-
if java_connection.is_a?(Java::ComMysqlJdbc::ConnectionImpl)
589+
if java_connection.java_class.name == 'com.mysql.jdbc.ConnectionImpl'
590590
version << jdbc_connection.serverMajorVersion
591591
version << jdbc_connection.serverMinorVersion
592592
version << jdbc_connection.serverSubMinorVersion
593593
else
594-
warn "INFO: failed to resolve MySQL server version using: #{java_connection}"
594+
result = execute 'SELECT VERSION()', 'SCHEMA'
595+
result = result.first.values.first # [{"VERSION()"=>"5.5.37-0ubuntu..."}]
596+
if match = result.match(/^(\d)\.(\d+)\.(\d+)/)
597+
version << match[1].to_i
598+
version << match[2].to_i
599+
version << match[3].to_i
600+
end
595601
end
596-
version
602+
version.freeze
597603
end
598604
end
599605

0 commit comments

Comments
 (0)