Title: [591] trunk/activerecord-jdbc: Fix for JRUBY-922, the utf8 regression.
Revision
591
Author
olabini
Date
2007-05-17 12:16:58 -0400 (Thu, 17 May 2007)

Log Message

Fix for JRUBY-922, the utf8 regression. Most of the implementation by Shinya Kasatani.

Modified Paths

Added Paths

Diff

Modified: trunk/activerecord-jdbc/Rakefile (590 => 591)


--- trunk/activerecord-jdbc/Rakefile	2007-05-16 08:25:47 UTC (rev 590)
+++ trunk/activerecord-jdbc/Rakefile	2007-05-17 16:16:58 UTC (rev 591)
@@ -50,6 +50,11 @@
   t.libs << 'test'
 end
 
+Rake::TestTask.new(:test_mysql_multibyte) do |t|
+  t.test_files = FileList['test/mysql_multibyte_test.rb']
+  t.libs << 'test'
+end
+
 Rake::TestTask.new(:test_hsqldb) do |t|
   t.test_files = FileList['test/hsqldb_simple_test.rb']
   t.libs << 'test'

Modified: trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java (590 => 591)


--- trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-05-16 08:25:47 UTC (rev 590)
+++ trunk/activerecord-jdbc/src/java/JdbcAdapterInternalService.java	2007-05-17 16:16:58 UTC (rev 591)
@@ -204,7 +204,7 @@
     }
 
     public static IRubyObject columns(IRubyObject recv, IRubyObject[] args) throws SQLException, IOException {
-        String table_name = args[0].toString();
+        String table_name = args[0].convertToString().getUnicodeValue();
         while(true) {
             Connection c = (Connection)recv.dataGetStruct();
             try {
@@ -323,7 +323,7 @@
 
     public static IRubyObject execute_id_insert(IRubyObject recv, IRubyObject sql, IRubyObject id) throws SQLException {
         Connection c = (Connection)recv.dataGetStruct();
-        PreparedStatement ps = c.prepareStatement(sql.toString());
+        PreparedStatement ps = c.prepareStatement(sql.convertToString().getUnicodeValue());
         try {
             ps.setLong(1,RubyNumeric.fix2long(id));
             ps.executeUpdate();
@@ -339,7 +339,7 @@
             Statement stmt = null;
             try {
                 stmt = c.createStatement();
-                return recv.getRuntime().newFixnum(stmt.executeUpdate(sql.toString()));
+                return recv.getRuntime().newFixnum(stmt.executeUpdate(sql.convertToString().getUnicodeValue()));
             } catch(SQLException e) {
                 if(c.isClosed()) {
                     recv.callMethod(recv.getRuntime().getCurrentContext(),"reconnect!");
@@ -368,7 +368,7 @@
             try {
                 stmt = c.createStatement();
                 stmt.setMaxRows(0);
-                return unmarshal_result(recv, stmt.executeQuery(sql.toString()));
+                return unmarshal_result(recv, stmt.executeQuery(sql.convertToString().getUnicodeValue()));
             } catch(SQLException e) {
                 if(c.isClosed()) {
                     recv.callMethod(recv.getRuntime().getCurrentContext(),"reconnect!");
@@ -391,7 +391,7 @@
             Statement stmt = null;
             try {
                 stmt = c.createStatement();
-                stmt.executeUpdate(sql.toString(), Statement.RETURN_GENERATED_KEYS);
+                stmt.executeUpdate(sql.convertToString().getUnicodeValue(), Statement.RETURN_GENERATED_KEYS);
                 return unmarshal_id_result(recv.getRuntime(), stmt.getGeneratedKeys());
             } catch(SQLException e) {
                 if(c.isClosed()) {
@@ -554,7 +554,7 @@
             if(vs == null || rs.wasNull()) {
                 return runtime.getNil();
             }
-            return runtime.newString(vs);
+            return RubyString.newUnicodeString(runtime, vs);
         }
     }
 

Added: trunk/activerecord-jdbc/test/mysql_multibyte_test.rb (0 => 591)


--- trunk/activerecord-jdbc/test/mysql_multibyte_test.rb	                        (rev 0)
+++ trunk/activerecord-jdbc/test/mysql_multibyte_test.rb	2007-05-17 16:16:58 UTC (rev 591)
@@ -0,0 +1,50 @@
+# To run this script, run the following in a mysql instance:
+#
+#   drop database if exists weblog_development;
+#   create database weblog_development;
+#   grant all on weblog_development.* to [EMAIL PROTECTED];
+
+require 'jdbc_common'
+require 'db/mysql'
+
+require 'java'
+
+include_class 'java.util.Properties'
+include_class 'java.sql.DriverManager'
+
+class ActiveRecord::Base
+  cattr_accessor :defined_connections
+end
+
+class MysqlMultibyteTest < Test::Unit::TestCase
+  include MigrationSetup
+
+  def setup
+    super
+    config = ActiveRecord::Base.defined_connections["ActiveRecord::Base"].config
+    props = Properties.new
+    props.setProperty("user", config[:username])
+    props.setProperty("password", config[:password])
+    @java_con = DriverManager.getConnection(config[:url], props)
+    @java_con.setAutoCommit(true)
+  end
+
+  def teardown
+    @java_con.close
+    super
+  end
+
+  def test_select_multibyte_string
+    @java_con.createStatement().execute("insert into entries (title) values ('テスト')")
+    entry = Entry.find(:first)
+    assert_equal "テスト", entry.title
+    assert_equal entry, Entry.find_by_title("テスト")
+  end
+
+  def test_update_multibyte_string
+    Entry.create!(:title => "テスト")
+    rs = @java_con.createStatement().executeQuery("select title from entries")
+    assert rs.next
+    assert_equal "テスト", rs.getString(1)
+  end
+end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to