On 5/05/11 9:02 PM, Chris Corbyn wrote:
Hi,

I hope you don't mind my asking here but I have a few questions about
something I'm doing.

The MySQL adapter sets sql_mode in MySQL to an extremely strict set of
options, somewhere at a low level beyond the adapter's control.  The
solution is to "undo" that change by setting a less strict mode.  The
only way I could see to make this application-wide was to redefine the
#open_connection method.

=begin
DataMapper Mixin to force sql_mode to allow our lack of use of default
values

This can go away eventually, when we migrate out our incompatible
fields in MySQL.
=end
module Flippa
        module DataMapper

                class ::DataMapper::Adapters::MysqlAdapter
                        def open_connection
                                connection = super

                                statement = "SET sql_mode = ?"
                                bind_values = 
[Flippa::Application.config.data_mapper_sql_mode]
                                command = connection.create_command(statement)
                                command.execute_non_query(*bind_values)

                                puts "Sending SET sql_mode" # DEBUG!!

                                connection
                        end
                end

        end
end

Just a few questions (excuse my Rails newbiness):

1.  I'm including this by putting a file in initializers called
data_mapper.rb, which simply has a require line for my module.  Is
this the right place to do this?
yep

2.  Is it weird that I've put the file at flippa/data_mapper, when in
fact the file only exists to decorate the MysqlAdapter class?  It
feels weird, but maybe I'm just not so open minded with what I'm
doing, being new to Ruby.
yes this is unnecessary. The :: at the start of ::DataMapper::Adapters::MysqlAdapters puts you back up into the global namespace. I would remove your enclosing modules, they do nothing.

3.  It looks like a connection is opened and closed for every single
query executed.  Is this right?  Isn't that expensive?
I don't know about this one.


If I knew how to do it I'd contribute back any changes I make to
improve support, by creating a plugin or whatever.  This is a pretty
simple modification though ;)
Another option you have is to fork the original on github, patch it, then use your fork in your Gemfile: http://www.rubyinside.com/the-end-of-monkeypatching-4570.html


Cheers,

Chris

PS: Absolutely loving DataMapper.  I'm seriously in awe of the
elegance of it all.  It makes every other ORM I've worked with in the
past (and I've worked with a few) look pitiful ;)  Kudos to you guys.


--
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to