[Mono-bugs] [Bug 78544][Wis] New - [PATCH] Sqlite Should Return DBNull.Value for fields with null values

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed May 31 00:05:47 EDT 2006


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 jhill at arcfocus.com.

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

--- shadow/78544	2006-05-31 00:05:47.000000000 -0400
+++ shadow/78544.tmp.22969	2006-05-31 00:05:47.000000000 -0400
@@ -0,0 +1,84 @@
+Bug#: 78544
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: tsenganal at novell.com                            
+ReportedBy: jhill at arcfocus.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: [PATCH] Sqlite Should Return DBNull.Value for fields with null values
+
+Description of Problem:
+SqliteDataReader should return DBNull for fields which have a null value. 
+Currently, IsDBNull correctly reports that fields with a null value are
+DBNull; however, when the value is requested, the reader will return null,
+which can cause a System.NullReferenceException to be thrown when the value
+is accessed.  
+
+Steps to reproduce the problem:
+1. Create and populate sqlite database:
+
+CREATE TABLE `FirstTable` (
+  `TextField` TEXT NOT NULL default '',
+  `EmptyField` TEXT NULL
+);
+
+INSERT INTO FirstTable (TextField) Values ("Some Text");
+
+
+2. Create a C# program to access this data:
+using System;
+using System.Data;
+using Mono.Data.SqliteClient;
+
+namespace AppX
+{
+	class X
+	{
+		static void Main(string[] args)
+		{
+			SqliteCommand cmd = new SqliteCommand();
+			SqliteConnection connection = new
+SqliteConnection(@"version=3,URI=file:C:\Temp\x.db");
+			connection.Open();
+			cmd.Connection = connection;
+			cmd.CommandText = "SELECT * FROM FirstTable;";
+			cmd.CommandType = CommandType.Text;
+					
+			SqliteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
+
+			while(dr.Read()) {
+				Console.WriteLine("null SqliteDataReader field .ToString() looks like:
+" + dr["EmptyField"].ToString());
+			}
+		}
+	}
+}
+
+3. Build x.cs:
+mcs x.cs -r:Mono.Data.SqliteClient -r:System.Data
+
+4. Execute x.exe
+mono x.exe
+
+Actual Results:
+Unhandled Exception: System.NullReferenceException: Object reference not set to
+an instance of an object
+in <0x000a3> AppX.X:Main (System.String[] args)
+
+Expected Results:
+null SqliteDataReader field .ToString() looks like:
+
+How often does this happen? 
+Always
+
+Additional Information:
+Patch attached.


More information about the mono-bugs mailing list