[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
Tue, 25 May 2004 01:45:51 -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 sumadevi@novell.com.

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

--- shadow/49340	2004-05-25 01:45:51.000000000 -0400
+++ shadow/49340.tmp.17056	2004-05-25 01:45:51.000000000 -0400
@@ -0,0 +1,74 @@
+Bug#: 49340
+Product: Mono: Class Libraries
+Version: unspecified
+OS: unknown
+OS Details: 
+Status: RESOLVED   
+Resolution: FIXED
+Severity: Unknown
+Priority: Normal
+Component: Sys.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;
+                                }
+
+------- Additional Comments From sumadevi@novell.com  2004-05-25 01:45 -------
+ 1. "255-character strings padded with garbage returned"
+the fix seems to be in CVS.
+ 
+2. "unixODBC would return the wrong Data Type for columns, often a
+value of '0' for character fields"
+- This issue is not reproducable on mysql system for char datatype.
+The system works as expected. For this I considered the following
+method calls on OdbcDataReader object
+* GetDataTypeName
+* GetFieldType(i).ToString()
+* GetSchemaTable, i.e. After getting SchemaTable, iterating through
+all DataColumns and checking ColumnType column.
+ 
+
+Can you please let us know if there is any specific code that you want
+us to look at. Else we assume that the bug got fixed during some other
+fixes.