Author: senga
Date: 2006-06-15 08:02:57 -0400 (Thu, 15 Jun 2006)
New Revision: 61754
Modified:
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ChangeLog
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ColumnReference.cs
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Expressions.cs
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/In.cs
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Like.cs
trunk/mcs/class/System.Data/System.Data/ChangeLog
trunk/mcs/class/System.Data/System.Data/DataTable.cs
trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
trunk/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs
Log:
2006-06-15 Senganal T <[EMAIL PROTECTED]>
* Test/System.Data/DataTableTest2.cs :
- Test if the Sort Order is correct when Sort String is not
explicitly set.
- Test if EvaluateException is raised if filter is not a
boolean expression.
- Test if expression is evaluated corrected when the filter
is a boolean column.
* Mono.Data.SqlExpressions/Expression.cs :
- EvalBoolean : throw EvaluateException unless overridden.
- UnaryExpression.EvalBoolean : override EvalBoolean
* Mono.Data.SqlExpressions/Like.cs, In.cs, ColumnReference.cs :
override EvalBoolean
* System.Data/DataTable.cs :
- Select : If Sort String is not provided, sort the result
DataRows in Ascending Order of the Columns used in the filter
Modified: trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ChangeLog
2006-06-15 11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ChangeLog
2006-06-15 12:02:57 UTC (rev 61754)
@@ -1,3 +1,10 @@
+2006-06-15 Senganal T <[EMAIL PROTECTED]>
+
+ * Expression.cs :
+ - EvalBoolean : throw EvaluateException unless overridden.
+ - UnaryExpression.EvalBoolean : override EvalBoolean
+ * Like.cs, In.cs, ColumnReference.cs : override EvalBoolean
+
2006-06-09 Juraj Skripsky <[EMAIL PROTECTED]>
* Tokenizer.cs (ProcessEscapes): Inspect the next character, not the one
Modified:
trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ColumnReference.cs
===================================================================
--- trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ColumnReference.cs
2006-06-15 11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/ColumnReference.cs
2006-06-15 12:02:57 UTC (rev 61754)
@@ -221,6 +221,19 @@
return Unify (val);
}
+ public override bool EvalBoolean (DataRow row)
+ {
+ DataColumn col = GetColumn (row);
+ if (col.DataType != typeof (bool))
+ throw new EvaluateException ("Not a Boolean
Expression");
+
+ object result = Eval (row);
+ if (result == null || result == DBNull.Value)
+ return false;
+ else
+ return (bool)result;
+ }
+
override public bool DependsOn(DataColumn other)
{
return refTable == ReferencedTable.Self && columnName
== other.ColumnName;
Modified: trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Expressions.cs
===================================================================
--- trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Expressions.cs
2006-06-15 11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Expressions.cs
2006-06-15 12:02:57 UTC (rev 61754)
@@ -31,6 +31,7 @@
//
using System;
+using System.Data.Common;
using System.Collections;
using System.Data;
@@ -49,7 +50,7 @@
public virtual bool EvalBoolean (DataRow row)
{
- return (bool) Eval (row);
+ throw new EvaluateException ("Not a Boolean
Expression");
}
public override bool Equals(object obj)
@@ -102,6 +103,11 @@
override public bool DependsOn(DataColumn other) {
return expr.DependsOn(other);
}
+
+ override public bool EvalBoolean (DataRow row)
+ {
+ return (bool) Eval (row);
+ }
}
internal abstract class BinaryExpression : BaseExpression {
Modified: trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/In.cs
===================================================================
--- trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/In.cs 2006-06-15
11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/In.cs 2006-06-15
12:02:57 UTC (rev 61754)
@@ -101,5 +101,11 @@
return false;
}
+
+ override public bool EvalBoolean (DataRow row)
+ {
+ return (bool) Eval (row);
+ }
+
}
}
Modified: trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Like.cs
===================================================================
--- trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Like.cs
2006-06-15 11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Mono.Data.SqlExpressions/Like.cs
2006-06-15 12:02:57 UTC (rev 61754)
@@ -96,5 +96,10 @@
return (idx == 0 || openStart) && (idx + pattern.Length
== str.Length || openEnd);
}
+
+ override public bool EvalBoolean (DataRow row)
+ {
+ return (bool)Eval (row);
+ }
}
}
Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog 2006-06-15 11:31:44 UTC
(rev 61753)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog 2006-06-15 12:02:57 UTC
(rev 61754)
@@ -1,7 +1,13 @@
2006-06-15 Senganal T <[EMAIL PROTECTED]>
+ * DataTable.cs :
+ - Select : If Sort String is not provided, sort the result
+ DataRows in Ascending Order of the Columns used in the filter
+
+2006-06-15 Senganal T <[EMAIL PROTECTED]>
+
* DataSet.cs :
- - InternalEnforceConstraints : Check if any null constraints
+ - InternalEnforceConstraints : Check if any null constraints
are violated. Throw ConstraintException only after all the
errors
are filled.
* DataTable.cs :
Modified: trunk/mcs/class/System.Data/System.Data/DataTable.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTable.cs 2006-06-15
11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/System.Data/DataTable.cs 2006-06-15
12:02:57 UTC (rev 61754)
@@ -1557,15 +1557,31 @@
if (filterExpression == null)
filterExpression = String.Empty;
+ IExpression filter = null;
+ if (filterExpression != String.Empty) {
+ Parser parser = new Parser ();
+ filter = parser.Compile (filterExpression);
+ }
+
DataColumn[] columns = _emptyColumnArray;
ListSortDirection[] sorts = null;
+
if (sort != null && !sort.Equals(String.Empty))
columns = ParseSortString (this, sort, out
sorts, false);
- IExpression filter = null;
- if (filterExpression != String.Empty) {
- Parser parser = new Parser ();
- filter = parser.Compile (filterExpression);
+ if (Rows.Count == 0)
+ return new DataRow [0];
+
+ //if sort order is not given, sort it in Ascending
order of the
+ //columns involved in the filter
+ if (columns.Length ==0 && filter != null) {
+ ArrayList list = new ArrayList ();
+ for (int i=0, j=0; i < Columns.Count; ++i) {
+ if (!filter.DependsOn (Columns [i]))
+ continue;
+ list.Add (Columns [i]);
+ }
+ columns = (DataColumn[])list.ToArray (typeof
(DataColumn));
}
Index index = GetIndex(columns, sorts, recordStates,
filter, false);
@@ -1577,7 +1593,6 @@
return dataRows;
}
-
private void AddIndex (Index index)
{
Modified: trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/ChangeLog 2006-06-15
11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Test/System.Data/ChangeLog 2006-06-15
12:02:57 UTC (rev 61754)
@@ -1,5 +1,15 @@
2006-06-15 Senganal T <[EMAIL PROTECTED]>
+ * DataTableTest2.cs :
+ - Test if the Sort Order is correct when Sort String is not
+ explicitly set.
+ - Test if EvaluateException is raised if filter is not a
+ boolean expression.
+ - Test if expression is evaluated corrected when the filter
+ is a boolean column.
+
+2006-06-15 Senganal T <[EMAIL PROTECTED]>
+
* DataSetTest2.cs : Test the behavior of EnforceConstraints
* DataViewTest_IBindingList.cs : Test to ensure the correct index is
used for comparision
Modified: trunk/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs
2006-06-15 11:31:44 UTC (rev 61753)
+++ trunk/mcs/class/System.Data/Test/System.Data/DataTableTest2.cs
2006-06-15 12:02:57 UTC (rev 61754)
@@ -2253,6 +2253,65 @@
dt.Select(dt.Columns[0].ColumnName,dt.Columns[0].ColumnName + "1");
}
+ [Test]
+ public void Select_NonBooleanFilter ()
+ {
+ DataTable table = new DataTable ();
+ table.Columns.Add ("col1", typeof (int));
+
+ DataRow[] row = table.Select ("col1*10");
+ Assert.AreEqual (0, row.Length, "#1");
+
+ // No exception shud be thrown
+ // The filter created earlier (if cached), will raise
an EvaluateException
+ // and so shouldnt be cached
+ for (int i=0; i < 5; ++i)
+ table.Rows.Add (new object[] {i});
+
+ try {
+ table.Select ("col1*10");
+ Assert.Fail ("#2 Invalid Filter.. Should return
a Boolean result");
+ } catch (EvaluateException) {
+ }
+ }
+
+ [Test]
+ public void Select_BoolColumn ()
+ {
+ DataTable table = new DataTable ();
+ table.Columns.Add ("col1", typeof (int));
+ table.Columns.Add ("col2", typeof (bool));
+
+ for (int i=0; i < 5; i++)
+ table.Rows.Add (new object[] {i});
+
+ DataRow[] result;
+ try {
+ result = table.Select ("col1");
+ Assert.Fail ("#1 col1 is not a boolean
expression");
+ } catch (EvaluateException) {
+ }
+
+ //col2 is a boolean expression, and a null value
translates to
+ //false.
+ result = table.Select ("col2");
+ Assert.AreEqual (0, result.Length);
+ }
+
+ [Test]
+ public void Select_OrderOfRows ()
+ {
+ DataTable table = new DataTable ();
+ table.Columns.Add ("col1", typeof (int));
+ table.Columns.Add ("col2", typeof (int));
+
+ for (int i=0; i < 10; i++)
+ table.Rows.Add (new object[] {10-i, i});
+ DataRow[] result = table.Select ("col1 > 5");
+
+ Assert.AreEqual (6, result [0][0], "# incorrect sorting
order");
+ }
+
internal class DataRowsComparer : System.Collections.IComparer
{
#region Memebers
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches