Changeset 3152
- Timestamp:
- 11/21/05 18:51:27 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r3142 r3152 1 1 *SVN* 2 3 * MySQL: introduce :encoding option to specify the character set for client, connection, and results. Only available for MySQL 4.1 and later with the mysql-ruby driver. Do SHOW CHARACTER SET in mysql client to see available encodings. #2975 [Shugo Maeda] 2 4 3 5 * Add tasks to create, drop and rebuild the MySQL and PostgreSQL test databases. [Marcel Molina Jr.] trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r3148 r3152 39 39 mysql = Mysql.init 40 40 mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey] 41 ConnectionAdapters::MysqlAdapter.new(mysql.real_connect(host, username, password, database, port, socket), logger, [host, username, password, database, port, socket]) 41 if config[:encoding] 42 begin 43 mysql.options(Mysql::SET_CHARSET_NAME, config[:encoding]) 44 rescue 45 raise ActiveRecord::ConnectionFailed, 'The :encoding option is only available for MySQL 4.1 and later with the mysql-ruby driver. Again, this does not work with the ruby-mysql driver or MySQL < 4.1.' 46 end 47 end 48 49 conn = mysql.real_connect(host, username, password, database, port, socket) 50 conn.query("SET NAMES '#{config[:encoding]}'") if config[:encoding] 51 ConnectionAdapters::MysqlAdapter.new(conn, logger, [host, username, password, database, port, socket], mysql) 42 52 end 43 53 end … … 88 98 ] 89 99 90 def initialize(connection, logger, connection_options=nil )100 def initialize(connection, logger, connection_options=nil, mysql=Mysql) 91 101 super(connection, logger) 92 102 @connection_options = connection_options 103 @mysql = mysql 93 104 end 94 105 … … 120 131 # QUOTING ================================================== 121 132 133 def quote(value, column = nil) 134 if value.kind_of?(String) && column && column.type == :binary 135 s = column.class.string_to_binary(value).unpack("H*")[0] 136 "x'#{s}'" 137 else 138 super 139 end 140 end 141 122 142 def quote_column_name(name) #:nodoc: 123 143 "`#{name}`" … … 125 145 126 146 def quote_string(string) #:nodoc: 127 Mysql::quote(string)147 @mysql.quote(string) 128 148 end 129 149