Exemple #1
0
        public async Task CanWriteBlob()
        {
            const int length = 512;

            using (var db = new Sqlite3().OpenTest("CREATE TABLE t1(id INTEGER PRIMARY KEY, data BLOB)"))
            {
                using (var stmt = db.Prepare($"INSERT INTO t1(data) VALUES(?)"))
                {
                    Assert.IsTrue(stmt.Bindings.SetBlob(1, length));
                    Assert.AreEqual(Status.Done, stmt.Step());
                }

                var expected = new byte[length];
                new Random().NextBytes(expected);

                using (var blob = db.OpenBlob("main", "t1", "data", 1, 1))
                    using (var stream = new MemoryStream(expected))
                        await stream.CopyToAsync(blob, 60);

                using (var stmt = db.Prepare($"SELECT data FROM t1"))
                {
                    Assert.AreEqual(Status.Row, stmt.Step());
                    Assert.IsTrue(expected.SequenceEqual(stmt.Columns.GetBlob(0)));
                }
            }
        }