public void TestIntegerData(int id, long expectedInteger, long?expectedNewInteger) { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("MyTable"); IEnumerable <Sqlite3Row> rows = tbl.EnumerateRows(); foreach (Sqlite3Row row in rows) { Assert.True(row.TryGetOrdinal(1, out long actual)); if (row.RowId == id) { Assert.Equal(expectedInteger, actual); if (expectedNewInteger.HasValue) { Assert.True(row.TryGetOrdinal(2, out long actualOther)); Assert.Equal(expectedNewInteger.Value, actualOther); } else { Assert.False(row.TryGetOrdinal(2, out long _)); } return; } } Assert.True(false, "Number is missing"); } }
public void TestTableRowCount() { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("MyTable"); IEnumerable <Sqlite3Row> rows = tbl.EnumerateRows(); int actual = rows.Count(); Assert.Equal(11, actual); } }
public void TestIntegerRowCount(int expected) { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("IntegerTable"); IEnumerable <Sqlite3Row> rows = tbl.EnumerateRows(); int actual = rows.Count(); Assert.Equal(expected, actual); } }
public void TestIntegerData(int id, long expected) { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("IntegerTable"); Sqlite3Row row = tbl.GetRowById(id); Assert.NotNull(row); Assert.True(row.TryGetOrdinal(1, out long actual)); Assert.Equal(expected, actual); } }
public void TestRealRowCount() { int expected = _testData.Count; using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("RealTable"); IEnumerable <Sqlite3Row> rows = tbl.EnumerateRows(); int actual = rows.Count(); Assert.Equal(expected, actual); } }
public static Sqlite3Row GetRowById(this Sqlite3Table tbl, long rowId) { foreach (var row in tbl.EnumerateRows()) { if (row.RowId != rowId) { continue; } return(row); } return(null); }
public void TestStringDataContents(SqliteEncoding encoding, int id, string expectedLanguage, string expectedString) { using (Sqlite3Database db = new Sqlite3Database(Get(encoding))) { Sqlite3Table tbl = db.GetTable("EncodingTable" + encoding); Sqlite3Row row = tbl.GetRowById(id); Assert.NotNull(row); Assert.True(row.TryGetOrdinal(1, out string actualLang)); Assert.True(row.TryGetOrdinal(2, out string actualText)); Assert.Equal(expectedLanguage, actualLang); Assert.Equal(expectedString, actualText); } }
public void TestLongText() { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("urls"); List <Sqlite3Row> rows = tbl.EnumerateRows().ToList(); Assert.Single(rows); Sqlite3Row row = rows.Single(); Assert.Equal(6014, row.RowId); Assert.True(row.TryGetOrdinal(1, out string actual)); Assert.Equal(_expected, actual); } }
public void TestRealData() { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("DataTable"); List <Sqlite3Row> rows = tbl.EnumerateRows().ToList(); Assert.Single(rows); Sqlite3Row row = rows.Single(); Assert.Equal(1, row.RowId); Assert.True(row.TryGetOrdinal(1, out byte[] actual)); Assert.Equal(_expected, actual); } }
public void TestRealData(int id, long expectedLong) { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("RealTable"); Sqlite3Row row = tbl.GetRowById(id); Assert.NotNull(row); Assert.True(row.TryGetOrdinal(1, out double actual)); long actualLong = BitConverter.DoubleToInt64Bits(actual); // Note: There is a loss of precision in the sqlite3 cli when generating the test database // This, and the similar loss of precision in C# / floating points here leads to the code below Assert.True(Math.Abs(expectedLong - actualLong) <= 2); } }
private void InitializeMasterTable() { // Parse table on Page 1, the sqlite_master table BTreePage rootBtree = BTreePage.Parse(_reader, 1); // Fake the schema for the sqlite_master table Sqlite3SchemaRow schemaRow = new Sqlite3SchemaRow { Database = this, Type = "table", Name = "sqlite_master", TableName = "sqlite_master", RootPage = rootBtree.Page, Sql = "CREATE TABLE sqlite_master (type TEXT, name TEXT, tbl_name TEXT, rootpage INTEGER, sql TEXT);" }; Sqlite3Table table = new Sqlite3Table(_reader, rootBtree, schemaRow); _masterTable = new Sqlite3MasterTable(this, table); }
public bool TryGetTable(string name, out Sqlite3Table table) { IEnumerable <Sqlite3SchemaRow> tables = GetTables(); foreach (Sqlite3SchemaRow tbl in tables) { if (tbl.TableName != name || tbl.Type != "table") { continue; } // Found it BTreePage root = BTreePage.Parse(_reader, tbl.RootPage); table = new Sqlite3Table(_reader, root, tbl); return(true); } table = null; return(false); }
public void TestIntegerData(int id, long expectedInteger, long?expectedNewInteger) { using (Sqlite3Database db = new Sqlite3Database(_stream)) { Sqlite3Table tbl = db.GetTable("MyTable"); Sqlite3Row row = tbl.GetRowById(id); Assert.NotNull(row); Assert.True(row.TryGetOrdinal(1, out long actual)); Assert.Equal(expectedInteger, actual); if (expectedNewInteger.HasValue) { Assert.True(row.TryGetOrdinal(2, out long actualOther)); Assert.Equal(expectedNewInteger.Value, actualOther); } else { Assert.False(row.TryGetOrdinal(2, out long _)); } } }
public static SqlTableDefinition GetTableDefinition(this Sqlite3Table table) { return(table.SchemaDefinition.GetTableDefinition()); }