Beispiel #1
0
        public void TestSession10_IterateChangeSet()
        {
            MakeAndValidateTableChanges();

            // create a change set
            Assert.That(SQLiteSession.GenerateChangeSet(session, out SQLiteChangeSet changeSet), Is.EqualTo(SQLite3.Result.OK));
            using (changeSet)
            {
                Assert.That(changeSet.size, Is.GreaterThan(0));

                // create an iterator so can iterate through change set
                Assert.That(SQLiteSession.ChangeSetStart(out Sqlite3ChangesetIterator iter, changeSet), Is.EqualTo(SQLite3.Result.OK));
                using (iter)
                {
                    SQLite3.Result result;
                    while ((result = SQLiteSession.ChangeSetNext(iter)) == SQLite3.Result.Row)
                    {
                        Assert.That(result, Is.EqualTo(SQLite3.Result.Row));

                        // get table, column, and other information about this change
                        Assert.That(SQLiteSession.ChangeSetOp(iter, out string table, out int columnCount, out SQLiteSession.ActionCode op, out bool indirect), Is.EqualTo(SQLite3.Result.OK));

                        Assert.That(table, Is.EqualTo("TestTable1"));
                        Assert.That(columnCount, Is.GreaterThan(0));
                        Assert.That(op, Is.EqualTo(SQLiteSession.ActionCode.SQLITE_INSERT));
                        Assert.That(indirect, Is.False);

                        // since insert, should be able to get new values inserted
#pragma warning disable IDE0018                                            // Inline variable declaration
                        SQLiteValue value;                                 // 0th column is primary key
#pragma warning restore IDE0018                                            // Inline variable declaration
                        Assert.That(SQLiteSession.ChangeSetNewValue(iter, 1, out value), Is.EqualTo(SQLite3.Result.OK));
                        Assert.That(value.GetValue(), Is.EqualTo("test")); // 1st column = myString
                        Assert.That(SQLiteSession.ChangeSetNewValue(iter, 2, out value), Is.EqualTo(SQLite3.Result.OK));
                        Assert.That(value.GetValue(), Is.EqualTo(3));      // 2nd column = myInt
                        // DateTime is stored as long, WARNING may vary, see storeDateTimeAsTicks when creating db connection
                        // Guid is stored as string

                        // verify we can retrieve all values regardless of type
                        for (int i = 0; i < columnCount; i++)
                        {
                            Assert.That(SQLiteSession.ChangeSetNewValue(iter, i, out value), Is.EqualTo(SQLite3.Result.OK));
                            Assert.That(value.GetValue(), Is.Not.Null);
                        }
                    }
                    Assert.That(result, Is.EqualTo(SQLite3.Result.Done));
                }
                Assert.That(iter.IsInvalid, Is.True);
            }
            Assert.That(changeSet.buffer.IsInvalid, Is.True);

            // done with our session
            SQLiteSession.Delete(session);
        }