
dm-migrations dm-mysql-adapter undefined method
Reported by Paul Walker | September 14th, 2010 @ 09:19 PM | in 1.1
Lines 96-99 of dm-mysql-adapter.rb
def show_variable(name)
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
#<#Class...>
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
-
Paul Walker September 14th, 2010 @ 10:08 PM
In case anyone is interested, in order to monkey patch this, rather than modify the source code I did the following:
repository.adapter.class.class_eval do
def show_variable(name)result = select('SHOW VARIABLES LIKE ?', name).first result ? result.variable_value.freeze : nil
end end
attempting to open the DataMapper::Adapters::MysqlAdapter did not work for me.
-
Martin Gamsjaeger (snusnu) September 15th, 2010 @ 06:04 AM
- State changed from new to unconfirmed
Trusted sources say that this obviously happens on jruby-1.5. I couldn't reproduce it on 1.8.7 and 1.9.2.
It's always a good idea to add the ruby version in use to a ticket :)
-
Martin Gamsjaeger (snusnu) September 15th, 2010 @ 06:30 AM
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>'
-
Dan Kubb (dkubb) September 15th, 2010 @ 03:35 PM
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.
-
Dan Kubb (dkubb) September 15th, 2010 @ 03:41 PM
@Paul: Try changing #show_variable to something like this:
def show_variable(name) result = select('SELECT variable_value FROM information_schema.session_variables WHERE LOWER(variable_name) = ?', name) result.variable_value.freeze if result end
-
Paul Walker September 15th, 2010 @ 03:41 PM
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."
-
Paul Walker September 15th, 2010 @ 03:54 PM
def show_variable(name) select('SELECT variable_value FROM information_schema.session_variables WHERE LOWER(variable_name) = ?', name).first end
works for me :-).
-
Paul Walker September 15th, 2010 @ 04:00 PM
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
-
Dan Kubb (dkubb) September 15th, 2010 @ 09:30 PM
- 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:
http://github.com/datamapper/dm-migrations/commit/faea4c2b7a5e03c6b...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »