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
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.
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
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?
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
m|a
Please do patch. Let's encourage Unicode end-to-end.
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: