コード例 #1
0
ファイル: MappingTest.cs プロジェクト: sp958857/SQLite4Unity
        public void OnlyKey()
        {
            var db = new TestDb();

            db.CreateTable <OnlyKeyModel> ();

            db.InsertOrReplace(new OnlyKeyModel {
                MyModelId = "Foo"
            });
            var foo = db.Get <OnlyKeyModel> ("Foo");

            Assert.AreEqual(foo.MyModelId, "Foo");

            db.Insert(new OnlyKeyModel {
                MyModelId = "Bar"
            });
            var bar = db.Get <OnlyKeyModel> ("Bar");

            Assert.AreEqual(bar.MyModelId, "Bar");

            db.Update(new OnlyKeyModel {
                MyModelId = "Foo"
            });
            var foo2 = db.Get <OnlyKeyModel> ("Foo");

            Assert.AreEqual(foo2.MyModelId, "Foo");
        }
コード例 #2
0
ファイル: InsertTest.cs プロジェクト: sp958857/SQLite4Unity
        public void InsertOrReplace()
        {
            _db.Trace = true;
            _db.InsertAll(from i in Enumerable.Range(1, 20) select new TestObj {
                Text = "#" + i
            });

            Assert.AreEqual(20, _db.Table <TestObj> ().Count());

            var t = new TestObj {
                Id = 5, Text = "Foo",
            };

            _db.InsertOrReplace(t);

            var r = (from x in _db.Table <TestObj> () orderby x.Id select x).ToList();

            Assert.AreEqual(20, r.Count);
            Assert.AreEqual("Foo", r[4].Text);
        }
コード例 #3
0
        public void ExecuteNonQueryWithNullThrowsException()
        {
            using (TestDb db = new TestDb()) {
                db.CreateTable <NotNullNoPK> ();

                try {
                    NotNullNoPK obj = new NotNullNoPK()
                    {
                        AnotherRequiredStringProp = "Another required prop",
                        RequiredIntProp           = 123,
                        RequiredStringProp        = "Required string prop"
                    };
                    db.Insert(obj);

                    NotNullNoPK obj2 = new NotNullNoPK()
                    {
                        objectId        = 1,
                        OptionalIntProp = 123,
                    };
                    db.InsertOrReplace(obj2);
                }
                catch (NotNullConstraintViolationException) {
                    return;
                }
                catch (SQLiteException ex) {
                    if (SQLite3.LibVersionNumber() < 3007017 && ex.Result == SQLite3.Result.Constraint)
                    {
                        Inconclusive();
                        return;
                    }
                }
                catch (Exception ex) {
                    Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. An exception of type {0} was thrown instead.", ex.GetType().Name);
                }
            }
            Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
        }