public IList<int> RegexSearch(Table table, int column, string regularExpression, string expressionOps) { // Get the ordered column, IList<int> row_list = table.SelectAll(column); // The result matched rows, List<int> result_list = new List<int>(); // Make into a new list that matches the pattern, Regex regex; try { RegexOptions options = RegexOptions.None; if (expressionOps != null) { if (expressionOps.IndexOf('i') != -1) { options |= RegexOptions.IgnoreCase; } if (expressionOps.IndexOf('s') != -1) { options |= RegexOptions.Singleline; } if (expressionOps.IndexOf('m') != -1) { options |= RegexOptions.Multiline; } } regex = new Regex(regularExpression, options); } catch (Exception) { // Incorrect syntax means we always match to an empty list, return result_list; } // For each row in the column, test it against the regular expression. int size = row_list.Count; for (int i = 0; i < size; ++i) { int row_index = row_list[i]; TObject cell = table.GetCell(column, row_index); // Only try and match against non-null cells. if (!cell.IsNull) { Object ob = cell.Object; String str = ob.ToString(); // If the column matches the regular expression then return it, if (regex.IsMatch(str)) { result_list.Add(row_index); } } } return result_list; }
/// <summary> /// Constructs the result set. /// </summary> /// <param name="query"></param> /// <param name="result"></param> public QueryResult(SqlQuery query, Table result) { this.query = query; this.result = result; streamableBlobMap = new Dictionary<long, StreamableObject>(); resultRowCount = result.RowCount; // HACK: Read the contents of the first row so that we can pick up // any errors with reading, and also to fix the 'uniquekey' bug // that causes a new transaction to be started if 'uniquekey' is // a column and the value is resolved later. IRowEnumerator rowEnum = result.GetRowEnumerator(); if (rowEnum.MoveNext()) { int rowIndex = rowEnum.RowIndex; for (int c = 0; c < result.ColumnCount; ++c) { result.GetCell(c, rowIndex); } } // If simple enum, note it here resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator); rowEnum = null; // Build 'row_index_map' if not a simple enum if (!resultIsSimpleEnum) { rowIndexMap = new List<int>(result.RowCount); IRowEnumerator en = result.GetRowEnumerator(); while (en.MoveNext()) { rowIndexMap.Add(en.RowIndex); } } // This is a safe operation provides we are shared. // Copy all the TableField columns from the table to our own // QueryResultColumn array, naming each column by what is returned from // the 'GetResolvedVariable' method. int colCount = result.ColumnCount; colDesc = new QueryResultColumn[colCount]; for (int i = 0; i < colCount; ++i) { VariableName v = result.GetResolvedVariable(i); string fieldName; if (v.TableName == null) { // This means the column is an alias fieldName = String.Format("@a{0}", v.Name); } else { // This means the column is an schema/table/column reference fieldName = String.Format("@f{0}", v); } colDesc[i] = new QueryResultColumn(fieldName, result.GetColumnInfo(i)); } locked = 0; }