1

I'm deploying my rails application on a shared host, using mysql. During development, however, I'm using an sqlite database. My queries need to work on both these environments. I'd earlier asked about a query using concat that'd work on both databases: Can MySQL concatenate strings with ||

I was told that I should set sql_mode to PIPES_AS_CONCAT or ANSI. Now my question is where and how should I set sql_mode in my application. Can it be done as an initializer, so as not to change my general code?

I tried using the code snippet from here: http://gabrito.com/post/configuring-mysql-sql-mode-in-ruby-on-rails, but that didn't work - I'm guessing the connect method has since changed as that post is rather old.

Any help is much appreciated. I'm using rails 3.1.3, by the way.

Community
  • 1
  • 1
Rahul Sekhar
  • 2,761
  • 5
  • 23
  • 27

1 Answers1

1

The main difference is probably that you're probably using the mysql2 adapter - try overwriting that method on ActiveRecord::ConnectionAdapters::Mysql2Adapter instead.

Personally I think using different databases in development and production is asking for trouble (unless perhaps you're writing something designed to be able to run on many different databases). The differences between databases can be subtle, for example sqlite3 has a rather flexible view when it comes to column types - you can quite happily insert > 255 characters in a column declared as VARCHAR(255), whereas mysql would truncate the data.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • Yes that's true, I've decided to use mysql in development too. So I'm using concat instead of the pipes. I'll try changing the class name to Mysql2Adapter soon though and mark your answer correct if it works :) – Rahul Sekhar Dec 26 '11 at 12:22