Matt Aimonetti
2007-May-22 00:56 UTC
ActiveRecord::Base.connection.create_database defaults to latin1
If you use ActiveRecord::Base.connection.create_database you''ll notice that by default the created db will use latin1 encoding. I created a plugin to handle different charset and collations (on top of helping you with other boring DB tasks). You can check out the early version of the plugin svn checkout svn://rubyforge.org/var/svn/raketasks/db_tasks (I really need to move my projects out of rubyforge, it''s a real pain to browse the code) Anyway, if people consider that it''s an important feature, I''d be glad to submit a patch. Ohh, by the way, when you set your database with a specific charset, tables inherit the collation and charset automatically. Rails handles encoded queries by adding an encoding value in the environment file. (database.yml) I have a rake tasks which does that for you if you are too lazy to type 3 times encoding: utf8 ;) Matt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
DHH
2007-May-22 03:47 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
> If you use ActiveRecord::Base.connection.create_database you''ll notice > that by default the created db will use latin1 encoding. I created a > plugin to handle different charset and collations (on top of helping > you with other boring DB tasks).Which database are you talking about specifically? I believe Rails will use whatever the current default is. MySQL, for example, has a installation-wide configuration file that controls that. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Aimonetti
2007-May-22 04:28 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
right, I was talking about the MysqlAdapter, the other database adapters don''t let you create a database. Here is the create_database method: def create_database(name) #:nodoc: execute "CREATE DATABASE `#{name}`" end Here is my suggestion: # Create a new MySQL database allowing you to specify the charset and collation, by default the database is created with utf8 charset and utf8_bin collation # usage: ActiveRecord::Base.connection.create_database(''charset_plugin_test'', {:charset => ''latin1'', :collation => ''latin1_bin''}) def create_database(name, options = {}) execute "CREATE DATABASE `#{name}` DEFAULT CHARACTER SET `#{options[:charset] ||= ''utf8''}` COLLATE `#{options[:collation] ||''utf8_bin''}`" end Nothing fancy but using utf8 by default means that people have to/ should update their database.yml file to add the encoding to each environment. Does it make sense? -Matt On May 21, 8:47 pm, DHH <david.heineme...@gmail.com> wrote:> > If you use ActiveRecord::Base.connection.create_database you''ll notice > > that by default the created db will use latin1 encoding. I created a > > plugin to handle different charset and collations (on top of helping > > you with other boring DB tasks). > > Which database are you talking about specifically? I believe Rails > will use whatever the current default is. MySQL, for example, has a > installation-wide configuration file that controls that.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Mislav Marohnić
2007-May-22 12:14 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
On 5/22/07, Matt Aimonetti <mattAimonetti@gmail.com> wrote:> > > Nothing fancy but using utf8 by default means that people have to/ > should update their database.yml file to add the encoding to each > environment. > > Does it make sense?To me it does. It''s inexpensive and exposes native database functionality to the framework user. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Manfred Stienstra
2007-May-22 16:03 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
> On May 21, 8:47 pm, DHH <david.heineme...@gmail.com> wrote: >>> If you use ActiveRecord::Base.connection.create_database you''ll >>> notice >>> that by default the created db will use latin1 encoding. I created a >>> plugin to handle different charset and collations (on top of helping >>> you with other boring DB tasks). >> >> Which database are you talking about specifically? I believe Rails >> will use whatever the current default is. MySQL, for example, has a >> installation-wide configuration file that controls that.Just a quick note, it''s probably best to set the server-wide encoding to UTF-8. I''ve seen some instances, mostly with MySQL 4.x where even with SET NAMES utf8 the MySQL client wouldn''t go into UTF-8 mode. Ending up with mixed charsets in one table is a pita. Manfred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Aimonetti
2007-May-23 15:26 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
Somebody from the core team? Do you want a patch or sould I keep that in my plugin? m|a On May 22, 9:03 am, Manfred Stienstra <manf...@gmail.com> wrote:> > On May 21, 8:47 pm, DHH <david.heineme...@gmail.com> wrote: > >>> If you use ActiveRecord::Base.connection.create_database you''ll > >>> notice > >>> that by default the created db will use latin1 encoding. I created a > >>> plugin to handle different charset and collations (on top of helping > >>> you with other boring DB tasks). > > >> Which database are you talking about specifically? I believe Rails > >> will use whatever the current default is. MySQL, for example, has a > >> installation-wide configuration file that controls that. > > Just a quick note, it''s probably best to set the server-wide encoding > to UTF-8. I''ve seen some instances, mostly with MySQL 4.x where even > with SET NAMES utf8 the MySQL client wouldn''t go into UTF-8 mode. > Ending up with mixed charsets in one table is a pita. > > Manfred--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-May-23 19:25 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
On 5/23/07, Matt Aimonetti <mattAimonetti@gmail.com> wrote:> Somebody from the core team? Do you want a patch or sould I keep that > in my plugin?Please do patch. Let''s encourage Unicode end-to-end. jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Aimonetti
2007-May-24 03:12 UTC
Re: ActiveRecord::Base.connection.create_database defaults to latin1
Thanks Jeremy, Here is the ticket: http://dev.rubyonrails.org/ticket/8448 if the patch is used, one can start a rails app just like that: rake my_project rake db:create ruby script/server That''s it! ready to go. (compatible with PostgreSQL, MySQL, and SQLite3) One thing though, we might want to add the following key/value: encoding: utf8 to each default environment from database.yml - Matt On May 23, 12:25 pm, "Jeremy Kemper" <jer...@bitsweat.net> wrote:> On 5/23/07, Matt Aimonetti <mattAimone...@gmail.com> wrote: > > > Somebody from the core team? Do you want a patch or sould I keep that > > in my plugin? > > Please do patch. Let''s encourage Unicode end-to-end. > > jeremy--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---