Esempio n. 1
0
		/// <summary>
		/// Computes the given expression on the current_rows that
		/// pass the filter criteria.
		/// </summary>
		public object Compute (string expression, string filter)
		{
			// expression is an aggregate function
			// filter is an expression used to limit rows

			DataRow [] rows = Select (filter);

			if (rows == null || rows.Length == 0)
				return DBNull.Value;

			Parser parser = new Parser (rows);
			IExpression expr = parser.Compile (expression);
			object obj = expr.Eval (rows [0]);

			return obj;
		}
Esempio n. 2
0
		internal void CompileExpression (string expression)
		{
			if (expression != String.Empty) {
				if (AutoIncrement || Unique)
					throw new ArgumentException ("Cannot create an expression on a column that has AutoIncrement or Unique.");

				if (Table != null) {
					for (int i = 0; i < Table.Constraints.Count; i++) {
						if (Table.Constraints [i].IsColumnContained (this))
							throw new ArgumentException (
								String.Format (
									"Cannot set Expression property on column {0}, because it is a part of a constraint.",
									ColumnName));
					}
				}

				Parser parser = new Parser ();
				IExpression compiledExpression = parser.Compile (expression);

				if (Table != null) {
					if (compiledExpression.DependsOn (this))
						throw new ArgumentException ("Cannot set Expression property due to circular reference in the expression.");
					// Check if expression is ok
					if (Table.Rows.Count == 0)
						compiledExpression.Eval (Table.NewRow ());
					else
						compiledExpression.Eval (Table.Rows [0]);
				}
				ReadOnly = true;
				_compiledExpression = compiledExpression;
			} else {
				_compiledExpression = null;
				if (Table != null) {
					int defaultValuesRowIndex = Table.DefaultValuesRowIndex;
					if (defaultValuesRowIndex != -1)
						DataContainer.FillValues (defaultValuesRowIndex);
				}
			}
		}
Esempio n. 3
0
		/// <summary>
		/// Gets an array of all DataRow objects that match
		/// the filter in the order of the sort, that match
		/// the specified state.
		/// </summary>
		public DataRow [] Select (string filterExpression, string sort, DataViewRowState recordStates)
		{
			if (filterExpression == null)
				filterExpression = String.Empty;

			IExpression filter = null;
			if (filterExpression != String.Empty) {
				Parser parser = new Parser ();
				filter = parser.Compile (filterExpression);
			}

			DataColumn [] columns = _emptyColumnArray;
			ListSortDirection [] sorts = null;

			if (sort != null && !sort.Equals(String.Empty))
				columns = ParseSortString (this, sort, out sorts, false);

			if (Rows.Count == 0)
				return NewRowArray (0);

			//if sort order is not given, sort it in Ascending order of the
			//columns involved in the filter
			if (columns.Length == 0 && filter != null) {
				ArrayList list = new ArrayList ();
				for (int i = 0; i < Columns.Count; ++i) {
					if (!filter.DependsOn (Columns [i]))
						continue;
					list.Add (Columns [i]);
				}
				columns = (DataColumn []) list.ToArray (typeof (DataColumn));
			}

			bool addIndex = true;
			if (filterExpression != String.Empty)
				addIndex = false;
			Index index = GetIndex (columns, sorts, recordStates, filter, false, addIndex);

			int [] records = index.GetAll ();
			DataRow [] dataRows = NewRowArray (index.Size);
			for (int i = 0; i < dataRows.Length; i++)
				dataRows [i] = RecordCache [records [i]];

			return dataRows;
		}
Esempio n. 4
0
		public DataRow[] Select(string filterExpression, string sort, DataViewRowState recordStates) 
		{
			if (filterExpression == null)
				filterExpression = String.Empty;

			DataColumn[] columns = _emptyColumnArray;
			ListSortDirection[] sorts = null;
			if (sort != null && !sort.Equals(String.Empty))
				columns = ParseSortString (this, sort, out sorts, false);

			IExpression filter = null;
			if (filterExpression != String.Empty) {
				Parser parser = new Parser ();
				filter = parser.Compile (filterExpression);
			}

			Index index = FindIndex(columns, sorts, recordStates, filter);
			if (index == null)
				index = new Index(new Key(this,columns,sorts,recordStates,filter));

			int[] records = index.GetAll();
			DataRow[] dataRows = NewRowArray(index.Size);
			for (int i = 0; i < dataRows.Length; i++)
				dataRows[i] = RecordCache[records[i]];

			return dataRows;
		}