public void CreateTable()
        {
            _storage.EnterFluidMode();

            var data = new Dictionary <string, object> {
                { "p1", null },
                { "p2", 1 },
                { "p3", 1000 },
                { "p4", Int64.MaxValue },
                { "p5", 3.14 },
                { "p6", "abc" },
                { "p7", "".PadRight(37, 'a') },
                { "p8", "".PadRight(192, 'a') },
                { "p9", DateTime.Now },
                { "p10", new byte[0] }
            };

            _storage.Store("foo", data);

            var cols = _storage.GetSchema()["foo"];

            Assert.DoesNotContain("p1", cols.Keys);
            Assert.Equal(MariaDbDetails.RANK_INT8, cols["p2"]);
            Assert.Equal(MariaDbDetails.RANK_INT32, cols["p3"]);
            Assert.Equal(MariaDbDetails.RANK_INT64, cols["p4"]);
            Assert.Equal(MariaDbDetails.RANK_DOUBLE, cols["p5"]);
            Assert.Equal(MariaDbDetails.RANK_TEXT_36, cols["p6"]);
            Assert.Equal(MariaDbDetails.RANK_TEXT_191, cols["p7"]);
            Assert.Equal(MariaDbDetails.RANK_TEXT_MAX, cols["p8"]);
            Assert.Equal(MariaDbDetails.RANK_STATIC_DATETIME, cols["p9"]);
            Assert.Equal(MariaDbDetails.RANK_STATIC_BLOB, cols["p10"]);
        }
Exemple #2
0
        public void CreateTable()
        {
            _storage.EnterFluidMode();

            var data = new Dictionary <string, object> {
                { "p1", null },
                { "p2", 1 },
                { "p3", -1 },
                { "p4", Int64.MaxValue },
                { "p5", 3.14 },
                { "p6", "abcdfgh" },
                { "p7_16", "".PadRight(9, 'a') },
                { "p7_32", "".PadRight(17, 'a') },
                { "p7_64", "".PadRight(33, 'a') },
                { "p7_128", "".PadRight(65, 'a') },
                { "p7_256", "".PadRight(129, 'a') },
                { "p7_512", "".PadRight(257, 'a') },
                { "p7_4k", "".PadRight(513, 'a') },
                { "p8", "".PadRight(4001, 'a') },
                { "p9", DateTime.Now },
                { "p10", DateTimeOffset.Now },
                { "p11", Guid.NewGuid() },
                { "p12", new byte[0] }
            };

            _storage.Store("foo", data);

            var cols = _storage.GetSchema()["foo"];

            Assert.DoesNotContain("p1", cols.Keys);
            Assert.Equal(MsSqlDetails.RANK_BYTE, cols["p2"]);
            Assert.Equal(MsSqlDetails.RANK_INT32, cols["p3"]);
            Assert.Equal(MsSqlDetails.RANK_INT64, cols["p4"]);
            Assert.Equal(MsSqlDetails.RANK_DOUBLE, cols["p5"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_8, cols["p6"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_16, cols["p7_16"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_32, cols["p7_32"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_64, cols["p7_64"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_128, cols["p7_128"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_256, cols["p7_256"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_512, cols["p7_512"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_4000, cols["p7_4k"]);
            Assert.Equal(MsSqlDetails.RANK_TEXT_MAX, cols["p8"]);
            Assert.Equal(MsSqlDetails.RANK_STATIC_DATETIME, cols["p9"]);
            Assert.Equal(MsSqlDetails.RANK_STATIC_DATETIME_OFFSET, cols["p10"]);
            Assert.Equal(MsSqlDetails.RANK_STATIC_GUID, cols["p11"]);
            Assert.Equal(MsSqlDetails.RANK_STATIC_BLOB, cols["p12"]);
        }
        public void ImplicitTransactionsOnStoreAndTrash()
        {
            using (var conn = SQLitePortability.CreateConnection()) {
                conn.Open();

                IDatabaseDetails details = new SQLiteDetails();
                IDatabaseAccess  db      = new DatabaseAccess(conn, details);
                IKeyAccess       keys    = new KeyUtil();
                DatabaseStorage  storage = new DatabaseStorage(details, db, keys);
                IBeanFactory     factory = new BeanFactory();
                IBeanCrud        crud    = new BeanCrud(storage, db, keys, factory);

                storage.EnterFluidMode();

                var bean = crud.Dispense <ThrowingBean>();
                bean["foo"] = "ok";
                var id = crud.Store(bean);

                bean.Throw  = true;
                bean["foo"] = "fail";

                try { crud.Store(bean); } catch { }
                Assert.Equal("ok", db.Cell <string>(true, "select foo from test where id = {0}", id));

                try { crud.Trash(bean); } catch { }
                Assert.True(db.Cell <int>(true, "select count(*) from test") > 0);
            }
        }
        public void ImplicitTransactionsOnStoreAndTrash()
        {
            using(var conn = SQLitePortability.CreateConnection()) {
                conn.Open();

                IDatabaseDetails details = new SQLiteDetails();
                IDatabaseAccess db = new DatabaseAccess(conn, details);
                IKeyAccess keys = new KeyUtil();
                DatabaseStorage storage = new DatabaseStorage(details, db, keys);
                IBeanCrud crud = new BeanCrud(storage, db, keys);

                storage.EnterFluidMode();

                var bean = crud.Dispense<ThrowingBean>();
                bean["foo"] = "ok";
                var id = crud.Store(bean);

                bean.Throw = true;
                bean["foo"] = "fail";

                try { crud.Store(bean); } catch { }
                Assert.Equal("ok", db.Cell<string>(true, "select foo from test where id = {0}", id));

                try { crud.Trash(bean); } catch { }
                Assert.True(db.Cell<int>(true, "select count(*) from test") > 0);
            }
        }
Exemple #5
0
        public static void CheckLongToDouble(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var bigLong = Int64.MinValue + 12345;
            var longID  = storage.Store("foo", MakeRow("p", bigLong));

            storage.Store("foo", MakeRow("p", Math.PI));
            Assert.Equal(bigLong, db.Cell <long>(false, "select p from foo where id = {0}", longID));
        }
Exemple #6
0
        public static void CheckStoringNull(DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var row = MakeRow("p", 1);
            var id  = storage.Store("foo", row);

            row      = storage.Load("foo", id);
            row["p"] = null;
            storage.Store("foo", row);

            row = storage.Load("foo", id);
            Assert.Null(row["p"]);
        }
Exemple #7
0
        public void CreateTable()
        {
            _storage.EnterFluidMode();

            var data = new Dictionary <string, object> {
                { "p1", null },
                { "p2", true },
                { "p3", 1 },
                { "p4", Int64.MaxValue },
                { "p5", 3.14 },
                { "p6", Decimal.MaxValue },
                { "p7", UInt64.MaxValue },
                { "p8", "abc" },
                { "p9", DateTime.Now },
                { "p10", DateTimeOffset.Now },
                { "p11", Guid.NewGuid() },
                { "p12", new byte[0] }
            };

            _storage.Store("foo", data);

            var cols = _storage.GetSchema()["foo"];

            Assert.DoesNotContain("p1", cols.Keys);
            Assert.Equal(PgSqlDetails.RANK_BOOLEAN, cols["p2"]);
            Assert.Equal(PgSqlDetails.RANK_INT32, cols["p3"]);
            Assert.Equal(PgSqlDetails.RANK_INT64, cols["p4"]);
            Assert.Equal(PgSqlDetails.RANK_DOUBLE, cols["p5"]);
            Assert.Equal(PgSqlDetails.RANK_NUMERIC, cols["p6"]);
            Assert.Equal(PgSqlDetails.RANK_NUMERIC, cols["p7"]);
            Assert.Equal(PgSqlDetails.RANK_TEXT, cols["p8"]);
            Assert.Equal(PgSqlDetails.RANK_STATIC_DATETIME, cols["p9"]);
            Assert.Equal(PgSqlDetails.RANK_STATIC_DATETIME_OFFSET, cols["p10"]);
            Assert.Equal(PgSqlDetails.RANK_STATIC_GUID, cols["p11"]);
            Assert.Equal(PgSqlDetails.RANK_STATIC_BLOB, cols["p12"]);
        }
Exemple #8
0
        public static void CheckCustomRank_MissingColumn(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var row = MakeRow("a", new object());

            // Try create table
            AssertCannotAddColumn(Record.Exception(delegate() {
                storage.Store("foo1", row);
            }));

            storage.Store("foo2", MakeRow("b", 1));

            // Try add column
            AssertCannotAddColumn(Record.Exception(delegate() {
                storage.Store("foo2", row);
            }));
        }
Exemple #9
0
        public static void CheckCustomRank_MissingColumn(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var row = MakeRow("a", new object());

            // Try create table
            AssertCannotAddColumn(Record.Exception(delegate() {
                storage.Store("foo1", row);
            }));

            storage.Store("foo2", MakeRow("b", 1));

            // Try add column
            AssertCannotAddColumn(Record.Exception(delegate() {
                storage.Store("foo2", row);
            }));
        }
Exemple #10
0
        public static void CheckDateTimeQueries(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var dateTime = SAMPLE_DATETIME;
            var date = SAMPLE_DATETIME.Date;

            storage.Store("foo", MakeRow("d", date));
            storage.Store("foo", MakeRow("d", dateTime));
            Assert.Equal(2, db.Cell<int>(false, "select count(*) from foo where d = {0} or d = {1}", date, dateTime));

            db.Exec("delete from foo");

            for(var i = -2; i <= 2; i++)
                storage.Store("foo", MakeRow("d", date.AddDays(i)));
            Assert.Equal(3, db.Cell<int>(false, "select count(*) from foo where d between {0} and {1}", date.AddDays(-1), date.AddDays(1)));

            Assert.Equal(date, db.Cell<DateTime>(false, "select d from foo where d = {0}", date));
        }
Exemple #11
0
        public static void CheckCompoundKey(DatabaseStorage storage, KeyUtil keys)
        {
            storage.EnterFluidMode();

            keys.RegisterKey("foo", new[] { "k1", "k2" }, null);

            var row = MakeRow(
                "k1", "text",
                "k2", Guid.NewGuid(),
                "v", "hello"
            );

            var id = storage.Store("foo", row) as CompoundKey;
            Assert.Equal(row["k1"], id["k1"]);
            Assert.Equal(row["k2"], id["k2"]);

            row = storage.Load("foo", id);
            Assert.Equal("hello", row["v"]);
        }
Exemple #12
0
        public static void CheckCompoundKey(DatabaseStorage storage, KeyUtil keys)
        {
            storage.EnterFluidMode();

            keys.RegisterKey("foo", new[] { "k1", "k2" }, null);

            var row = MakeRow(
                "k1", "text",
                "k2", Guid.NewGuid(),
                "v", "hello"
                );

            var id = storage.Store("foo", row) as CompoundKey;

            Assert.Equal(row["k1"], id["k1"]);
            Assert.Equal(row["k2"], id["k2"]);

            row = storage.Load("foo", id);
            Assert.Equal("hello", row["v"]);
        }
Exemple #13
0
        public static void CheckDateTimeQueries(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var dateTime = SAMPLE_DATETIME;
            var date     = SAMPLE_DATETIME.Date;

            storage.Store("foo", MakeRow("d", date));
            storage.Store("foo", MakeRow("d", dateTime));
            Assert.Equal(2, db.Cell <int>(false, "select count(*) from foo where d = {0} or d = {1}", date, dateTime));

            db.Exec("delete from foo");

            for (var i = -2; i <= 2; i++)
            {
                storage.Store("foo", MakeRow("d", date.AddDays(i)));
            }
            Assert.Equal(3, db.Cell <int>(false, "select count(*) from foo where d between {0} and {1}", date.AddDays(-1), date.AddDays(1)));

            Assert.Equal(date, db.Cell <DateTime>(false, "select d from foo where d = {0}", date));
        }
Exemple #14
0
 public static void CheckGuidQuery(IDatabaseAccess db, DatabaseStorage storage)
 {
     storage.EnterFluidMode();
     storage.Store("foo", MakeRow("g", SAMPLE_GUID));
     Assert.Equal(SAMPLE_GUID, db.Cell <Guid>(false, "select g from foo where g = {0}", SAMPLE_GUID));
 }
        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);
        }
Exemple #16
0
        public static void CheckLongToDouble(IDatabaseAccess db, DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var bigLong = Int64.MinValue + 12345;
            var longID = storage.Store("foo", MakeRow("p", bigLong));

            storage.Store("foo", MakeRow("p", Math.PI));
            Assert.Equal(bigLong, db.Cell<long>(false, "select p from foo where id = {0}", longID));
        }
Exemple #17
0
 public static void CheckGuidQuery(IDatabaseAccess db, DatabaseStorage storage)
 {
     storage.EnterFluidMode();
     storage.Store("foo", MakeRow("g", SAMPLE_GUID));
     Assert.Equal(SAMPLE_GUID, db.Cell<Guid>(false, "select g from foo where g = {0}", SAMPLE_GUID));
 }
Exemple #18
0
        public static void CheckStoringNull(DatabaseStorage storage)
        {
            storage.EnterFluidMode();

            var row = MakeRow("p", 1);
            var id = storage.Store("foo", row);

            row = storage.Load("foo", id);
            row["p"] = null;
            storage.Store("foo", row);

            row = storage.Load("foo", id);
            Assert.Null(row["p"]);
        }