public void TestMultiTransactionsSQLite() { using (var db = new SQLDBConnection(SQLiteTestConnection)) { db.Open(); db.Open(); db.Transaction((th) => { try { th.ExecuteNonQuery("DROP TABLE test"); } catch (Exception) { }; }); db.Transaction((th) => { try { th.ExecuteNonQuery("DROP TABLE test2"); } catch (Exception) { }; }); db.Transaction((th) => { th.ExecuteNonQuery("CREATE TABLE test(i INTEGER)"); th.ExecuteNonQuery("INSERT INTO test(i) VALUES(1)"); var v = db.ReadOneInt("SELECT COUNT(*) FROM test"); // Test Reader executed in transaction context db.Transaction((th) => { th.ExecuteNonQuery("CREATE TABLE test2(i INTEGER)"); th.ExecuteNonQuery("INSERT INTO test2(i) VALUES(1)"); th.ExecuteNonQuery("DROP TABLE test2"); }); th.ExecuteNonQuery("DROP TABLE test"); }); db.Close(); }; }
public void TestSelectOutOfTransactionSQLite() { using (var db = new SQLDBConnection(SQLiteTestConnection)) { db.Open(); db.Transaction((th) => { try { th.ExecuteNonQuery("DROP TABLE test"); } catch (Exception) { }; }); db.Transaction((th) => { th.ExecuteNonQuery("CREATE TABLE test(i INTEGER)"); th.ExecuteNonQuery("INSERT INTO test(i) VALUES(1)"); }); db.ExecuteReader("SELECT i FROM test", (rd) => { db.Transaction((th) => { th.ExecuteNonQuery("UPDATE test SET i=2 WHERE i=1"); //db.ExecuteReader("SELECT i FROM test", (rd) => //{ // return true; //}); }); return(true); }); db.Transaction((th) => { th.ExecuteNonQuery("DROP TABLE test"); }); db.Close(); }; }
public void TestDBException() { var s = ""; using (var db = new SQLDBConnection("sqlite", "", "", ":memory:")) { db.Open(); try { var SQL = "SELECT * FROM NotExistedTable"; db.ExecuteReader(SQL, (rd) => { return(true); }); }catch (Exception ex) { s = ex.Message; } db.Close(); }; if (s == "") { throw new Exception("Exception was not generated in ExecuteReader"); } }
public void TestExecuteReader() { using (var db = new SQLDBConnection("sqlite", "", "", ":memory:")) { db.Open(); try { db.Transaction((t) => { t.ExecuteNonQuery("CREATE TABLE test(i INTEGER)"); t.ExecuteNonQuery("INSERT INTO test VALUES(:V)", DbParam.New("V", 1)); }); } catch (Exception) { } var i = 0; db.ExecuteReader(@"SELECT * FROM test WHERE i=:V", (rd) => { i++; return(true); }, DbParam.New("V", 1)); if (i != 1) { throw new Exception("Data read not successfull"); } db.Close(); }; }
public void TestSqliteConnection() { using (var db = new SQLDBConnection(SQLiteTestConnection)) { db.Open(); db.Close(); }; }
public void TestExecuteNonQuery() { using (var db = new SQLDBConnection("sqlite", "", "", ":memory:")) { db.Open(); db.Transaction((t) => { try{ t.ExecuteNonQuery("CREATE TABLE test(i INTEGER)"); }catch (Exception) {} t.ExecuteNonQuery("INSERT INTO test VALUES(:V)", DbParam.New("V", 1)); }); db.Close(); }; }