コード例 #1
0
        public void InsertWithExtra()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj2>();

            var obj1 = new TestObj2 {
                Id = 1, Text = "GLaDOS loves testing!"
            };
            var obj2 = new TestObj2 {
                Id = 1, Text = "Keep testing, just keep testing"
            };
            var obj3 = new TestObj2 {
                Id = 1, Text = "Done testing"
            };

            db.Insert(obj1);

            // "Expected unique constraint violation"
            ExceptionAssert.Throws <SqliteException>(() => db.Insert(obj2));

            db.Insert(obj2, ConflictResolution.Replace);

            // "Expected unique constraint violation"
            ExceptionAssert.Throws <SqliteException>(() => db.Insert(obj3));

            db.Insert(obj3, ConflictResolution.Ignore);

            List <TestObj> result = db.Query <TestObj>("select * from TestObj2").ToList();

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(obj2.Text, result.First().Text);

            db.Close();
        }
コード例 #2
0
        public void InsertTwoTimes()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            var obj1 = new TestObj {
                Text = "GLaDOS loves testing!"
            };
            var obj2 = new TestObj {
                Text = "Keep testing, just keep testing"
            };

            int numIn1 = db.Insert(obj1);
            int numIn2 = db.Insert(obj2);

            Assert.AreEqual(1, numIn1);
            Assert.AreEqual(1, numIn2);

            List <TestObj> result = db.Query <TestObj>("select * from TestObj").ToList();

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(obj1.Text, result[0].Text);
            Assert.AreEqual(obj2.Text, result[1].Text);

            db.Close();
        }
コード例 #3
0
        public void InsertUsingNestedSystemTransactions()
        {
            var options = new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (var db = new OrmTestSession())
            {
                using (var trans = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    db.CreateTable <TestObj>();
                    db.Insert(new TestObj {
                        Text = "My Text"
                    });

                    using (var trans2 = new TransactionScope(TransactionScopeOption.Required, options))
                    {
                        db.Insert(new TestObj {
                            Text = "My Text"
                        });
                        trans2.Complete();
                    }

                    trans.Complete();
                }

                Assert.AreEqual(2, db.Table <TestObj>().Count());
            }
        }
コード例 #4
0
        public void StringQueryOnQueryableTable()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable <QueryableTable>();
                db.Insert(new QueryableTable {
                    Name = "sqlite"
                });
                db.Insert(new QueryableTable {
                    Name = "sqlevy"
                });
                db.Insert(new QueryableTable {
                    Name = "cars"
                });
                db.Insert(new QueryableTable {
                    Name = "we know sqlite is cool"
                });
                db.Insert(new QueryableTable {
                    Name = "we think sqlites"
                });

                var count = db.ExecuteScalar <int>(
                    "SELECT COUNT(*) FROM [QueryableTable] WHERE [Name] MATCH ?", "sqlite");

                Assert.AreEqual(3, count);
            }
        }
コード例 #5
0
        public void InsertIntoTwoTables()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();
            db.CreateTable <TestObj2>();

            var obj1 = new TestObj {
                Text = "GLaDOS loves testing!"
            };
            var obj2 = new TestObj2 {
                Text = "Keep testing, just keep testing"
            };

            int numIn1 = db.Insert(obj1);

            Assert.AreEqual(1, numIn1);
            int numIn2 = db.Insert(obj2);

            Assert.AreEqual(1, numIn2);

            List <TestObj> result1 = db.Table <TestObj>().ToList();

            Assert.AreEqual(numIn1, result1.Count);
            Assert.AreEqual(obj1.Text, result1.First().Text);

            List <TestObj> result2 = db.Query <TestObj>("select * from TestObj2").ToList();

            Assert.AreEqual(numIn2, result2.Count);

            db.Close();
        }
コード例 #6
0
        public void TableQueryOnQueryableTable()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable <QueryableTable>();
                db.Insert(new QueryableTable {
                    Name = "sqlite"
                });
                db.Insert(new QueryableTable {
                    Name = "sqlevy"
                });
                db.Insert(new QueryableTable {
                    Name = "cars"
                });
                db.Insert(new QueryableTable {
                    Name = "we know sqlite is cool"
                });
                db.Insert(new QueryableTable {
                    Name = "we think sqlites"
                });

                var count = db.Table <QueryableTable>().Where(x => x.Name.Matches("sqlite")).Count();

                Assert.AreEqual(3, count);
            }
        }
コード例 #7
0
        public void BitwiseAndTest()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable <BitwiseTable>();

                db.Insert(new BitwiseTable {
                    Flags = 0
                });
                db.Insert(new BitwiseTable {
                    Flags = 1
                });
                db.Insert(new BitwiseTable {
                    Flags = 2
                });
                db.Insert(new BitwiseTable {
                    Flags = 2 | 1
                });

                var bit = db.Table <BitwiseTable>().Where(x => (x.Flags & 2) != 0).Select(x => x.Flags).ToArray();
                ArrayAssert.AreEqual(new[] { 2, 3 }, bit);

                bit = db.Table <BitwiseTable>().Where(x => (x.Flags & 1) != 0).Select(x => x.Flags).ToArray();
                ArrayAssert.AreEqual(new[] { 1, 3 }, bit);

                bit = db.Table <BitwiseTable>().Where(x => (x.Flags & 4) != 0).Select(x => x.Flags).ToArray();
                ArrayAssert.AreEqual(new int[] { }, bit);
            }
        }
コード例 #8
0
        public void OrderByCast()
        {
            var db = new OrmTestSession();

            db.CreateTable <CoolTable>();

            db.Insert(new CoolTable {
                Name = "A", Price = 20
            });
            db.Insert(new CoolTable {
                Name = "B", Price = 100
            });

            var nocast = (from p in db.Table <CoolTable>()
                          orderby p.Price descending
                          select p).ToList();

            Assert.AreEqual(2, nocast.Count);
            Assert.AreEqual("B", nocast[0].Name);

            var cast = (from p in db.Table <CoolTable>()
                        orderby(int) p.Price descending
                        select p).ToList();

            Assert.AreEqual(2, cast.Count);
            Assert.AreEqual("B", cast[0].Name);
        }
コード例 #9
0
        public void CreateThem()
        {
            var db = new OrmTestSession();

            db.CreateTable <Product>();
            db.CreateTable <OrderLine>();

            var foo = new Product {
                Name = "Foo", Price = 10.0m
            };
            var bar = new Product {
                Name = "Bar", Price = 0.10m
            };

            db.Insert(foo);
            db.Insert(bar);
            db.Insert(new OrderLine {
                ProductId = foo.Id, Quantity = 6, UnitPrice = 10.01m
            });
            db.Insert(new OrderLine {
                ProductId = foo.Id, Quantity = 3, UnitPrice = 0.02m
            });
            db.Insert(new OrderLine {
                ProductId = bar.Id, Quantity = 9, UnitPrice = 100.01m
            });

            OrderLine[] lines = foo.OrderLines;

            Assert.AreEqual(lines.Length, 2, "Has 2 order lines");
            Assert.AreEqual(foo.Connection, db, "foo.Connection was set");
            Assert.AreEqual(lines[0].Connection, db, "lines[0].Connection was set");
        }
コード例 #10
0
        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();

            db.CreateTable <Product>();

            // insert
            db.Insert(new Product {
                Name = "Hello", Price = 16,
            });
            db.Insert(new Product {
                Name = "Hello", Price = 16,
            });

            // confirm
            Assert.AreEqual(2, db.Table <Product>().Count());
            db.Get <Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable <Product>());

            // confirm
            Assert.AreEqual(0, db.Table <Product>().Count());

            // insert
            db.Insert(new Product {
                Name = "Hello", Price = 16,
            });

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table <Product>().Count());
            db.Get <Product>(3);
        }
コード例 #11
0
        public void WhereNull()
        {
            var db = new OrmTestSession();

            db.CreateTable <NullableIntClass>();

            var withNull = new NullableIntClass {
                NullableInt = null
            };
            var with0 = new NullableIntClass {
                NullableInt = 0
            };
            var with1 = new NullableIntClass {
                NullableInt = 1
            };
            var withMinus1 = new NullableIntClass {
                NullableInt = -1
            };

            db.Insert(withNull);
            db.Insert(with0);
            db.Insert(with1);
            db.Insert(withMinus1);

            NullableIntClass[] results = db.Table <NullableIntClass>().Where(x => x.NullableInt == null).OrderBy(x => x.Id).ToArray();

            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(withNull, results[0]);
        }
コード例 #12
0
        public void StringWhereNotNull()
        {
            var db = new OrmTestSession();

            db.CreateTable <StringClass>();

            var withNull = new StringClass {
                StringData = null
            };
            var withEmpty = new StringClass {
                StringData = ""
            };
            var withData = new StringClass {
                StringData = "data"
            };

            db.Insert(withNull);
            db.Insert(withEmpty);
            db.Insert(withData);

            StringClass[] results = db.Table <StringClass>().Where(x => x.StringData != null).OrderBy(x => x.Id).ToArray();
            Assert.AreEqual(2, results.Length);
            Assert.AreEqual(withEmpty, results[0]);
            Assert.AreEqual(withData, results[1]);
        }
コード例 #13
0
        public void TestElementAtOrDefault()
        {
            OrmTestSession db = CreateDb();

            db.Insert(new Product
            {
                Name  = "A",
                Price = 20,
            });

            db.Insert(new Product
            {
                Name  = "B",
                Price = 10,
            });

            Assert.AreEqual(2, db.Table <Product>().Count());

            var correct = db.Table <Product>().ElementAtOrDefault(1);

            Assert.AreEqual("B", correct.Name);

            var incorrect = db.Table <Product>().ElementAtOrDefault(2);

            Assert.IsNull(incorrect);
        }
コード例 #14
0
        // [Description("Create a table with a nullable int column then insert and select against it")]
        public void NullableFloat()
        {
            var db = new OrmTestSession();

            db.CreateTable <NullableFloatClass>();

            var withNull = new NullableFloatClass {
                NullableFloat = null
            };
            var with0 = new NullableFloatClass {
                NullableFloat = 0
            };
            var with1 = new NullableFloatClass {
                NullableFloat = 1
            };
            var withMinus1 = new NullableFloatClass {
                NullableFloat = -1
            };

            db.Insert(withNull);
            db.Insert(with0);
            db.Insert(with1);
            db.Insert(withMinus1);

            NullableFloatClass[] results = db.Table <NullableFloatClass>().OrderBy(x => x.Id).ToArray();

            Assert.AreEqual(4, results.Length);

            Assert.AreEqual(withNull, results[0]);
            Assert.AreEqual(with0, results[1]);
            Assert.AreEqual(with1, results[2]);
            Assert.AreEqual(withMinus1, results[3]);
        }
コード例 #15
0
        public void WhereGreaterThan()
        {
            OrmTestSession db = CreateDb();

            db.Insert(new Product
            {
                Name  = "A",
                Price = 20,
            });

            db.Insert(new Product
            {
                Name  = "B",
                Price = 10,
            });

            Assert.AreEqual(2, db.Table <Product>().Count());

            List <Product> r = (from p in db.Table <Product>()
                                where p.Price > 15
                                select p).ToList();

            Assert.AreEqual(1, r.Count);
            Assert.AreEqual("A", r[0].Name);
        }
コード例 #16
0
        public void FunctionParameter()
        {
            OrmTestSession db = CreateDb();

            db.Insert(new Product
            {
                Name  = "A",
                Price = 20,
            });

            db.Insert(new Product
            {
                Name  = "B",
                Price = 10,
            });

            Func <decimal, List <Product> > getProductsWithPriceAtLeast = val => (from p in db.Table <Product>()
                                                                                  where p.Price > val
                                                                                  select p).ToList();

            List <Product> r = getProductsWithPriceAtLeast(15);

            Assert.AreEqual(1, r.Count);
            Assert.AreEqual("A", r[0].Name);
        }
コード例 #17
0
        public void InsertUsingInterweavingSavePoints()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                using (var trans = db.BeginTransaction())
                {
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 1);

                    trans.CreateSavepoint("First");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 2);

                    trans.CreateSavepoint("Second");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 3);

                    trans.RollbackSavepoint("First");

                    trans.Commit();
                }

                Assert.AreEqual(db.Table <TestObj>().Count(), 1);
            }
        }
コード例 #18
0
        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            // insert
            db.Insert(new Product { Name = "Hello", Price = 16, });
            db.Insert(new Product { Name = "Hello", Price = 16, });

            // confirm
            Assert.AreEqual(2, db.Table<Product>().Count());
            db.Get<Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable<Product>());

            // confirm
            Assert.AreEqual(0, db.Table<Product>().Count());

            // insert
            db.Insert(new Product { Name = "Hello", Price = 16, });

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table<Product>().Count());
            db.Get<Product>(3);
        }
コード例 #19
0
        public void CreateIndexedTable()
        {
            var db = new OrmTestSession();

            db.CreateTable <IndexedTable>();
            db.Insert(new IndexedTable {
                Indexed = 1
            });
            ExceptionAssert.Throws <SqliteException>(
                () => db.Insert(new IndexedTable {
                Indexed = 1
            }));
        }
コード例 #20
0
        public void TestBoolean()
        {
            var db = new OrmTestSession();
            db.CreateTable<Vo>();

            for (int i = 0; i < 10; i++)
            {
                db.Insert(new Vo {Flag = (i%3 == 0), Text = String.Format("VO{0}", i)});
            }

            // count vo which flag is true            
            Assert.AreEqual(4, CountWithFlag(db, true));
            Assert.AreEqual(6, CountWithFlag(db, false));

            Debug.WriteLine("VO with true flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", true))
            {
                Debug.WriteLine(vo.ToString());
            }

            Debug.WriteLine("VO with false flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", false))
            {
                Debug.WriteLine(vo.ToString());
            }
        }
コード例 #21
0
        public void NestedTransactionsTest()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                using (var trans1 = db.BeginTransaction())
                {
                    trans1.CreateSavepoint("First");
                    db.Insert(obj);

                    using (var trans2 = db.BeginTransaction())
                    {
                        // rollback on the second trans affects the first as
                        // it is the same transaction
                        trans2.RollbackSavepoint("First");
                    }

                    Assert.AreEqual(db.Table <TestObj>().Count(), 0);
                }
            }
        }
コード例 #22
0
        public void InsertObjectWithValueInPrimaryKey()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj2>();

            var obj2 = new TestObj2 {
                Id = 5, Text = "Old"
            };

            int numIn1 = db.Insert(obj2);

            Assert.AreEqual(1, numIn1);

            var result = db.Table <TestObj2>().Single(i => i.Id == 5);

            Assert.AreEqual("Old", result.Text);

            result.Text = "New";
            var upd = db.Update(result);

            result = db.Table <TestObj2>().Single(i => i.Id == 5);
            Assert.AreEqual("New", result.Text);

            db.Close();
        }
コード例 #23
0
        public void CreateInsertDrop()
        {
            var db = new OrmTestSession();

            db.CreateTable<Product>();

            db.Insert(new Product
                          {
                              Name = "Hello",
                              Price = 16,
                          });

            int n = db.Table<Product>().Count();

            Assert.AreEqual(1, n);

            db.DropTable<Product>();

            try
            {
                // Should throw SqliteException
                db.Table<Product>().Count();

                Assert.Fail("Expeced 'table does not exist' error.");
            }
            catch (SqliteException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
コード例 #24
0
        public void CreateInsertDrop()
        {
            var db = new OrmTestSession();

            db.CreateTable <Product>();

            db.Insert(new Product
            {
                Name  = "Hello",
                Price = 16,
            });

            int n = db.Table <Product>().Count();

            Assert.AreEqual(1, n);

            db.DropTable <Product>();

            try
            {
                // Should throw SqliteException
                db.Table <Product>().Count();

                Assert.Fail("Expeced 'table does not exist' error.");
            }
            catch (SqliteException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
コード例 #25
0
        public void Collate()
        {
            var obj = new TestObj
            {
                CollateDefault = "Alpha ",
                CollateBinary  = "Alpha ",
                CollateRTrim   = "Alpha ",
                CollateNoCase  = "Alpha ",
            };

            var db = new OrmTestSession();

            db.CreateTable <TestObj>();
            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table <TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table <TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
コード例 #26
0
        // [Description("Create A large byte array and check it can be stored and retrieved correctly")]
        public void LargeByteArrayTest()
        {
            const int byteArraySize = 1024 * 1024;
            var       bytes         = new byte[byteArraySize];

            for (int i = 0; i < byteArraySize; i++)
            {
                bytes[i] = (byte)(i % 256);
            }

            var byteArray = new ByteArrayClass {
                Bytes = bytes
            };

            var database = new OrmTestSession();

            database.CreateTable <ByteArrayClass>();

            //Insert the ByteArrayClass
            database.Insert(byteArray);

            //Get it back out
            ByteArrayClass[] fetchedByteArrays = database.Table <ByteArrayClass>().ToArray();

            Assert.AreEqual(fetchedByteArrays.Length, 1);

            //Check they are the same
            byteArray.AssertEquals(fetchedByteArrays[0]);
        }
コード例 #27
0
        public void Collate()
        {
            var obj = new TestObj
                          {
                              CollateDefault = "Alpha ",
                              CollateBinary = "Alpha ",
                              CollateRTrim = "Alpha ",
                              CollateNoCase = "Alpha ",
                          };

            var db = new OrmTestSession();
            db.CreateTable<TestObj>();
            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
コード例 #28
0
        public void CanCompareAnyField()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObjString>();
            db.Insert(new TestObjString
            {
                Data = Convert.ToString(3),
                Date = new DateTime(2013, 1, 3)
            });

            var results = db.Table <TestObjString>().Where(o => o.Data.Equals("3"));

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual("3", results.FirstOrDefault().Data);

            results = db.Table <TestObjString>().Where(o => o.Id.Equals(1));
            Assert.AreEqual(1, results.Count());
            Assert.AreEqual("3", results.FirstOrDefault().Data);

            var date = new DateTime(2013, 1, 3);

            results = db.Table <TestObjString>().Where(o => o.Date.Equals(date));
            Assert.AreEqual(1, results.Count());
            Assert.AreEqual("3", results.FirstOrDefault().Data);
        }
コード例 #29
0
        public void TestBoolean()
        {
            var db = new OrmTestSession();

            db.CreateTable <Vo>();

            for (int i = 0; i < 10; i++)
            {
                db.Insert(new Vo {
                    Flag = (i % 3 == 0), Text = String.Format("VO{0}", i)
                });
            }

            // count vo which flag is true
            Assert.AreEqual(4, CountWithFlag(db, true));
            Assert.AreEqual(6, CountWithFlag(db, false));

            Debug.WriteLine("VO with true flag:");
            foreach (Vo vo in db.Query <Vo>("SELECT * FROM VO Where Flag = ?", true))
            {
                Debug.WriteLine(vo.ToString());
            }

            Debug.WriteLine("VO with false flag:");
            foreach (Vo vo in db.Query <Vo>("SELECT * FROM VO Where Flag = ?", false))
            {
                Debug.WriteLine(vo.ToString());
            }
        }
コード例 #30
0
        public void StringPrimaryKeys()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable <StringKeyObject>();

                // insert 2 items
                db.Insert(new StringKeyObject {
                    Key = "Name", Value = "Matthew"
                });
                db.Insert(new StringKeyObject {
                    Key = "Age", Value = "19"
                });

                // see if they saved
                Assert.AreEqual(2, db.Table <StringKeyObject>().Count());

                // get the age
                var fromDb = db.Table <StringKeyObject>().Where(x => x.Key == "Age").Single();

                // make sure they are correct
                Assert.AreEqual("Age", fromDb.Key);
                Assert.AreEqual("19", fromDb.Value);

                // try updating
                db.Update(new StringKeyObject {
                    Key = "Name", Value = "Matthew Leibowitz"
                });

                // make sure it wasn't an add
                Assert.AreEqual(2, db.Table <StringKeyObject>().Count());

                // get the name
                fromDb = db.Table <StringKeyObject>().Where(x => x.Key == "Name").Single();

                // make sure the name has changed
                Assert.AreEqual("Matthew Leibowitz", fromDb.Value);

                // try a delete
                db.Delete(new StringKeyObject {
                    Key = "Age"
                });

                // ensure it was really deleted
                Assert.AreEqual(1, db.Table <StringKeyObject>().Count());
            }
        }
コード例 #31
0
        public void EnumDataConverterTest()
        {
            var db = new OrmTestSession();

            db.CreateTable <EnumTestTable>();

            db.Insert(new EnumTestTable {
                EnumColumn = MyEnum.Second
            });
            db.Insert(new EnumTestTable {
                EnumColumn = null
            });

            var plain = db.Get <EnumTestTablePlain>(1);

            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get <EnumTestTablePlain>(2);
            Assert.IsNull(plain.EnumColumn);

            var rich = db.Get <EnumTestTable>(1);

            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get <EnumTestTable>(2);
            Assert.IsNull(rich.EnumColumn);

            db.Insert(new EnumTestTablePlain {
                EnumColumn = "2"
            });
            db.Insert(new EnumTestTablePlain {
                EnumColumn = null
            });

            plain = db.Get <EnumTestTablePlain>(3);
            Assert.AreEqual("2", plain.EnumColumn);

            plain = db.Get <EnumTestTablePlain>(4);
            Assert.IsNull(plain.EnumColumn);

            rich = db.Get <EnumTestTable>(3);
            Assert.AreEqual(MyEnum.Second, rich.EnumColumn);

            rich = db.Get <EnumTestTable>(4);
            Assert.IsNull(rich.EnumColumn);
        }
コード例 #32
0
 public void RunMergeUntilOptimalTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.RunMergeUntilOptimal<SimpleTable>();
     }
 }
コード例 #33
0
 public void MergeTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.Merge<SimpleTable>();
     }
 }
コード例 #34
0
 public void IntegrityCheckTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.IntegrityCheck<SimpleTable>();
     }
 }
コード例 #35
0
 public void CreateInstanceHookTestNonGeneric()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get(typeof(HookTestTable), 1);
     Assert.AreEqual(ReplacedText, ((HookTestTable)got).Text);
 }
コード例 #36
0
 public void CreateInstanceHookTest()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get<HookTestTable>(1);
     Assert.AreEqual(ReplacedText, got.Text);
 }
コード例 #37
0
        public void StringQueryOnQueryableTable()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable<QueryableTable>();
                db.Insert(new QueryableTable { Name = "sqlite" });
                db.Insert(new QueryableTable { Name = "sqlevy" });
                db.Insert(new QueryableTable { Name = "cars" });
                db.Insert(new QueryableTable { Name = "we know sqlite is cool" });
                db.Insert(new QueryableTable { Name = "we think sqlites" });

                var count = db.ExecuteScalar<int>(
                    "SELECT COUNT(*) FROM [QueryableTable] WHERE [Name] MATCH ?", 
                    "sqlite");

                Assert.AreEqual(3, count);
            }
        }
コード例 #38
0
        public void Insert()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            db.Insert(new Product { Name = TestString, });

            var p = db.Get<Product>(1);

            Assert.AreEqual(TestString, p.Name);
        }
コード例 #39
0
 public void IntegrityCheckTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable <SimpleTable>();
         db.Insert(new SimpleTable {
             Name = RandomString()
         });
         db.IntegrityCheck <SimpleTable>();
     }
 }
コード例 #40
0
 public void AutoMergeTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable <SimpleTable>();
         db.Insert(new SimpleTable {
             Name = RandomString()
         });
         db.AutoMerge <SimpleTable>();
     }
 }
コード例 #41
0
 public void RunMergeUntilOptimalTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable <SimpleTable>();
         db.Insert(new SimpleTable {
             Name = RandomString()
         });
         db.RunMergeUntilOptimal <SimpleTable>();
     }
 }
コード例 #42
0
        public void CreateThem()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();
            db.CreateTable<OrderLine>();

            var foo = new Product { Name = "Foo", Price = 10.0m };
            var bar = new Product { Name = "Bar", Price = 0.10m };
            db.Insert(foo);
            db.Insert(bar);
            db.Insert(new OrderLine { ProductId = foo.Id, Quantity = 6, UnitPrice = 10.01m });
            db.Insert(new OrderLine { ProductId = foo.Id, Quantity = 3, UnitPrice = 0.02m });
            db.Insert(new OrderLine { ProductId = bar.Id, Quantity = 9, UnitPrice = 100.01m });

            OrderLine[] lines = foo.OrderLines;

            Assert.AreEqual(lines.Length, 2, "Has 2 order lines");
            Assert.AreEqual(foo.Connection, db, "foo.Connection was set");
            Assert.AreEqual(lines[0].Connection, db, "lines[0].Connection was set");
        }
コード例 #43
0
        public void Query()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            db.Insert(new Product { Name = TestString, });

            var ps = (from p in db.Table<Product>() where p.Name == TestString select p).ToList();

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual(TestString, ps[0].Name);
        }
コード例 #44
0
        public void InterfaceTest()
        {
            var db = new OrmTestSession();

            db.CreateTable<Product>();

            var obj1 = new Product { Name = "Some Cool Name" };

            int numIn1 = db.Insert(obj1);
            Assert.AreEqual(1, numIn1);

            db.Close();
        }
コード例 #45
0
        public void StringContains()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var testObj = new TestObj { Name = "This is a Good name" };
            db.Insert(testObj);

            var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains("Good") select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
            var finder = "good";
            stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains(finder) select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
        }
コード例 #46
0
        public void StringStartsWith()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var testObj = new TestObj { Name = "This is a Good name" };
            db.Insert(testObj);

            var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith("This") select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
            var finder = "name";
            stringContainsTest = (from n in db.Table<TestObj>() where n.Name.StartsWith(finder) select n).SingleOrDefault();
            Assert.IsNull(stringContainsTest);
        }
コード例 #47
0
        public void ColumnsSaveLoadMaxCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
                           {
                               Id = 0,
                               Int32 = Int32.MaxValue,
                               String = "A unicode string \u2022 <- bullet point",
                               Byte = Byte.MaxValue,
                               UInt16 = UInt16.MaxValue,
                               SByte = SByte.MaxValue,
                               Int16 = Int16.MaxValue,
                               Boolean = true,
                               UInt32 = UInt32.MaxValue,
                               Int64 = Int64.MaxValue,
                               Single = Single.MaxValue,
                               Double = Double.MaxValue,
                               Decimal = 79228162514264300000000000000M,
                               Enum1 = EEnum.EnumVal1,
                               Enum2 = EEnum.EnumVal2,
                               Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                               Blob = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
                               Guid = Guid.NewGuid()
                           };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
コード例 #48
0
            public CreateTest(OrmTestSession db)
            {
                db.CreateTable<OrderLine>();

                var orderLine = db.GetMapping<OrderLine>();
                Assert.AreEqual(4, orderLine.Columns.Count, "OrderLine has 4 columns");

                var l = new OrderLine { Status = OrderLineStatus.Shipped };
                db.Insert(l);

                OrderLine lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
                Assert.AreEqual(lo.Id, l.Id);

                Id = lo.Id;
            }
コード例 #49
0
        public void CreateInsertDrop()
        {
            var db = new OrmTestSession();

            db.CreateTable<Product>();

            db.Insert(new Product { Name = "Hello", Price = 16, });

            int n = db.Table<Product>().Count();

            Assert.AreEqual(1, n);

            db.DropTable<Product>();

            ExceptionAssert.Throws<SqliteException>(() => db.Table<Product>().Count());
        }
コード例 #50
0
        public void SqlQuery()
        {
            var expected = "абвг";

            var db = new OrmTestSession();
            db.CreateTable<Product>();

            var product = new Product { Name = TestString };
            db.Insert(product);

            db.Execute("UPDATE Product SET Name = '" + expected + "' WHERE Id = " + product.Id);

            var ps = (from p in db.Table<Product>()
                      where p.Name == expected 
                      select p).ToList();

            Assert.AreEqual(1, ps.Count);
            Assert.AreEqual(expected, ps[0].Name);
        }
コード例 #51
0
        public void InsertUsingNestedSystemTransactions()
        {
            var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted };

            using (var db = new OrmTestSession())
            {
                using (var trans = new TransactionScope(TransactionScopeOption.Required, options))
                {
                    db.CreateTable<TestObj>();
                    db.Insert(new TestObj { Text = "My Text" });

                    using (var trans2 = new TransactionScope(TransactionScopeOption.Required, options))
                    {
                        db.Insert(new TestObj { Text = "My Text" });
                        trans2.Complete();
                    }

                    trans.Complete();
                }

                Assert.AreEqual(2, db.Table<TestObj>().Count());
            }
        }
コード例 #52
0
        // [Description("Create objects with various byte arrays and check they can be stored and retrieved correctly")]
        public void ByteArrays()
        {
            //Byte Arrays for comparisson
            var byteArrays = new[]
                                 {
                                     new ByteArrayClass {Bytes = new byte[] {1, 2, 3, 4, 250, 252, 253, 254, 255}}, //Range check
                                     new ByteArrayClass {Bytes = new byte[] {0}}, //null bytes need to be handled correctly
                                     new ByteArrayClass {Bytes = new byte[] {0, 0}},
                                     new ByteArrayClass {Bytes = new byte[] {0, 1, 0}},
                                     new ByteArrayClass {Bytes = new byte[] {1, 0, 1}},
                                     new ByteArrayClass {Bytes = new byte[] {}}, //Empty byte array should stay empty (and not become null)
                                     new ByteArrayClass {Bytes = null} //Null should be supported
                                 };

            var database = new OrmTestSession();
            database.CreateTable<ByteArrayClass>();

            //Insert all of the ByteArrayClass
            foreach (ByteArrayClass b in byteArrays)
                database.Insert(b);

            //Get them back out
            ByteArrayClass[] fetchedByteArrays = database.Table<ByteArrayClass>().OrderBy(x => x.Id).ToArray();

            Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
            //Check they are the same
            for (int i = 0; i < byteArrays.Length; i++)
            {
                var byteArrayClass = byteArrays[i];
                var other = fetchedByteArrays[i];

                var actual = byteArrayClass.Bytes;
                var expected = other.Bytes;

                byteArrayClass.AssertEquals(other);
            }
        }
コード例 #53
0
        // [Description("Create objects with various byte arrays and check they can be stored and retrieved correctly")]
        public void ByteArraysSavedCorrectlyTest()
        {
            //Byte Arrays for comparisson
            var byteArrays = new[]
                {
                    new ByteArrayClass { Bytes = new byte[] { 1, 2, 3, 4, 250, 252, 253, 254, 255 } }, // Range check
                    new ByteArrayClass { Bytes = new byte[] { 0, 0 } },
                    new ByteArrayClass { Bytes = new byte[] { 0, 1, 0 } },
                    new ByteArrayClass { Bytes = new byte[] { 1, 0, 1 } },
                };

            var database = new OrmTestSession();
            database.CreateTable<ByteArrayClass>();

            //Insert all of the ByteArrayClass
            foreach (ByteArrayClass b in byteArrays)
            {
                database.Insert(b);
            }

            //Get them back out
            ByteArrayClass[] fetchedByteArrays = database.Table<ByteArrayClass>().OrderBy(x => x.Id).ToArray();

            Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
            //Check they are the same
            for (int i = 0; i < byteArrays.Length; i++)
            {
                var byteArrayClass = byteArrays[i];
                var other = fetchedByteArrays[i];

                var actual = byteArrayClass.Bytes;
                var expected = other.Bytes;

                byteArrayClass.AssertEquals(other);
            }
        }
コード例 #54
0
        public void CreateTableWithoutIndexesTest()
        {
            var db = new OrmTestSession();
            
            // the table
            db.CreateTable<IndexedTable>(false);

            // the indexes
            var map = db.GetMapping<IndexedTable>();
            foreach (var index in map.Indexes)
            {
                db.Execute(index.GetCreateSql(map.TableName));
            }

            // the test
            db.Insert(new IndexedTable { Indexed = 1 });
            ExceptionAssert.Throws<SqliteException>(
                () => db.Insert(new IndexedTable { Indexed = 1 }));
        }
コード例 #55
0
        public void CreateEnumTable()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable<EnumTable>();

                var sql = new TableMapping(typeof(EnumTable)).GetCreateSql();
                var correct = @"CREATE TABLE [EnumTable] (
[Type] varchar(1) NOT NULL,
[Age] integer NOT NULL,
[Kind] text NOT NULL
);";

                Assert.AreEqual(correct, sql);

                db.Insert(
                    new EnumTable
                        {
                            Type = EnumTable.PersonType.Child,
                            Age = EnumTable.PersonAge.ChildAge,
                            Kind = EnumTable.PersonKind.Junior
                        });
            }
        }
コード例 #56
0
 public void CreateIndexedTable()
 {
     var db = new OrmTestSession();
     db.CreateTable<IndexedTable>();
     db.Insert(new IndexedTable { Indexed = 1 });
     ExceptionAssert.Throws<SqliteException>(
         () => db.Insert(new IndexedTable { Indexed = 1 }));
 }
コード例 #57
0
        public void ColumnsSaveLoadZerosCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0,
                UInt16 = 0,
                SByte = 0,
                Int16 = 0,
                Boolean = false,
                UInt32 = 0,
                Int64 = 0,
                Single = Single.Epsilon,
                Double = Double.Epsilon,
                Decimal = Decimal.Zero,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("0001-01-01 00:00:00.000"),
                Blob = new byte[] { 0 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
コード例 #58
0
        public void ColumnsSaveLoadRandomValuesCorrectly()
        {
            var db = new OrmTestSession();
            db.CreateTable<Test>();

            var test = new Test
            {
                Id = 0,
                Int32 = 0x1337beef,
                String = "A unicode string \u2022 <- bullet point",
                Byte = 0xEA,
                UInt16 = 65535,
                SByte = -128,
                Int16 = -32768,
                Boolean = false,
                UInt32 = 0xdeadbeef,
                Int64 = 0x123456789abcdef,
                Single = 6.283185f,
                Double = 6.283185307179586476925286766559,
                Decimal = (decimal)6.283185307179586476925286766559,
                Enum1 = EEnum.EnumVal1,
                Enum2 = EEnum.EnumVal2,
                Timestamp = DateTime.Parse("2012-04-05 15:08:24.723"),
                Blob = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                Guid = Guid.NewGuid()
            };

            db.Insert(test);
            var res = db.Get<Test>(test.Id);

            Assert.AreEqual(test.Id, res.Id);
            Assert.AreEqual(test.Int32, res.Int32);
            Assert.AreEqual(test.String, res.String);
            Assert.AreEqual(test.Byte, res.Byte);
            Assert.AreEqual(test.UInt16, res.UInt16);
            Assert.AreEqual(test.SByte, res.SByte);
            Assert.AreEqual(test.Int16, res.Int16);
            Assert.AreEqual(test.Boolean, res.Boolean);
            Assert.AreEqual(test.UInt32, res.UInt32);
            Assert.AreEqual(test.Int64, res.Int64);
            Assert.AreEqual(test.Single, res.Single);
            Assert.AreEqual(test.Double, res.Double);
            Assert.AreEqual(test.Decimal, res.Decimal);
            Assert.AreEqual(test.Enum1, res.Enum1);
            Assert.AreEqual(test.Enum2, res.Enum2);
            Assert.AreEqual(test.Timestamp, res.Timestamp);
            ArrayAssert.AreEqual(test.Blob, res.Blob);
            Assert.AreEqual(test.Guid, res.Guid);
        }
コード例 #59
0
        public void InsertUsingSavePoints()
        {
            var obj = new TestObj { Text = "Matthew" };

            using (var db = new OrmTestSession())
            {
                db.CreateTable<TestObj>();

                using (var trans = db.BeginTransaction())
                {
                    db.Insert(obj);
                    Assert.AreEqual(db.Table<TestObj>().Count(), 1);

                    trans.CreateSavepoint("First");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table<TestObj>().Count(), 2);

                    trans.RollbackSavepoint("First");

                    trans.Commit();
                }

                Assert.AreEqual(db.Table<TestObj>().Count(), 1);
            }
        }
コード例 #60
0
        public void MultiplePkOperations()
		{
			var db = new OrmTestSession();
			db.CreateTable<TestObj>();
			
			// insert
			const int n = 10 , m= 5;
			var objs = new TestObj[n * m];
			for (int j = 0; j != n; ++j)
			{
				for (int i = 0; i != m; ++i)
				{
					objs[j * m + i] = new TestObj {Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"};
				}
			}

			int numIn = db.InsertAll(objs);

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

			var obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual(5, obj.Id);
			Assert.AreEqual(3, obj.SubId);
			Assert.AreEqual("I am (5,3)", obj.Text);
			
			try
			{
				db.Insert(obj);
			}
			catch (SqliteException ex)
			{
                Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
			}

			// update
			obj.Text = "I've been changed";
			db.Update(obj);
			db.Update<TestObj>("Text", "I've been changed also", 8, 2);

			obj = db.Get<TestObj>(5, 3);
			Assert.AreEqual("I've been changed", obj.Text);

			obj = db.Get<TestObj>(8, 2);
			Assert.AreEqual("I've been changed also", obj.Text);

			db.UpdateAll<TestObj>("Text", "All changed");
			IEnumerable<TestObj> q1 = from o in db.Table<TestObj>() select o;
			foreach (TestObj o in q1)
				Assert.AreEqual("All changed", o.Text);

			TestObj[] q2 = (from o in db.Table<TestObj>() where o.SubId == 3 select o).ToArray();
			Assert.AreEqual(10, q2.Length);
			for (int i = 0; i != 10; ++i)
			{
				Assert.AreEqual(i, q2[i].Id);
			}

            object numCount = db.Table<TestObj>().Count();
			Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");

			// delete
			obj = db.Get<TestObj>(8, 2);
			db.Delete(obj);
			
			try
			{
				var item = db.Get<TestObj>(8, 2);

				Assert.Fail();
			}
			catch (InvalidOperationException)
			{
			}
			catch (Exception ex)
			{
				Assert.Fail(ex.Message);
			}

            db.Execute("delete from TestObj where SubId=2");
            numCount = db.ExecuteScalar<int>("select count(*) from TestObj");
			Assert.AreEqual(numCount, objs.Length - 10);
			foreach (TestObj o in (from o in db.Table<TestObj>() select o))
				Assert.AreNotEqual(2, o.SubId);
		}