Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4892 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

DB2 Adapter truncates characters if data received in UTF-8

Reported by: Andrew Dolgov <cthulhoo@gmail.com> Assigned to: David
Priority: normal Milestone:
Component: ActiveRecord Version: 1.1.0
Severity: normal Keywords:
Cc:

Description

(Sorry if it is already fixed in upstream, but for several reasons I can't test this with trunk code. I'm using Rails 1.1.0-release1 package from Debian).

I have 3 russian characters stored in varchar(3) field on my server database in DB2 (iso-8859-5 encoding), which is being accessed using DB2 client w/ utf-8 encoding (DB2CODEPAGE=1208). So the number of bytes actually received is 6.

Resulting property of ActiveRecord object for my table displays only 2 characters, not 3 - last character is truncated. I have traced this problem to active_record/vendor/db2.rb:326.

I'm not familiar enough with rails source to create a "right" fix, but it looks like a buffer size problem and I could fix it with a simple workaround:

--- db2.rb.orig 2006-04-26 14:06:39.000000000 +0400
+++ db2.rb      2006-04-26 14:15:03.000000000 +0400
@@ -305,7 +305,7 @@
 
       retval = []
       cols.each_with_index do |c, i|
-        rc, content = SQLGetData(@handle, i + 1, c[1], c[2] + 1) #yun added 1 to c[2]
+        rc, content = SQLGetData(@handle, i + 1, c[1], c[2] + 50) #yun added 1 to c[2]
         retval << adjust_content(content)
       end
       retval
@@ -323,7 +323,7 @@
 
       retval = {}
       cols.each_with_index do |c, i|
-        rc, content = SQLGetData(@handle, i + 1, c[1], c[2] + 1)   #yun added 1 to c[2]
+        rc, content = SQLGetData(@handle, i + 1, c[1], c[2] + 50)   #yun added 1 to c[2]
         retval[c[0]] = adjust_content(content)
       end
       retval

Change History

08/05/06 02:36:20 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

Please reopen if this is an issue with the latest db2 adapter.