dm-migrations dm-mysql-adapter undefined method
Lines 96-99 of dm-mysql-adapter.rb
result = select('SHOW VARIABLES LIKE ?', name).first result ? result.value.freeze : nil end
Calling DataMapper.auto_migrate! or DataMapper.auto_upgrade!
will result in a NoMethodError: undefined method 'value' for
on JRuby 1.5.2 and MySql 5.1.45
Depending on the version of ruby or mysql I guess the method "value" may or may not exist. I did find that the method "variable_value" did exist that returned the desired value in my environment. So perhaps, the last line could be modified to:
return nil unless result
defined?(result.value) ? result.value.freeze : result.variable_value.freeze
Comments and changes to this ticket
In case anyone is interested, in order to monkey patch this, rather than modify the source code I did the following:
result = select('SHOW VARIABLES LIKE ?', name).first result ? result.variable_value.freeze : nil
attempting to open the DataMapper::Adapters::MysqlAdapter did not work for me.
Here's a stacktrace when the suggested monkeypatch is run against 1.9.2. Makes me assume you're using a different mysql version, or, maybe less likely, the JDBC driver returns different names in the structs?
NoMethodError: undefined method `variable_value' for #<struct variable_name="character_set_connection", value="utf8"> from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:37:in `class_eval' from (eval):20:in `execute' from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:37:in `class_eval' from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:37:in `execute' from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:33:in `edit' from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:42:in `edit' from /Users/snusnu/.rvm/gems/ruby-1.9.2-p0/gems/interactive_editor-0.0.4/lib/interactive_editor.rb:74:in `block (2 levels) in <module:Editors>' from (irb):2 from /Users/snusnu/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'
There is another way to get the current character set for a given connection:
SELECT variable_value FROM information_schema.session_variables WHERE LOWER(variable_name) = 'character_set_connection'
I would be interested in testing this out to see if it resolves this specific issue. If anyone has seen Paul's issue, and can try modifying the code to use the above query, and let me know if it fixes the problem for you.
Once we get that confirmation, I'm fine with making this change, but I don't want to make random changes for things I can't reproduce locally.
I have been trying to create a reduction for this, but so far I have not been able to reproduce on the same installation of jruby and the same connection string. Command line from the project with the issue:
jruby-1.5.2 > result = repository.adapter.select("SHOW VARIABLES LIKE 'character_set_connection'").first
~ (0.001) com.mysql.jdbc.JDBC4PreparedStatement@4c48d0c9: SHOW VARIABLES LIKE 'character_set_connection' => # variable_name="character_set_connection", variable_value="utf8">
Clearly shows "variable_value" rather than just "value."
In case anyone else runs into this, here is a monkey patch until the next version:
repository.adapter.class.class_eval do def show_variable(name) select('SELECT variable_value FROM information_schema.session_variables WHERE LOWER(variable_name) = ?', name).first end end
- Milestone set to 1.1
- State changed from unconfirmed to resolved
- Assigned user set to Dan Kubb (dkubb)
- Milestone order changed from 196279 to 0
This was resolved in: