BUILT_SOURCES = Mono.Data.SqlExpressions/Parser.cs
Mono.Data.SqlExpressions/Parser.cs: Mono.Data.SqlExpressions/Parser.jay $(topdir)/jay/skeleton.cs
- $(topdir)/jay/jay -ct < $(topdir)/jay/skeleton.cs $(CURDIR)/$< >$@
+ $(topdir)/jay/jay -vct < $(topdir)/jay/skeleton.cs $(CURDIR)/$< >$@
include ../../build/library.make
// Juraj Skripsky (juraj@hotfeet.ch)
//
// (C) 2004 HotFeet GmbH (http://www.hotfeet.ch)
+// Copyright 2011 Xamarin Inc (http://www.xamarin.com)
//
using System;
| NumberLiteral { $$ = new Literal ($1); }
| DateLiteral { $$ = new Literal ($1); }
| BoolLiteral
+ | NULL { $$ = new Literal (null); }
;
BoolLiteral
;
StringExpr
- : PAROPEN StringExpr PARCLOSE
- {
- $$ = (IExpression)$2;
- }
- | SingleColumnValue
+ : SingleColumnValue
| StringLiteral { $$ = new Literal ($1); }
- | StringFunction
+ | Function
;
StringFunction
- : TRIM PAROPEN StringExpr PARCLOSE
+ : TRIM PAROPEN ArithExpr PARCLOSE
{
$$ = new TrimFunction ((IExpression)$3);
}
- | SUBSTRING PAROPEN StringExpr COMMA ArithExpr COMMA ArithExpr PARCLOSE
+ | SUBSTRING PAROPEN ArithExpr COMMA ArithExpr COMMA ArithExpr PARCLOSE
{
$$ = new SubstringFunction ((IExpression)$3, (IExpression)$5, (IExpression)$7);
}
- | StringExpr PLUS StringExpr
- {
- $$ = new ConcatFunction ((IExpression)$1, (IExpression)$3);
- }
;
CalcFunction
}
}
- internal class ConcatFunction : StringFunction
- {
- readonly IExpression _add;
- public ConcatFunction (IExpression e, IExpression add)
- : base (e)
- {
- _add = add;
- }
-
- public override bool Equals(object obj)
- {
- if (!base.Equals (obj))
- return false;
-
- if (!(obj is ConcatFunction))
- return false;
-
- ConcatFunction other = (ConcatFunction) obj;
- return _add.Equals (other._add);
- }
-
- public override int GetHashCode()
- {
- int hashCode = base.GetHashCode ();
- hashCode ^= _add.GetHashCode ();
- return hashCode;
- }
-
- override public object Eval (DataRow row) {
- string str = (string) base.Eval (row);
- string x = (string) _add.Eval (row);
-
- return str + x;
- }
- }
-
internal class SubstringFunction : StringFunction {
IExpression start;
IExpression len;
// (C) Copyright 2002 Rodrigo Moya
// (C) Copyright 2003 Daniel Morgan
// (C) Copyright 2003 Martin Willemoes Hansen
-//
+// (C) Copyright 2011 Xamarin Inc
//
+// Copyright 2011 Xamarin Inc (http://www.xamarin.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
Assert.Fail ("SetOrdinalTest failed");
}
}
+
+ [Test]
+ public void Xamarin665 ()
+ {
+ var t = new DataTable() ;
+ var c1 = t.Columns.Add ("c1");
+ var c2 = t.Columns.Add ("c2");
+ c2.Expression = "TRIM(ISNULL(c1,' '))";
+ c2.Expression = "SUBSTRING(ISNULL(c1,' '), 1, 10)";
+ }
+
+ DataColumn MakeColumn (string col, string test)
+ {
+ return new DataColumn () {
+ ColumnName = col,
+ Expression = test
+ };
+ }
+
+#if false
+// Check Windows output for the row [0] value
+ [Test]
+ public void NullStrings ()
+ {
+ var a = MakeColumn ("nullbar", "null+'bar'");
+ var b = MakeColumn ("barnull", "'bar'+null");
+ var c = MakeColumn ("foobar", "'foo'+'bar'");
+
+ var table = new DataTable();
+
+ table.Columns.Add(a);
+ table.Columns.Add(b);
+ table.Columns.Add(c);
+
+ var row = table.NewRow();
+ table.Rows.Add(row);
+ Assert.AreEqual (row [0], DBNull.Value, "#1");
+ Assert.AreEqual (row [1], DBNull.Value, "#2");
+ Assert.AreEqual (row [2], "foobar", "#3");
+ }
+#endif
}
}