/// <summary> /// Create a new <see cref="SQLite3Transaction" /> /// </summary> /// <param name="connection"> /// The <see cref="SQLite3" /> connection on which to create the transaction /// </param> internal SQLite3Transaction(SQLite3 connection) { if (connection == null) throw new ArgumentNullException("connection"); if (connection.InTransaction) throw new SQLite3Exception("There is a transaction present"); _connection = connection; _connection.Query("BEGIN"); }
private static void Main() { string filename = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "test.sqlite" ); using (var db = new SQLite3(filename)) { try { using (SQLite3Transaction transaction = db.BeginTransaction()) { db.Query("CREATE TABLE User ( ID INTEGER PRIMARY KEY, Name TEXT UNIQUE );"); db.Query("INSERT INTO User (Name) VALUES ('John')"); db.Query("INSERT INTO User (Name) VALUES ('Jeff')"); db.Query("INSERT INTO User (Name) VALUES ('Jesus')"); transaction.Commit(); } } catch (SQLite3Exception ex) { Console.WriteLine("EXCEPTION: " + ex.Message); } using (IEnumerator<User> enumerator = db.QueryEnumerator<User>("SELECT ID, Name FROM User")) { enumerator.MoveNext(); enumerator.MoveNext(); Console.WriteLine(enumerator.Current); enumerator.Reset(); while (enumerator.MoveNext()) Console.WriteLine(enumerator.Current); } } }