[Mono-bugs] [Bug 49340][Nor] New - OdbcDataReader returns garbage padded strings for default data type

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 4 Oct 2003 21:31:07 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by seifert@everybody.org.

http://bugzilla.ximian.com/show_bug.cgi?id=49340

--- shadow/49340	2003-10-04 21:31:07.000000000 -0400
+++ shadow/49340.tmp.11488	2003-10-04 21:31:07.000000000 -0400
@@ -0,0 +1,55 @@
+Bug#: 49340
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: seifert@everybody.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: OdbcDataReader returns garbage padded strings for default data type
+
+While using the ODBC driver for both MySQL and PostgreSQL on Linux, I found
+that unixODBC would return the wrong Data Type for columns, often a value
+of '0' for character fields.  I haven't been able to figure out why, but
+the end result was that I was getting 255-character strings padded with
+garbage returned to me.  I eventually fixed it with the following code in
+OdbcDataReader.cs, which doesn't solve my ODBC data type problem but seems
+to be the Right Thing to do nonetheless.  (patch below)
+
+Index: OdbcDataReader.cs
+===================================================================
+RCS file: /mono/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs,v
+retrieving revision 1.6
+diff -c -r1.6 OdbcDataReader.cs
+*** OdbcDataReader.cs   30 Nov 2002 11:05:14 -0000      1.6
+--- OdbcDataReader.cs   5 Oct 2003 01:22:20 -0000
+***************
+*** 446,452 ****
+                                                bufsize=255;
+                                                buffer=new byte[bufsize];
+                                               
+ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref
+outsize);
+!                                              
+DataValue=System.Text.Encoding.Default.GetString(buffer);
+                                                break;
+                                }
+   
+--- 446,452 ----
+                                                bufsize=255;
+                                                buffer=new byte[bufsize];
+                                               
+ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref
+outsize);
+!                                              
+DataValue=System.Text.Encoding.Default.GetString(buffer,0,outsize);
+                                                break;
+                                }