コード例 #1
0
 /// <summary>
 /// Constructs the class
 /// </summary>
 /// <param name="filter">
 /// Filter used on the evaluation
 /// </param>
 public AndFilter(AndFilter filter) : this(filter.InnerFilters)
 {
 }
コード例 #2
0
		public void InventoryTest()
		{
			DataBase db = Connect();
			var generator = new OKHOSTING.Sql.Net4.SqlServer.SqlGenerator();

			//Create table store
			Table store = new Table("store");
			store.Columns.Add(new Column() { Name = "Id", DbType = DbType.Int32, IsPrimaryKey = true, IsAutoNumber = true, Table = store });
			store.Columns.Add(new Column() { Name = "Name", DbType = DbType.AnsiString, Length = 50, IsNullable = false, Table = store });
			store.Columns.Add(new Column() { Name = "Inventory", DbType = DbType.AnsiString, Length = 50, IsNullable = false, Table = store });
			store.Columns.Add(new Column() { Name = "Employee", DbType = DbType.AnsiString, Length = 100, IsNullable = false, Table = store });

			Command sql = generator.Create(store);
			db.Execute(sql);

			//First inserts store 
			Insert insert = new Insert();
			insert.Table = store;
			insert.Values.Add(new ColumnValue(store["Id"], 1));
			insert.Values.Add(new ColumnValue(store["Name"], "Abarrotes Torrez"));
			insert.Values.Add(new ColumnValue(store["Inventory"], "Torreon"));
			insert.Values.Add(new ColumnValue(store["Employee"], "Juan Rocha Gomez"));

			sql = generator.Insert(insert);
			int affectedRows = db.Execute(sql);
			Assert.AreEqual(affectedRows, 1);

			//Second inserts store
			insert = new Insert();
			insert.Table = store;
			insert.Values.Add(new ColumnValue(store["Id"], 2));
			insert.Values.Add(new ColumnValue(store["Name"], "La Furiosa"));
			insert.Values.Add(new ColumnValue(store["Inventory"], "Zacatecas"));
			insert.Values.Add(new ColumnValue(store["Employee"], "Martin Torrez"));

			sql = generator.Insert(insert);
			affectedRows = db.Execute(sql);
			Assert.AreEqual(affectedRows, 1);

			//third inserts store
			insert = new Insert();
			insert.Table = store;
			insert.Values.Add(new ColumnValue(store["Id"], 3));
			insert.Values.Add(new ColumnValue(store["Name"], "Los dos amigos"));
			insert.Values.Add(new ColumnValue(store["Inventory"], "Durango"));
			insert.Values.Add(new ColumnValue(store["Employee"], "Luis Martinez"));

			sql = generator.Insert(insert);
			affectedRows = db.Execute(sql);
			Assert.AreEqual(affectedRows, 1);

			//Fourth inserts store
			insert = new Insert();
			insert.Table = store;
			insert.Values.Add(new ColumnValue(store["Id"], 4));
			insert.Values.Add(new ColumnValue(store["Name"], "La Pasada"));
			insert.Values.Add(new ColumnValue(store["Inventory"], "Nayarit"));
			insert.Values.Add(new ColumnValue(store["Employee"], "Raul Gomez"));

			sql = generator.Insert(insert);
			affectedRows = db.Execute(sql);
			Assert.AreEqual(affectedRows, 1);

			//select whit OrFilter
			Select select = new Select();
			select.Table = store;
			select.Columns.Add(store["id"]);
			select.Columns.Add(store["Name"]);
			select.Columns.Add(store["Employee"]);

			OrFilter filter = new OrFilter();
			filter.InnerFilters.Add(new ValueCompareFilter() { Column = store["id"], ValueToCompare = 1, Operator = Data.CompareOperator.Equal });
			filter.InnerFilters.Add(new ValueCompareFilter() { Column = store["id"], ValueToCompare = 2, Operator = Data.CompareOperator.Equal });
			select.Where.Add(filter);


			sql = generator.Select(select);
			var result = db.GetDataTable(sql);

			Assert.AreEqual(result.Count, 2);

			//select whit like
			select = new Select();
			select.Table = store;
			select.Columns.Add(store["Name"]);
			select.Columns.Add(store["Employee"]);
			select.Where.Add(new ValueCompareFilter() { Column = store["Name"], ValueToCompare = '%' + "la" + '%', Operator = Data.CompareOperator.Like });

			sql = generator.Select(select);
			result = db.GetDataTable(sql);
			Assert.AreEqual(result.Count, 2);


			Assert.AreEqual(result.Count, 0);


			//select whit AndFilter
			select = new Select();
			select.Table = store;
			select.Columns.Add(store["id"]);
			select.Columns.Add(store["Name"]);
			select.Columns.Add(store["Inventory"]);

			AndFilter and = new AndFilter();
			and.InnerFilters.Add(new ValueCompareFilter() { Column = store["id"], ValueToCompare = 1, Operator = Data.CompareOperator.Equal });
			and.InnerFilters.Add(new ValueCompareFilter() { Column = store["Name"], ValueToCompare = "Abarrotes Torrez", Operator = Data.CompareOperator.Equal });
			select.Where.Add(and);

			sql = generator.Select(select);
			result = db.GetDataTable(sql);
			Assert.AreEqual(result.Count, 0);

			//Drop table
			sql = generator.Drop(store);
			db.Execute(sql);
			Assert.IsFalse(db.ExistsTable(store.Name));
		}
コード例 #3
0
		/// <summary>
		/// Constructs the class
		/// </summary>
		/// <param name="filter">
		/// Filter used on the evaluation
		/// </param>
		public AndFilter(AndFilter filter) : this(filter.InnerFilters) { }