Ejemplo n.º 1
0
        public void TestSimpleWhere()
        {
            var paramsCollection = new ParamsCollection();

            var where = new WhereSequence("key", Is.EqualWith, "val", paramsCollection);
            Assert.AreEqual("key = @" + Math.Abs("val".GetHashCode()), where.ToString());
        }
Ejemplo n.º 2
0
        public void TestNull()
        {
            var collection = new ParamsCollection();

            collection.GetIdentifier(null);
            Assert.AreEqual(0, collection.Params.Count);
        }
Ejemplo n.º 3
0
        public void TestSimpleAndOr()
        {
            var paramsCollection = new ParamsCollection();

            var where = new WhereSequence("a", Is.EqualWith, "b", paramsCollection).Or("c", Is.EqualWith, "d").And("e", Is.EqualWith, "f");
            Assert.AreEqual(string.Format("a = @{0} OR c = @{1} AND e = @{2}",
                                          Math.Abs("b".GetHashCode()), Math.Abs("d".GetHashCode()), Math.Abs("f".GetHashCode())), where.ToString());
        }
Ejemplo n.º 4
0
        public void TestCollection()
        {
            var collection = new ParamsCollection();

            Assert.AreEqual("@" + Math.Abs("test".GetHashCode()), collection.GetIdentifier("test"));
            Assert.AreEqual(1, collection.Params.Count);
            Assert.AreEqual("@" + Math.Abs("test".GetHashCode()), collection.Params.First().Key);
            Assert.AreEqual("test", collection.Params.First().Value);
        }
Ejemplo n.º 5
0
        public void TestComplex()
        {
            var paramsCollection = new ParamsCollection();

            var where = new WhereSequence("a", Is.EqualWith, "b", paramsCollection).And(
                subsequence => subsequence.Where("c", Is.EqualWith, "d").Or("e", Is.EqualWith, "f").Or(
                    secondLevel => secondLevel.Where("g", Is.EqualWith, "h").And("i", Is.EqualWith, "j")
                    )
                ).Or("k", Is.EqualWith, "l");

            Assert.AreEqual(string.Format("a = @{0} AND (c = @{1} OR e = @{2} OR (g = @{3} AND i = @{4})) OR k = @{5}",
                                          Math.Abs("b".GetHashCode()), Math.Abs("d".GetHashCode()), Math.Abs("f".GetHashCode()),
                                          Math.Abs("h".GetHashCode()), Math.Abs("j".GetHashCode()), Math.Abs("l".GetHashCode())), where.ToString());
        }
Ejemplo n.º 6
0
        public InsertBatch(IEnumerable <string> columns, IEnumerable <IConvertible> values, ParamsCollection paramsCollection)
        {
            var colArray    = columns as string[] ?? columns.ToArray();
            var valuesArray = values as IConvertible[] ?? values.ToArray();

            if (colArray.Count() != valuesArray.Count())
            {
                throw new InvalidOperationException("La ligne doit compter " + colArray.Count() + " colonnes");
            }

            Sql = valuesArray.Aggregate("(", (current, value) => current + (paramsCollection.GetIdentifier(value) + ", ")).TrimEnd(' ', ',') + ")";
        }
Ejemplo n.º 7
0
 public WhereSequence(string key, IBinaryOperator binOperator, IConvertible value, ParamsCollection parentCollection)
 {
     _parentCollection = parentCollection;
     _sequence         = binOperator.ToString(key, parentCollection.GetIdentifier(value));
 }
Ejemplo n.º 8
0
 internal SubSequence(ParamsCollection parentCollection)
 {
     _parentCollection = parentCollection;
 }
Ejemplo n.º 9
0
 protected StatementAbstract(string tableName)
 {
     TableName = tableName;
     Params    = new ParamsCollection();
 }