How do you run a batch of SQL statements using the SQLite.NET PCL How do you run a batch of SQL statements using the SQLite.NET PCL sqlite sqlite

How do you run a batch of SQL statements using the SQLite.NET PCL


Can't you do :

    [Test]    public void AlanTest()    {        var queries = new List<string> ()         {            " DELETE FROM Product",            " INSERT INTO Product VALUES (1,\"Name1\",1,1)",            " INSERT INTO Product VALUES (2,\"Name2\",2,3)"        };        db.BeginTransaction ();        queries.ForEach (query => db.Execute (query));        db.Commit ();    }

You don't really need the transaction, just faster execution / checkpoint rollback...


I just ran into this issue too. I found a blog post that explains why.

Here is what the post says in case it goes missing.

All of the code [in sqlite-net] correctly checks the result codes and throws exceptions accordingly.

Although I haven't posted all relevant code here, I did review it, and the real origin of this behavior is elsewhere - in the native sqlite3.dll sqlite3_prepare_v2 method. Here's the relevant part of the documentation:

These routines only compile the first statement in zSql, so *pzTail is left pointing to what remains uncompiled.Since sqlite-net doesn't do anything with the uncompiled tail, only the first statement in the command is actually executed. The remainder is silently ignored. In most cases you won't notice that when using sqlite-net. You will either use its micro ORM layer or execute individual statements. The only common exception that comes to mind, is trying to execute DDL or migration scripts which are typically multi statement batches.