Example #1
0
        public void ContainsQueriedData()
        {
            int n  = 20;
            var cq = from i in Enumerable.Range(1, n)
                     select new TestObj()
            {
                Name = i.ToString()
            };

            var db = new TestDb(TestPath.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new string[] { "0", "10", "20" };
            var tens  = (from o in db.Table <TestObj>() where tensq.Contains(o.Name) select o).ToList();

            Assert.AreEqual(2, tens.Count);

            var moreq = new string[] { "0", "x", "99", "10", "20", "234324" };
            var more  = (from o in db.Table <TestObj>() where moreq.Contains(o.Name) select o).ToList();

            Assert.AreEqual(2, more.Count);

            // https://github.com/praeclarum/sqlite-net/issues/28
            var moreq2 = moreq.ToList();
            var more2  = (from o in db.Table <TestObj>() where moreq2.Contains(o.Name) select o).ToList();

            Assert.AreEqual(2, more2.Count);
        }
Example #2
0
        public void ContainsConstantData()
        {
            int n  = 20;
            var cq = from i in Enumerable.Range(1, n)
                     select new TestObj()
            {
                Name = i.ToString()
            };

            var db = new TestDb(TestPath.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new string[] { "0", "10", "20" };
            var tens  = (from o in db.Table <TestObj>() where tensq.Contains(o.Name) select o).ToList();

            Assert.AreEqual(2, tens.Count);

            var moreq = new string[] { "0", "x", "99", "10", "20", "234324" };
            var more  = (from o in db.Table <TestObj>() where moreq.Contains(o.Name) select o).ToList();

            Assert.AreEqual(2, more.Count);
        }
Example #3
0
        public void SetUp()
        {
            _db = new TestDb();
            _db.CreateTable <Product> ();
            _db.CreateTable <Order> ();
            _db.CreateTable <OrderLine> ();

            var p1 = new Product {
                Name = "One",
            };
            var p2 = new Product {
                Name = "Two",
            };
            var p3 = new Product {
                Name = "Three",
            };

            _db.InsertAll(new [] { p1, p2, p3 });

            var o1 = new Order {
                PlacedTime = DateTime.Now,
            };
            var o2 = new Order {
                PlacedTime = DateTime.Now,
            };

            _db.InsertAll(new [] { o1, o2 });

            _db.InsertAll(new [] {
                new OrderLine {
                    OrderId   = o1.Id,
                    ProductId = p1.Id,
                    Quantity  = 1,
                },
                new OrderLine {
                    OrderId   = o1.Id,
                    ProductId = p2.Id,
                    Quantity  = 2,
                },
                new OrderLine {
                    OrderId   = o2.Id,
                    ProductId = p3.Id,
                    Quantity  = 3,
                },
            });
        }
Example #4
0
        public void InsertALot()
        {
            int n = 10000;
            var q = from i in Enumerable.Range(1, n)
                    select new TestObj()
            {
                Text = "I am"
            };
            var objs = q.ToArray();

            _db.Trace = false;

            var sw = new Stopwatch();

            sw.Start();

            var numIn = _db.InsertAll(objs);

            sw.Stop();

            Assert.AreEqual(numIn, n, "Num inserted must = num objects");

            var inObjs = _db.CreateCommand("select * from TestObj").ExecuteQuery <TestObj>().ToArray();

            for (var i = 0; i < inObjs.Length; i++)
            {
                Assert.AreEqual(i + 1, objs[i].Id);
                Assert.AreEqual(i + 1, inObjs[i].Id);
                Assert.AreEqual("I am", inObjs[i].Text);
            }

            var numCount = _db.CreateCommand("select count(*) from TestObj").ExecuteScalar <int>();

            Assert.AreEqual(numCount, n, "Num counted must = num objects");
        }
Example #5
0
        SQLiteConnection CreateDb()
        {
            var db = new TestDb();

            db.CreateTable <TestTable> ();
            var items = from i in Enumerable.Range(0, Count)
                        select new TestTable {
                Datum = 1000 + i, Test = "Hello World"
            };

            db.InsertAll(items);
            Assert.AreEqual(Count, db.Table <TestTable> ().Count());
            return(db);
        }
        public void InsertAll()
        {
            var query =
                from p in db.Table <Product>()
                select p;

            Assert.AreEqual(0, changeCount);
            Assert.AreEqual(22, query.Count());

            db.InsertAll(from i in Enumerable.Range(0, 22)
                         select new Product {
                Name = "Test" + i, Price = (decimal)Math.Pow(3, i)
            });

            Assert.AreEqual(23, changeCount);
            Assert.AreEqual(44, query.Count());
        }
Example #7
0
        public void Issue115_MissingPrimaryKey()
        {
            using (var conn = new TestDb()) {
                conn.CreateTable <Issue115_MyObject> ();
                conn.InsertAll(from i in Enumerable.Range(0, 10) select new Issue115_MyObject {
                    UniqueId   = i.ToString(),
                    OtherValue = (byte)(i * 10),
                });

                var query = conn.Table <Issue115_MyObject> ();
                foreach (var itm in query)
                {
                    itm.OtherValue++;
                    Assert.AreEqual(1, conn.Update(itm, typeof(Issue115_MyObject)));
                }
            }
        }
Example #8
0
        public void SetUp()
        {
            db = new TestDb();
            db.CreateTable <Product> ();

            var prods = new[] {
                new Product {
                    Name = "Foo"
                },
                new Product {
                    Name = "Bar"
                },
                new Product {
                    Name = "Foobar"
                },
            };

            db.InsertAll(prods);
        }
        public void SetUp()
        {
            db       = new TestDb();
            db.Trace = true;
            db.CreateTable <Product>();
            db.CreateTable <Order>();
            db.InsertAll(from i in Enumerable.Range(0, 22)
                         select new Product {
                Name = "Thing" + i, Price = (decimal)Math.Pow(2, i)
            });

            changeCount = 0;

            db.TableChanged += (sender, e) => {
                if (e.Table.TableName == "Product")
                {
                    changeCount++;
                    if (!db.IsInTransaction)
                    {
                        Console.WriteLine("this changed called by the end of InsertAll");
                    }
                }
            };
        }