示例#1
0
        public void StoreToGoodTable()
        {
            _db.Exec("create table kind1 (id integer primary key, p1, p2)");

            var id = _storage.Store("kind1", SharedChecks.MakeRow(
                                        "p1", 123,
                                        "p2", "hello"
                                        ));

            var row = _db.Row(true, "select * from kind1");

            Assert.Equal(123L, row["p1"]);
            Assert.Equal("hello", row["p2"]);
            Assert.Equal(id, row["id"]);

            Assert.Equal(id, _storage.Store("kind1", SharedChecks.MakeRow(
                                                "id", id,
                                                "p1", -1,
                                                "p2", "see you"
                                                )));

            row = _db.Row(true, "select * from kind1");
            Assert.Equal(-1L, row["p1"]);
            Assert.Equal("see you", row["p2"]);
        }
示例#2
0
        public void ChangeSchemaOnStore()
        {
            _db.Exec("create table kind1 (id integer primary key)");
            _storage.EnterFluidMode();

            _storage.Store("kind1", SharedChecks.MakeRow("x", 1));

            var schema = _storage.GetSchema();

            Assert.Equal(SQLiteDetails.RANK_ANY, schema["kind1"]["x"]);

            _storage.Store("kind1", SharedChecks.MakeRow(
                               "x", "hello",
                               "y", 3.14,
                               "z", null
                               ));

            schema = _storage.GetSchema();
            Assert.Equal(SQLiteDetails.RANK_ANY, schema["kind1"]["x"]);
            Assert.Equal(SQLiteDetails.RANK_ANY, schema["kind1"]["y"]);
            Assert.DoesNotContain("z", schema["kind1"].Keys);

            var rows = _db.Rows(true, "select * from kind1 order by id");

            Assert.Equal(1L, rows[0]["x"]);
            Assert.Null(rows[0]["y"]);

            Assert.Equal("hello", rows[1]["x"]);
            Assert.Equal(3.14, rows[1]["y"]);
        }
示例#3
0
        public void Booleans()
        {
            _storage.EnterFluidMode();

            var trueKeys = new[]
            {
                _storage.Store("foo", SharedChecks.MakeRow("x", true)),
                _storage.Store("foo", SharedChecks.MakeRow("x", 1)),
                _storage.Store("foo", SharedChecks.MakeRow("x", "1"))
            };

            var falseKeys = new[]
            {
                _storage.Store("foo", SharedChecks.MakeRow("x", false)),
                _storage.Store("foo", SharedChecks.MakeRow("x", 0)),
                _storage.Store("foo", SharedChecks.MakeRow("x", "0"))
            };

            var nullKeys = new[]
            {
                _storage.Store("foo", SharedChecks.MakeRow("x", null)),
                _storage.Store("foo", SharedChecks.MakeRow("x", ""))
            };

            AssertExtensions.Equivalent(trueKeys, _db.Col <object>(true, "select id from foo where x"));
            AssertExtensions.Equivalent(falseKeys, _db.Col <object>(true, "select id from foo where not x"));
            AssertExtensions.Equivalent(nullKeys, _db.Col <object>(true, "select id from foo where x is null"));
        }
示例#4
0
        public void NotIsNewBean()
        {
            _storage.EnterFluidMode();

            var key = _storage.Store("foo", SharedChecks.MakeRow("a", 1));
            var foo = _api.Load("foo", key);

            Assert.False(_storage.IsNew(foo));
        }
        public void UTF8_mb4()
        {
            const string pile = "\U0001f4a9";

            _storage.EnterFluidMode();
            var id = _storage.Store("foo", SharedChecks.MakeRow("p", pile));

            Assert.Equal(pile, _storage.Load("foo", id)["p"]);
        }
示例#6
0
        public void InsertUpdateWithoutValues()
        {
            _storage.EnterFluidMode();

            var id = _storage.Store("kind1", SharedChecks.MakeRow());

            Assert.Equal(1, _db.Cell <int>(true, "select count(*) from kind1"));

            Assert.Null(Record.Exception(() => { _storage.Store("kind1", SharedChecks.MakeRow("id", id)); }));
        }
示例#7
0
        public void IsNewBean()
        {
            _storage.EnterFluidMode();

            _storage.Store("foo", SharedChecks.MakeRow("a", 1));

            var foo = _api.Dispense("foo");

            foo["a"] = 2;

            Assert.True(_storage.IsNew(foo));
        }
示例#8
0
        public void StoreWithKeyMissingFromDb()
        {
            _storage.EnterFluidMode();

            var error = Record.Exception(() =>
            {
                _storage.Store("foo", SharedChecks.MakeRow(
                                   "id", 123,
                                   "a", 1
                                   ));
            });

            Assert.Equal("Row not found", error.Message);
        }
示例#9
0
        public void Trash()
        {
            var emptiness = SharedChecks.MakeRow();

            _storage.EnterFluidMode();

            var ids = new[]
            {
                _storage.Store("kind1", emptiness),
                _storage.Store("kind1", emptiness)
            };

            _storage.Trash("kind1", ids[0]);
            Assert.Equal(1, _db.Cell <int>(true, "select count(*) from kind1"));
        }
        public void CustomRank_ExistingColumn()
        {
            _db.Exec("create table foo(id int, p geometry)");

            _db.QueryExecuting += cmd => {
                foreach (MySqlParameter p in cmd.Parameters)
                {
                    if (p.Value is MySqlGeometry)
                    {
                        p.MySqlDbType = MySqlDbType.Geometry;
                    }
                }
            };

            _storage.Store("foo", SharedChecks.MakeRow("p", new MySqlGeometry(54.2, 37.61667)));

            // http://stackoverflow.com/q/30584522
            var blob = _db.Cell <byte[]>(false, "select p from foo");

            Assert.Equal(54.2, new MySqlGeometry(MySqlDbType.Geometry, blob).XCoordinate);
        }
示例#11
0
        public void StoreToMissingTable()
        {
            _storage.EnterFluidMode();
            _storage.Store("kind1", SharedChecks.MakeRow(
                               "p1", 123,
                               "p2", 3.14,
                               "p3", "hello",
                               "p4", null
                               ));

            var row = _db.Row(true, "select * from kind1");

            Assert.Equal(123L, row["p1"]);
            Assert.Equal(3.14, row["p2"]);
            Assert.Equal("hello", row["p3"]);
            Assert.DoesNotContain("p4", row.Keys);

            var table = _storage.GetSchema()["kind1"];

            Assert.Equal(SQLiteDetails.RANK_ANY, table["p1"]);
            Assert.Equal(SQLiteDetails.RANK_ANY, table["p2"]);
            Assert.Equal(SQLiteDetails.RANK_ANY, table["p3"]);
            Assert.DoesNotContain("p4", table.Keys);
        }
示例#12
0
 public void CustomRank_ExistingColumn()
 {
     _db.Exec("create table foo(id int, p smallmoney)");
     _storage.Store("foo", SharedChecks.MakeRow("p", new SqlMoney(9.9)));
     Assert.Equal(9.900M, _db.Cell <object>(false, "select p from foo"));
 }
示例#13
0
 public void ChangeSchemaWhenFrozen()
 {
     Assert.Throws(SQLitePortability.ExceptionType,
                   () => { _storage.Store("unlucky", SharedChecks.MakeRow("a", 1)); });
 }
示例#14
0
 public void CustomRank_ExistingColumn()
 {
     _db.Exec("create table foo(id int, p point)");
     _storage.Store("foo", SharedChecks.MakeRow("p", new NpgsqlPoint(54.2, 37.61667)));
     Assert.Equal(54.2, _db.Cell <NpgsqlPoint>(false, "select p from foo").X);
 }