public void HasUnplacedHolders() { SqlPredicate p; p = new SqlPredicate("@PH"); Assert.That(p.HasUnplacedHolders(), Is.True); p.Place("PH", "'abc' <= 'abcd'"); Assert.That(p.HasUnplacedHolders(), Is.False); p = new SqlPredicate("@PH1 And @PH2"); p.Place("PH1", "x = +100"); Assert.That(p.HasUnplacedHolders(), Is.True); p.Place("PH2", "y = -9"); Assert.That(p.HasUnplacedHolders(), Is.False); p = new SqlPredicate("@PH AND @PH"); p.Place("PH", "'abc' <= 'abcd'"); Assert.That(p.HasUnplacedHolders(), Is.False); p.Place("PH", "'abc' <= 'abcd'"); Assert.That(p.HasUnplacedHolders(), Is.False); }
public void GetAllPlaceHolders() { SqlPredicate p; p = new SqlPredicate("@PH"); Assert.That(p.GetAllPlaceHolders() , Is.EqualTo(new Dictionary <string, string> { { "PH", "" } })); p.Place("PH", "'abc' > 0"); Assert.That(p.GetAllPlaceHolders() , Is.EqualTo(new Dictionary <string, string> { { "PH", "'abc'>0" } })); p = new SqlPredicate("@PH1 And @PH2"); p.Place("PH1", "x=+100"); Assert.That(p.GetAllPlaceHolders(), Is.EqualTo(new Dictionary <string, string> { { "PH1", "x=+100" }, { "PH2", "" } })); p.Place("PH2", "y = -9"); Assert.That(p.GetAllPlaceHolders(), Is.EqualTo(new Dictionary <string, string> { { "PH1", "x=+100" }, { "PH2", "y=-9" } })); p = new SqlPredicate("@PH AND @PH"); p.Place("PH", "x = 'abc'"); Assert.That(p.GetAllPlaceHolders(), Is.EqualTo(new Dictionary <string, string> { { "PH", "x='abc'" } })); p.Place("PH", "x = 'abc'"); Assert.That(p.GetAllPlaceHolders(), Is.EqualTo(new Dictionary <string, string> { { "PH", "x='abc'" } })); }
public void Empty() { SqlPredicate p = new SqlPredicate(); Assert.That(p.And(p).ToString(), Is.EqualTo("")); Assert.That(p.Clone().ToString(), Is.EqualTo("")); Assert.That(p.GetAllPlaceHolders(), Is.EqualTo(new string[] { })); Assert.That(p.HasUnplacedHolder("T"), Is.False); Assert.That(p.HasUnplacedHolders(), Is.False); Assert.That(p.IsEmpty, Is.True); Assert.That(p.IsPlaceHolderOnly, Is.False); p.Place("PH", "a=1"); Assert.That(p.ToString(), Is.EqualTo("")); }
public void Place() { SqlPredicate p; p = new SqlPredicate("not c > 1"); p.Place("PH", "a"); Assert.That(p.ToString(), Is.EqualTo("NOT c>1")); p = new SqlPredicate("@PH"); Assert.Throws <CannotBuildASTException>(() => { p.Place("PH", "1"); }); p = new SqlPredicate("@PH"); p.Place("PH", "a=1"); Assert.That(p.ToString(), Is.EqualTo("a=1")); p = new SqlPredicate("Not @PH"); p.Place("PH", "x=2 or y=3"); Assert.That(p.ToString(), Is.EqualTo("NOT (x=2 OR y=3)")); }
public void Place2() { SqlPredicate p; // // Predicate演算子の結合の優先順位が適用前後で変わらないことを確認する // p = new SqlPredicate("@PH"); p.Place("PH", "a=1 and b=2"); Assert.That(p.ToString(), Is.EqualTo("a=1 AND b=2")); p = new SqlPredicate("@PH"); p.Place("PH", "a=1 or b=2"); Assert.That(p.ToString(), Is.EqualTo("a=1 OR b=2")); p = new SqlPredicate("@PH"); p.Place("PH", "not a=1"); Assert.That(p.ToString(), Is.EqualTo("NOT a=1")); p = new SqlPredicate("@PH"); p.Place("PH", "a=1 collate jp"); Assert.That(p.ToString(), Is.EqualTo("a=1 COLLATE jp")); p = new SqlPredicate("@PH AND 1 = 1"); p.Place("PH", "a=1 and b=2"); Assert.That(p.ToString(), Is.EqualTo("a=1 AND b=2 AND 1=1")); p = new SqlPredicate("@PH AND 1 = 1"); p.Place("PH", "a=1 or b=2"); Assert.That(p.ToString(), Is.EqualTo("(a=1 OR b=2) AND 1=1")); p = new SqlPredicate("@PH AND 1 = 1"); p.Place("PH", "not a=1"); Assert.That(p.ToString(), Is.EqualTo("NOT a=1 AND 1=1")); p = new SqlPredicate("@PH AND 1 = 1"); p.Place("PH", "a=1 collate jp"); Assert.That(p.ToString(), Is.EqualTo("a=1 COLLATE jp AND 1=1")); p = new SqlPredicate("@PH OR 1 = 1"); p.Place("PH", "a=1 and b=2"); Assert.That(p.ToString(), Is.EqualTo("a=1 AND b=2 OR 1=1")); p = new SqlPredicate("@PH OR 1 = 1"); p.Place("PH", "a=1 or b=2"); Assert.That(p.ToString(), Is.EqualTo("a=1 OR b=2 OR 1=1")); p = new SqlPredicate("@PH OR 1 = 1"); p.Place("PH", "not a=1"); Assert.That(p.ToString(), Is.EqualTo("NOT a=1 OR 1=1")); p = new SqlPredicate("@PH OR 1 = 1"); p.Place("PH", "a=1 collate jp"); Assert.That(p.ToString(), Is.EqualTo("a=1 COLLATE jp OR 1=1")); p = new SqlPredicate("Not @PH"); p.Place("PH", "a=1 and b=2"); Assert.That(p.ToString(), Is.EqualTo("NOT (a=1 AND b=2)")); p = new SqlPredicate("Not @PH"); p.Place("PH", "a=1 or b=2"); Assert.That(p.ToString(), Is.EqualTo("NOT (a=1 OR b=2)")); p = new SqlPredicate("Not @PH"); p.Place("PH", "not a=1"); Assert.That(p.ToString(), Is.EqualTo("NOT NOT a=1")); p = new SqlPredicate("Not @PH"); p.Place("PH", "a=1 collate jp"); Assert.That(p.ToString(), Is.EqualTo("NOT a=1 COLLATE jp")); p = new SqlPredicate("@PH collate jp"); p.Place("PH", "a=1 and b=2"); Assert.That(p.ToString(), Is.EqualTo("(a=1 AND b=2) COLLATE jp")); p = new SqlPredicate("@PH collate jp"); p.Place("PH", "a=1 or b=2"); Assert.That(p.ToString(), Is.EqualTo("(a=1 OR b=2) COLLATE jp")); p = new SqlPredicate("@PH collate jp"); p.Place("PH", "not a=1"); Assert.That(p.ToString(), Is.EqualTo("NOT a=1 COLLATE jp")); p = new SqlPredicate("@PH collate jp"); p.Place("PH", "a=1 collate jp"); Assert.That(p.ToString(), Is.EqualTo("a=1 COLLATE jp COLLATE jp")); }