[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-devel-list
Subject: [Mono-devel-list] [PATCH] but in System.Data.UniqueConstraint.AssertConstraint
From: "Eran Domb" <erand () mainsoft ! com>
Date: 2003-09-29 11:22:40
Message-ID: 005f01c3867b$fe7696f0$330111ac () il ! mainsoft ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello
There is a bug in UniqueConstraint.AssertConstraint(DataRow row).
There is no check that values in the row are not null, were it is a
primary key column.
Also check that the row has a proposed version, if not - we get the
current version when we compare the rows.
Attached are TestCase and patch.
Thanks
Eran.
[Attachment #5 (text/html)]
<html xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 10">
<meta name=Originator content="Microsoft Word 10">
<link rel=File-List href="cid:filelist.xml@01C38695.23A74640">
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:DoNotRelyOnCSS/>
</o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:DocumentKind>DocumentEmail</w:DocumentKind>
<w:EnvelopeVis/>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;
text-underline:single;}
span.EmailStyle17
{mso-style-type:personal-compose;
mso-style-noshow:yes;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
font-family:Arial;
mso-ascii-font-family:Arial;
mso-hansi-font-family:Arial;
mso-bidi-font-family:Arial;
color:windowtext;}
span.SpellE
{mso-style-name:"";
mso-spl-e:yes;}
span.GramE
{mso-style-name:"";
mso-gram-e:yes;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";}
</style>
<![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Hello<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>There is a bug in <span class=SpellE><span \
class=GramE>UniqueConstraint.AssertConstraint</span></span><span \
class=GramE>(</span><span class=SpellE>DataRow</span> \
row).<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>There is no check that values in the row are not null, were
it is a primary key column.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Also check that the row has a proposed version, if not - we
get the current version when we compare the rows.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Attached are <span class=SpellE>TestCase</span> and \
patch.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Thanks<o:p></o:p></span></font></p>
<p class=MsoNormal><span class=GramE><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>Eran.</span></font></span><font
size=2 face=Arial><span \
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></font></p>
</div>
</body>
</html>
["UniqueConstraint.cs.diff" (application/octet-stream)]
--- C:\DIFF\old\System.Data\System.Data\UniqueConstraint.cs 2003-09-22 \
16:34:51.000000000 +0300
+++ c:\DIFF\new\System.Data\System.Data\UniqueConstraint.cs 2003-09-25 \
08:26:52.000000000 +0300 @@ -409,6 +409,16 @@
if (_dataColumns == null) return; //???
//Unique?
+ // check that the row has values for all columns in the constarint.
+ object val;
+ for (int i = 0; i < _dataColumns.Length; i++)
+ {
+
+ val = row[_dataColumns[i]];
+ if (val == null || val == DBNull.Value)
+ throw new NoNullAllowedException("Column '" + _dataColumns[i].ColumnName + "' \
does not allow nulls."); + }
+
DataTable tbl = _dataTable;
bool isValid;
foreach(DataRow compareRow in tbl.Rows)
@@ -419,12 +429,17 @@
{
//FIXME: should we compare to compareRow[DataRowVersion.Current]?
//FIXME: We need to compare to all columns the constraint is set to.
-
+ object rowVal;
for (int i = 0; i < _dataColumns.Length; i++)
{
+ if(row.HasVersion(DataRowVersion.Proposed))
+ rowVal = row[_dataColumns[i], DataRowVersion.Proposed];
+ else
+ rowVal = row[_dataColumns[i], DataRowVersion.Current];
+
// if the values in the row are not equal to the values of
// the original row from the table we can move to the next row.
- if(!row[_dataColumns[i]].Equals( compareRow[_dataColumns[i]]))
+ if(!rowVal.Equals( compareRow[_dataColumns[i]]))
{
isValid = true;
break;
["UniqueConstraintTest.cs" (text/plain)]
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
namespace Nunittest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
[NUnit.Framework.TestFixture]
public class UniqueConstraintTest : NUnit.Framework.Assertion
{
[NUnit.Framework.Test]
public void TestAssertConstraint()
{
DataSet ds = new DataSet();
DataTable table = new DataTable("1");
table.Columns.Add("name");
table.Rows.Add(new object[] {"John"});
table.Rows.Add(new object[] {"Sara"});
table.PrimaryKey = new DataColumn[] {table.Columns[0]};
ds.Tables.Add(table);
DataRow r = table.NewRow();
try
{
table.Rows.Add(r);
Fail("Exception not thrown if PK values are missing");
}
catch (System.Data.NoNullAllowedException)
{
}
}
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic