[Mono-bugs] [Bug 40616][Wis] New - Unwanted null character in strings returned from SqlDataReader

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Tue, 1 Apr 2003 06:01:06 -0500 (EST)


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 ben.luckham@bimtech.co.uk.

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

--- shadow/40616	Tue Apr  1 06:01:05 2003
+++ shadow/40616.tmp.17042	Tue Apr  1 06:01:05 2003
@@ -0,0 +1,95 @@
+Bug#: 40616
+Product: Mono/Class Libraries
+Version: unspecified
+OS: other
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System.Data.SqlClient
+AssignedTo: rodrigo@ximian.com                            
+ReportedBy: ben.luckham@bimtech.co.uk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Unwanted null character in strings returned from SqlDataReader
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+
+When retrieving a char/varchar column using the SqlDataReader class, the 
+strings returned have an extra \0 character on the end. This does not 
+occur in .NET, and as such, strings obtained in this way in MONO are 1 
+character longer than in .NET. (URL encoding these strings will also 
+produce undesired results).
+
+
+Steps to reproduce the problem:
+1. Please see sample program below.
+2. 
+3. 
+
+Actual Results:
+The following output:
+
+The string retreived is 'Hello'.
+It is 6 characters long.
+When we URL encode it, we get 'Hello%00'.
+
+
+
+Expected Results:
+The following output:
+
+The string retreived is 'Hello'.
+It is 5 characters long.
+When we URL encode it, we get 'Hello'.
+
+
+
+How often does this happen? 
+Always in MONO, never in .NET. As far as I can tell, this only affects 
+char/varchar column types.
+
+
+Additional Information:
+----BEGIN SAMPLE PROGRAM----
+
+using System;
+using System.Data;
+using System.Data.SqlClient;
+
+public class SqlBugDemo
+{
+	public static void Main(string[] args)
+	{
+		// Set up the database connection.
+		string constring = "Data Source=192.168.1.38;"
+					  + "User ID=MergeTxt;"
+					  + "Password=iliketuna;"
+					  + "Pooling=false";
+		IDbConnection dbcon = new SqlConnection(constring);
+		dbcon.Open();
+
+		// Get a string value from the database.
+		IDbCommand dbcmd = dbcon.CreateCommand();
+		dbcmd.CommandText = "SELECT 'Hello' AS Text";
+		IDataReader dbreader = dbcmd.ExecuteReader();
+
+		if (dbreader.Read())
+		{
+			string s = (string)dbreader["Text"];
+			Console.Out.WriteLine("The string retreived is '" 
++ s + "'.");
+			Console.Out.WriteLine("It is " + s.Length + " 
+characters long.");
+			Console.Out.WriteLine("When we URL encode it, we 
+get '" + System.Web.HttpUtility.UrlEncode(s) + "'.");
+		}
+	}
+}
+
+----END SAMPLE PROGRAM----