Esempio n. 1
0
 public void SimpleInsertTest()
 {
     using(var con = new SQLiteConnection("Data Source=:memory:"))
         using(var cmd = con.CreateCommand())
             using(var reader = new StreamReader(Path.Combine("Sql", "People.sql")))
             {
                 con.Open();
                 cmd.CommandText = reader.AllLines().First();
                 cmd.ExecuteNonQuery();
                 cmd.CommandText = "INSERT INTO People VALUES(null,'Singleton',-25.5,'PHU74JVF3MT','ccb52c4a-c96a-4b44-9c40-6faff8f2a04b')";
                 cmd.ExecuteNonQuery();
                 cmd.CommandText = "select count(*) from people;";
                 var ct = cmd.ExecuteScalar();
                 Assert.That(ct, Is.EqualTo(1));
                 var guid = new Guid("ccb52c4a-c96a-4b44-9c40-6faff8f2a04b");
                 cmd.CommandText = string.Format("select * from people where testguid = '{0}'", guid.ToString());
                 var res = cmd.ExecuteReader();
                 res.Read();
                 Assert.That(res["testguid"], Is.EqualTo(guid));
                 Assert.That(res[4], Is.EqualTo(guid));
                 Assert.That(res["id"], Is.Not.Null);
                 Assert.That(res["id"], Is.GreaterThan(0));
                 Assert.That(res["name"], Is.Not.Null);
                 Assert.That(res["name"], Is.EqualTo("Singleton"));
                 Assert.That(res["double"], Is.EqualTo(-25.5M));
                 Assert.That(res["testtext"], Is.EqualTo("PHU74JVF3MT"));
             }
 }
Esempio n. 2
0
 public void BulkInsert()
 {
     using(var con = new SQLiteConnection("Data Source=" + _filename))
         using(var cmd = con.CreateCommand())
             using(var reader = new StreamReader(Path.Combine("Sql", "People.sql")))
             {
                 con.Open();
                 foreach(var sql in reader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
                 {
                     cmd.CommandText = sql;
                     cmd.ExecuteNonQuery();
                 }
                 cmd.CommandText = "select count(*) from people;";
                 var ct = cmd.ExecuteScalar();
                 Assert.That(ct, Is.EqualTo(100));
             }
 }
		public void SimpleInsertForeignTableTest()
		{
			using (var con = new SQLiteConnection("Data Source=:memory:"))
			using (var cmd = con.CreateCommand())
			using (var preader = new StreamReader(Path.Combine("Sql", "People.sql")))
			using (var sreader = new StreamReader(Path.Combine("Sql", "Shirts.sql")))
			{
				con.Open();
				foreach (var sql in preader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
				{
					cmd.CommandText = sql;
					cmd.ExecuteNonQuery();
				}
				foreach (var sql in sreader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
				{
					cmd.CommandText = sql;
					cmd.ExecuteNonQuery();
				}
			}
		}