/// <summary> /// Executes query against table and returns number of records satisfying this query /// </summary> /// <param name="TableName">Table name to run query against to</param> /// <param name="Rules">Collection of query rules</param> /// <returns>Number or records that satisfy select query provided</returns> public virtual int ExecuteGetCountQuery(string TableName, List<Rule> Rules) { dhtmlxFieldsCollection newRequestedFields = new dhtmlxFieldsCollection(); newRequestedFields.Add(new ExpressionField("1", "dummyValue")); #region LOG ENTRY #if !NO_LOG Log.WriteLine(this, string.Format("ExecuteGetCountQuery: TableName: {0}, RequesteFields: {1}, Rules: {2}", TableName, Tools.Join(newRequestedFields, ","), Tools.Join(Rules, ","))); #endif #endregion string selectQuery = this.CreateSelectQuery(TableName, newRequestedFields, Rules, null, 0, 0); int count = Convert.ToInt32(this.ExecuteScalar("SELECT COUNT(*) FROM (" + selectQuery + ") TBL")); #region LOG ENTRY #if !NO_LOG Log.WriteLine(this, "Result: " + count.ToString()); #endif #endregion return count; }
/// <summary> /// Converts columns/fields stored in SQL query into Field objects collection /// </summary> /// <param name="Fields">Database engine specific representation of columns (e.g. "CustomerName, CustomerID, CreatedDate as RegisterDate")</param> /// <returns>Collection of Field objects that represent given fields list</returns> protected virtual IEnumerable<Field> ParseFields(string Fields) { string[] FieldsArray = Regex.Split(Fields, ",", RegexOptions.IgnoreCase); dhtmlxFieldsCollection ResultFieldsCollection = new dhtmlxFieldsCollection(); foreach (string Field in FieldsArray) { if (Field.Trim() != String.Empty) ResultFieldsCollection.Add(this.ParseField(Field)); } return ResultFieldsCollection; }