@@ -5,11 +5,14 @@ def mysql_connection(config)
55
66 return jndi_connection ( config ) if jndi_config? ( config )
77
8+ driver = config [ :driver ] ||=
9+ defined? ( ::Jdbc ::MySQL . driver_name ) ? ::Jdbc ::MySQL . driver_name : 'com.mysql.jdbc.Driver'
10+
811 begin
912 require 'jdbc/mysql'
1013 ::Jdbc ::MySQL . load_driver ( :require ) if defined? ( ::Jdbc ::MySQL . load_driver )
1114 rescue LoadError # assuming driver.jar is on the class-path
12- end
15+ end if mysql_driver = driver [ 0 , 10 ] == 'com.mysql.'
1316
1417 config [ :username ] = 'root' unless config . key? ( :username )
1518 # jdbc:mysql://[host][,failoverhost...][:port]/[database]
@@ -23,32 +26,33 @@ def mysql_connection(config)
2326 url << "/#{ config [ :database ] } "
2427 config [ :url ] = url
2528 end
26- config [ :driver ] ||= defined? ( ::Jdbc ::MySQL . driver_name ) ? ::Jdbc ::MySQL . driver_name : 'com.mysql.jdbc.Driver'
2729
2830 properties = ( config [ :properties ] ||= { } )
29- properties [ 'zeroDateTimeBehavior' ] ||= 'convertToNull'
30- properties [ 'jdbcCompliantTruncation' ] ||= 'false'
31- properties [ 'useUnicode' ] = 'true' unless properties . key? ( 'useUnicode' ) # otherwise platform default
32- encoding = config . key? ( :encoding ) ? config [ :encoding ] : 'utf8'
33- properties [ 'characterEncoding' ] = encoding if encoding
34- if ! ( reconnect = config [ :reconnect ] ) . nil?
35- properties [ 'autoReconnect' ] ||= reconnect . to_s
36- # properties['maxReconnects'] ||= '3'
37- # with reconnect fail-over sets connection read-only (by default)
38- # properties['failOverReadOnly'] ||= 'false'
31+ if mysql_driver
32+ properties [ 'zeroDateTimeBehavior' ] ||= 'convertToNull'
33+ properties [ 'jdbcCompliantTruncation' ] ||= 'false'
34+ properties [ 'useUnicode' ] = 'true' unless properties . key? ( 'useUnicode' ) # otherwise platform default
35+ encoding = config . key? ( :encoding ) ? config [ :encoding ] : 'utf8'
36+ properties [ 'characterEncoding' ] = encoding if encoding
37+ if ! ( reconnect = config [ :reconnect ] ) . nil?
38+ properties [ 'autoReconnect' ] ||= reconnect . to_s
39+ # properties['maxReconnects'] ||= '3'
40+ # with reconnect fail-over sets connection read-only (by default)
41+ # properties['failOverReadOnly'] ||= 'false'
42+ end
3943 end
4044 if config [ :sslkey ] || sslcert = config [ :sslcert ] # || config[:use_ssl]
4145 properties [ 'useSSL' ] ||= true
42- properties [ 'requireSSL' ] ||= true
46+ properties [ 'requireSSL' ] ||= true if mysql_driver
4347 properties [ 'clientCertificateKeyStoreUrl' ] ||= begin
4448 java . io . File . new ( sslcert ) . to_url . to_s
45- end if sslcert
46- if sslca = config [ :sslca ]
49+ end if sslcert && mysql_driver
50+ if sslca = config [ :sslca ] && mysql_driver
4751 properties [ 'trustCertificateKeyStoreUrl' ] ||= begin
4852 java . io . File . new ( sslca ) . to_url . to_s
4953 end
5054 else
51- properties [ 'verifyServerCertificate' ] ||= false
55+ properties [ 'verifyServerCertificate' ] ||= false if mysql_driver
5256 end
5357 end
5458
0 commit comments