Пример #1
0
        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();
            };
        }
Пример #2
0
        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();
            };
        }
Пример #3
0
 public void TestNestedReaderSQLite()
 {
     using (var db = new SQLDBConnection(SQLiteTestConnection))
     {
         db.Open();
         try
         {
             db.Transaction((t) =>
             {
                 try { t.ExecuteNonQuery("DROP TABLE test"); } catch (Exception) { }
             });
             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) => {
             db.ExecuteReader("SELECT * FROM test", (rd) =>
             {
                 return(true);
             });
             i++;
             return(true);
         }, DbParam.New("V", 1));
         if (i != 1)
         {
             throw new Exception("Data read not successfull");
         }
     };
 }
Пример #4
0
 public void TestReadSingleRow()
 {
     using (var db = new SQLDBConnection("sqlite", "", "", ":memory:"))
     {
         db.Transaction((t) =>
         {
             try{ t.ExecuteNonQuery("DROP TABLE test"); }catch (Exception) {}
             t.ExecuteNonQuery("CREATE TABLE test(i INTEGER,d REAL, dt DATETIME)");
             t.ExecuteNonQuery("INSERT INTO test VALUES(:I,:F,:DT)",
                               DbParam.New("I", 1), DbParam.New("F", 123.456), DbParam.New("DT", DateTime.Now));
         });
         var v = db.ReadVector <long>("SELECT i FROM test");
         if (v[0] != 1)
         {
             throw new Exception("Data read not successfull");
         }
         var d = db.ReadOneDouble("SELECT d FROM test");
         if (d != 123.456)
         {
             throw new Exception("Data read not successfull");
         }
         var dt = db.ReadOneDateTime("SELECT dt FROM test");
         if (dt == null)
         {
             throw new Exception("Data read not successfull");
         }
     };
 }
Пример #5
0
 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();
     };
 }
Пример #6
0
 public DbTests()
 {
     db = new SQLDBConnection("sqlite", "", "", ":memory:");
     db.Transaction(th =>
     {
         th.ExecuteNonQuery("CREATE TABLE test(c1 INTEGER,c2 INTEGER, c3 INTEGER)");
         th.ExecuteNonQuery("INSERT INTO test VALUES(11,12,13)");
         th.ExecuteNonQuery("INSERT INTO test VALUES(21,22,23)");
         th.ExecuteNonQuery("INSERT INTO test VALUES(31,32,33)");
     });
 }
Пример #7
0
 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();
     };
 }