Exemple #1
0
    public void BusyErrorTest()
    {
        var dir = TestUtils.GetTestDirectoryPath();

        using var sqliteContext = new SqliteContext(new SqliteConnectionProvider(Path.Join(dir, "test.db")));

        using var transaction = new SqliteTransaction(sqliteContext, ITransaction.TransactionMode.Create);

        transaction.ExecuteNonQuery(() => @"CREATE TABLE IF NOT EXISTS TestTable (Name TEXT, Data Text);", "create");

        transaction.ExecuteNonQuery(() => @"INSERT INTO TestTable (Name, Data) VALUES('foo', 'bar');", "mutation");

        transaction.ExecuteNonQuery(() => @"INSERT INTO TestTable (Name, Data) VALUES('foo', 'bar');", "mutation");

        Assert.Catch(
            () => transaction.ExecuteReader(() => @"SELECT Data FROM TestTable WHERE Name='foo';", "query-foo-data", _ =>
        {
            transaction.ExecuteNonQuery(() => @"INSERT INTO TestTable (Name, Data) VALUES('foo', 'bar');", "mutation");
            return(0);
        }));

        var result = transaction.ExecuteScalar(() => @"SELECT Data FROM TestTable WHERE Name='foo';", "query-foo-data");

        Assert.AreEqual("bar", result);
    }