Пример #1
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");
         }
     };
 }
Пример #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 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");
            }
        }
Пример #4
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();
     };
 }