public void Roundtrip() { AssertExtensions.WithCulture("de-DE", () => { _storage.EnterFluidMode(); var checker = new RoundtripChecker(_db, _storage); // supported ranks checker.Check(null, null); checker.Check((sbyte)123, (sbyte)123); checker.Check(1000, 1000); checker.Check(0x80000000L, 0x80000000L); checker.Check(3.14, 3.14); checker.Check("hello", "hello"); checker.Check(SharedChecks.SAMPLE_DATETIME, SharedChecks.SAMPLE_DATETIME); checker.Check(SharedChecks.SAMPLE_BLOB, SharedChecks.SAMPLE_BLOB); // extremal vaues SharedChecks.CheckRoundtripOfExtremalValues(checker, checkDateTime: true); // conversion to string SharedChecks.CheckBigNumberRoundtripForcesString(checker); checker.Check(SharedChecks.SAMPLE_GUID, SharedChecks.SAMPLE_GUID.ToString()); // bool checker.Check(true, (sbyte)1); checker.Check(false, (sbyte)0); // enum checker.Check(DayOfWeek.Thursday, (sbyte)4); }); }
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"]); }
public void Roundtrip() { AssertExtensions.WithCulture("de-DE", () => { _storage.EnterFluidMode(); var checker = new RoundtripChecker(_db, _storage); // supported ranks checker.Check(null, null); checker.Check(true, true); checker.Check(1000, 1000); checker.Check(0x80000000L, 0x80000000L); checker.Check(3.14, 3.14); checker.Check(7.90M, 7.90M); checker.Check("hello", "hello"); checker.Check(SharedChecks.SAMPLE_DATETIME, SharedChecks.SAMPLE_DATETIME); checker.Check(SharedChecks.SAMPLE_GUID, SharedChecks.SAMPLE_GUID); checker.Check(SharedChecks.SAMPLE_BLOB, SharedChecks.SAMPLE_BLOB); // https://github.com/npgsql/npgsql/issues/11 checker.Check( SharedChecks.SAMPLE_DATETIME_OFFSET, SharedChecks.SAMPLE_DATETIME_OFFSET.ToLocalTime().DateTime ); // extremal vaues SharedChecks.CheckRoundtripOfExtremalValues(checker, checkDecimal: true, checkDateTime: true); checker.Check(UInt64.MaxValue, (decimal)UInt64.MaxValue); // enum checker.Check(DayOfWeek.Thursday, (int)4); }); }
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")); }
public void Roundtrip() { AssertExtensions.WithCulture("de-DE", () => { _storage.EnterFluidMode(); var checker = new RoundtripChecker(_db, _storage); // native SQLite types checker.Check(null, null); checker.Check("hello", "hello"); checker.Check(123L, 123L); checker.Check(3.14, 3.14); checker.Check(SharedChecks.SAMPLE_BLOB, SharedChecks.SAMPLE_BLOB); // extremal vaues SharedChecks.CheckRoundtripOfExtremalValues(checker); // conversion to string checker.Check(SharedChecks.SAMPLE_DATETIME, "1984-06-14 11:22:33"); SharedChecks.CheckBigNumberRoundtripForcesString(checker); // Guid #if SQLITE_MODE_GENUINE checker.Check(SharedChecks.SAMPLE_GUID, SharedChecks.SAMPLE_GUID.ToByteArray()); #else checker.Check(SharedChecks.SAMPLE_GUID, SharedChecks.SAMPLE_GUID.ToString().ToUpper()); #endif // upscale to long checker.Check(0, 0L); checker.Check(1, 1L); checker.Check(true, 1L); checker.Check(false, 0L); checker.Check(DayOfWeek.Thursday, 4L); }); }
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"]); }
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"]); }
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 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)); })); }
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)); }
public void TransactionIsolation() { Assert.Equal(IsolationLevel.Unspecified, _db.TransactionIsolation); using (var otherFixture = new MariaDbConnectionFixture()) { var dbName = _db.Cell <string>(false, "select database()"); var otherDb = new DatabaseAccess(otherFixture.Connection, null); otherDb.Exec("use " + dbName); SharedChecks.CheckReadUncommitted(_db, otherDb); } }
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); }
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 Roundtrip() { AssertExtensions.WithCulture("de-DE", () => { _storage.EnterFluidMode(); var checker = new RoundtripChecker(_db, _storage); // similar to https://github.com/StackExchange/dapper-dot-net/issues/229 _db.QueryExecuting += cmd => { foreach (SqlParameter p in cmd.Parameters) { if (Equals(p.Value, DateTime.MinValue)) { p.SqlDbType = SqlDbType.DateTime2; } } }; // supported ranks checker.Check(null, null); checker.Check(255, (byte)255); checker.Check(1000, 1000); checker.Check(0x80000000L, 0x80000000L); checker.Check(3.14, 3.14); checker.Check("hello", "hello"); checker.Check(SharedChecks.SAMPLE_DATETIME, SharedChecks.SAMPLE_DATETIME); checker.Check(SharedChecks.SAMPLE_DATETIME_OFFSET, SharedChecks.SAMPLE_DATETIME_OFFSET); checker.Check(SharedChecks.SAMPLE_GUID, SharedChecks.SAMPLE_GUID); checker.Check(SharedChecks.SAMPLE_BLOB, SharedChecks.SAMPLE_BLOB); // extremal vaues SharedChecks.CheckRoundtripOfExtremalValues(checker, checkDateTime: true, checkDateTimeOffset: true); // conversion to string SharedChecks.CheckBigNumberRoundtripForcesString(checker); // bool checker.Check(true, (byte)1); checker.Check(false, (byte)0); // enum checker.Check(DayOfWeek.Thursday, (byte)4); }); }
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); }
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); }
public void ChangeSchemaWhenFrozen() { Assert.Throws(SQLitePortability.ExceptionType, () => { _storage.Store("unlucky", SharedChecks.MakeRow("a", 1)); }); }
public void CustomRank_MissingColumn() { SharedChecks.CheckCustomRank_MissingColumn(_db, _storage); }
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")); }
public void CompoundKey() { SharedChecks.CheckCompoundKey(_storage, _keys); }
public void StoringNull() { SharedChecks.CheckStoringNull(_storage); }
public void GuidQuery() { SharedChecks.CheckGuidQuery(_db, _storage); }
public void DateTimeQueries() { SharedChecks.CheckDateTimeQueries(_db, _storage); }
public void SchemaReadingKeepsCache() { SharedChecks.CheckSchemaReadingKeepsCache(_db, _storage); }
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); }
public void LongToDouble() { SharedChecks.CheckLongToDouble(_db, _storage); }