[Mono-bugs] [Bug 582838] New: DataAdapter sends null values to database in the Update method.
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Feb 24 13:25:47 EST 2010
http://bugzilla.novell.com/show_bug.cgi?id=582838
http://bugzilla.novell.com/show_bug.cgi?id=582838#c0
Summary: DataAdapter sends null values to database in the
Update method.
Classification: Mono
Product: Mono: Class Libraries
Version: 2.6.x
Platform: All
OS/Version: All
Status: NEW
Severity: Critical
Priority: P5 - None
Component: Sys.Data
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: kuritsu at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
Created an attachment (id=344554)
--> (http://bugzilla.novell.com/attachment.cgi?id=344554)
This a MonoDevelop project with the test case.
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; es-MX; rv:1.9.1.5)
Gecko/20091109 Ubuntu/9.10 (karmic) Firefox/3.5.5
I have an SqliteDataAdapter instance (and also tried with OracleDataAdapter)
with a connection and select command. I also have a Sqlite database with a
table with several rows not null. When I use the adapter.Fill method it fills a
DataSet correctly. But, after I insert a new row in the dataset with non null
columns, and then call the adapter.Update method, all the column values are
lost and the table has a new row with all columns null (except the one that is
autonumeric).
Reproducible: Always
Steps to Reproduce:
1. Create a C# console project in MonoDevelop.
2. Add references to Mono.Data.Sqlite and System.Data.
3. Add usings to Mono.Data.Sqlite and System.Data.
4. Put the following code in the Main method of the main class:
SqliteConnection connection = new SqliteConnection("Data
Source=MySqliteSample.db");
SqliteDataAdapter adapter = new SqliteDataAdapter("SELECT ID, Name FROM
sampletable",
connection);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
Console.WriteLine ("Original dataset: ");
dataSet.Tables[0].WriteXml(Console.Out);
dataSet.Tables[0].LoadDataRow(new object[]{3, "Jeff"}, false);
adapter.InsertCommand = new SqliteCommand("INSERT INTO sampletable (ID, Name)
VALUES (@ID, @Name)", connection);
adapter.InsertCommand.Parameters.Add("@ID", DbType.Int32);
adapter.InsertCommand.Parameters[0].SourceColumn = "ID";
adapter.InsertCommand.Parameters.Add("@Name", DbType.String);
adapter.InsertCommand.Parameters[1].SourceColumn = "Name";
adapter.Update(dataSet);
dataSet = new DataSet();
adapter.Fill(dataSet);
Console.WriteLine (Environment.NewLine + Environment.NewLine + "New dataset:
");
dataSet.Tables[0].WriteXml(Console.Out);
5. Create a new Sqlite database with name MySqliteSample.db using this script:
BEGIN TRANSACTION;
CREATE TABLE "SampleTable" (
"ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"Name" TEXT
);
INSERT INTO "SampleTable" VALUES(1,'Dave');
INSERT INTO "SampleTable" VALUES(2,'Alice');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('SampleTable',2);
COMMIT;
6. Compile the project and put the database in the output folder (bin/Debug).
7. Run the project and check the output.
Actual Results:
This is the console output:
Original dataset:
<NewDataSet>
<Table>
<ID>1</ID>
<Name>Dave</Name>
</Table>
<Table>
<ID>2</ID>
<Name>Alice</Name>
</Table>
</NewDataSet>
New dataset after insert:
<NewDataSet>
<Table>
<ID>1</ID>
<Name>Dave</Name>
</Table>
<Table>
<ID>2</ID>
<Name>Alice</Name>
</Table>
<Table>
<ID>3</ID>
</Table>
</NewDataSet>
As you can see, the 3rd row has no Name column, so it's null.
Expected Results:
This is what the console should output:
Original dataset:
<NewDataSet>
<Table>
<ID>1</ID>
<Name>Dave</Name>
</Table>
<Table>
<ID>2</ID>
<Name>Alice</Name>
</Table>
</NewDataSet>
New dataset after insert:
<NewDataSet>
<Table>
<ID>1</ID>
<Name>Dave</Name>
</Table>
<Table>
<ID>2</ID>
<Name>Alice</Name>
</Table>
<Table>
<ID>3</ID>
<Name>Jeff</Name>
</Table>
</NewDataSet>
Notice the 3rd row is complete, including Jeff in the Name column.
Remember to install Sqlite to run the test project.
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list