UWP 包装 sqlite 插入查询到 sql 事务

UWP wrap sqlite insert queries into sql transaction

我正在尝试将一些 csv 样式 file.txt 内容插入本地 SQLite 数据库,我处理文件读取、内容处理并获取一些字符串:

INSERT OR REPLACE INTO mytab (id,name,adress) VALUES(1,john,adress1)
INSERT OR REPLACE INTO mytab (id,name,adress) VALUES(2,marry,adress2)
INSERT OR REPLACE INTO mytab (id,name,adress) VALUES(3,lama,ruadress3)
//...

现在我想打开一个 sqlite 事务,执行所有这些插入,然后关闭事务。我正在使用 SQLite.Net-PCLSQLite for Universal App Platform,我该怎么做?

我尝试打开这样的连接:

var sqlpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "Mydb.sqlite");
SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlpath);

//I'am trying to open transaction - but get ERROR -> SQLiteCommand does not contain contstructor that takes 2 arguments
 SQLiteCommand cmd = new SQLiteCommand("BEGIN", conn);

SQLite.Net-PCL中的SQLiteConnectionclass有BeginTransactionCommitRollback方法,所以你可以在BeginTransaction和提交:

// Open connection
SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), sqlpath);
try {
   // Start transaction
   conn.BeginTransaction();
   try {
      // Execute commands...
      // Commit transaction
      conn.Commit();
   }
   catch (Exception) {
      // Rollback transaction
      conn.Rollback();
   }
}
finally {
   // Close connection
   conn.Close();
}