本文整理汇总了C#中ITable.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# ITable.GetEnumerator方法的具体用法?C# ITable.GetEnumerator怎么用?C# ITable.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITable
的用法示例。
在下文中一共展示了ITable.GetEnumerator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public static int Delete(this IMutableTable table, ITable other, int limit)
{
List<int> rowSet = new List<int>(other.RowCount);
var e = other.GetEnumerator();
while (e.MoveNext()) {
rowSet.Add(e.Current.RowId.RowNumber);
}
// HACKY: Find the first column of this table in the search table. This
// will allow us to generate a row set of only the rows in the search
// table.
int firstColumn = other.IndexOfColumn(table.GetResolvedColumnName(0));
if (firstColumn == -1)
throw new DatabaseSystemException("Search table does not contain any reference to table being deleted from");
// Generate a row set that is in this tables domain.
var rowsToDelete = other.ResolveRows(firstColumn, rowSet, table).ToList();
// row_set may contain duplicate row indices, therefore we must sort so
// any duplicates are grouped and therefore easier to find.
rowSet.Sort();
// If limit less than zero then limit is whole set.
if (limit < 0)
limit = Int32.MaxValue;
// Remove each row in row set in turn. Make sure we don't remove the
// same row index twice.
int len = System.Math.Min(rowsToDelete.Count, limit);
int lastRemoved = -1;
int removeCount = 0;
for (int i = 0; i < len; ++i) {
int toRemove = rowsToDelete[i];
if (toRemove < lastRemoved)
throw new DatabaseSystemException("Internal error: row sorting error or row set not in the range > 0");
if (toRemove != lastRemoved) {
table.RemoveRow(toRemove);
lastRemoved = toRemove;
++removeCount;
}
}
if (removeCount > 0)
// Perform a referential integrity check on any changes to the table.
table.AssertConstraints();
return removeCount;
}
示例2: NaturallyJoinedTable
public NaturallyJoinedTable(ITable left, ITable right)
: base(new[] {left, right})
{
leftRowCount = left.RowCount;
rightRowCount = right.RowCount;
// Build lookup tables for the rows in the parent tables if necessary
// (usually it's not necessary).
// If the left or right tables are simple enumerations, we can optimize
// our access procedure,
leftIsSimpleEnum = (left.GetEnumerator() is SimpleRowEnumerator);
rightIsSimpleEnum = (right.GetEnumerator() is SimpleRowEnumerator);
leftSet = !leftIsSimpleEnum ? left.Select(x => x.RowId.RowNumber).ToList() : null;
rightSet = !rightIsSimpleEnum ? right.Select(x => x.RowId.RowNumber).ToList() : null;
}
示例3: Update
public static int Update(this IMutableTable mutableTable, IQueryContext context, ITable table,
IEnumerable<SqlAssignExpression> assignList, int limit)
{
// Get the rows from the input table.
var rowSet = new List<int>();
var e = table.GetEnumerator();
while (e.MoveNext()) {
rowSet.Add(e.Current.RowId.RowNumber);
}
// HACKY: Find the first column of this table in the search table. This
// will allow us to generate a row set of only the rows in the search
// table.
int firstColumn = table.FindColumn(mutableTable.GetResolvedColumnName(0));
if (firstColumn == -1)
throw new InvalidOperationException("Search table does not contain any " +
"reference to table being updated from");
// Convert the row_set to this table's domain.
rowSet = table.ResolveRows(firstColumn, rowSet, mutableTable).ToList();
// NOTE: Assume there's no duplicate rows.
// If limit less than zero then limit is whole set.
if (limit < 0)
limit = Int32.MaxValue;
// Update each row in row set in turn up to the limit.
int len = System.Math.Min(rowSet.Count, limit);
int updateCount = 0;
for (int i = 0; i < len; ++i) {
int toUpdate = rowSet[i];
// Make a row object from this row (plus keep the original intact
// in case we need to roll back to it).
var row = mutableTable.GetRow(toUpdate);
row.SetFromTable();
// Run each assignment on the row.
foreach (var assignment in assignList) {
row.EvaluateAssignment(assignment, context);
}
// Update the row
mutableTable.UpdateRow(row);
++updateCount;
}
if (updateCount > 0)
// Perform a referential integrity check on any changes to the table.
mutableTable.AssertConstraints();
return updateCount;
}
示例4: SimpleJoin
public static ITable SimpleJoin(this ITable thisTable, IQueryContext context, ITable other, SqlBinaryExpression binary)
{
var objRef = binary.Left as SqlReferenceExpression;
if (objRef == null)
throw new ArgumentException();
// Find the row with the name given in the condition.
int lhsColumn = thisTable.FindColumn(objRef.ReferenceName);
if (lhsColumn == -1)
throw new Exception("Unable to find the LHS column specified in the condition: " + objRef.ReferenceName);
// Create a variable resolver that can resolve columns in the destination
// table.
var resolver = other.GetVariableResolver();
// The join algorithm. It steps through the RHS expression, selecting the
// cells that match the relation from the LHS table (this table).
var thisRowSet = new List<int>();
var tableRowSet = new List<int>();
var e = other.GetEnumerator();
while (e.MoveNext()) {
int rowIndex = e.Current.RowId.RowNumber;
// Select all the rows in this table that match the joining condition.
var selectedSet = thisTable.SelectRows(resolver, context, binary);
var selectList = selectedSet.ToList();
var size = selectList.Count;
// Include in the set.
for (int i = 0; i < size; i++) {
tableRowSet.Add(rowIndex);
}
thisRowSet.AddRange(selectList);
}
// Create the new VirtualTable with the joined tables.
var tabs = new[] {thisTable, other};
var rowSets = new IList<int>[] {thisRowSet, tableRowSet};
return new VirtualTable(tabs, rowSets);
}
示例5: SelectRowsNotIn
/// <summary>
/// This implements the <c>not in</c> command.
/// </summary>
/// <param name="table"></param>
/// <param name="other"></param>
/// <param name="col1"></param>
/// <param name="col2"></param>
/// <remarks>
/// <b>Issue</b>: This will be less efficient than <see cref="SelectRowsIn(ITable,ITable,int,int)">in</see>
/// if <paramref name="table"/> has many rows and <paramref name="other"/> has few rows.
/// </remarks>
/// <returns></returns>
public static IEnumerable<int> SelectRowsNotIn(this ITable table, ITable other, int col1, int col2)
{
// Handle trivial cases
int t2RowCount = other.RowCount;
if (t2RowCount == 0)
// No rows so include all rows.
return table.SelectAllRows(col1);
if (t2RowCount == 1) {
// 1 row so select all from table1 that doesn't equal the value.
var en = other.GetEnumerator();
if (!en.MoveNext())
throw new InvalidOperationException("Cannot iterate through table rows.");
var cell = other.GetValue(en.Current.RowId.RowNumber, col2);
return table.SelectRows(col1, SqlExpressionType.NotEqual, cell);
}
// Iterate through table1's column. If we can find identical cell in the
// tables's column, then we should not include the row in our final
// result.
List<int> resultRows = new List<int>();
foreach (var row in table) {
int rowIndex = row.RowId.RowNumber;
var cell = row.GetValue(col1);
var selectedSet = other.SelectRows(col2, SqlExpressionType.Equal, cell);
// We've found a row in table1 that doesn't have an identical cell in
// other, so we should include it in the result.
if (!selectedSet.Any())
resultRows.Add(rowIndex);
}
return resultRows;
}
示例6: FormColumns
private void FormColumns(ITable result)
{
// 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.
var columnCount = result.TableInfo.ColumnCount;
using (var rowEnum = result.GetEnumerator()) {
if (rowEnum.MoveNext()) {
int rowIndex = rowEnum.Current.RowId.RowNumber;
for (int c = 0; c < columnCount; ++c) {
result.GetValue(rowIndex, c);
}
}
// If simple enum, note it here
resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
}
// Build 'row_index_map' if not a simple enum
if (!resultIsSimpleEnum) {
rowIndexMap = new List<int>(result.RowCount);
var en = result.GetEnumerator();
while (en.MoveNext()) {
rowIndexMap.Add(en.Current.RowId.RowNumber);
}
}
// 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.TableInfo.ColumnCount;
columns = new QueryResultColumn[colCount];
for (int i = 0; i < colCount; ++i) {
var v = result.GetResolvedColumnName(i);
string fieldName;
if (v.ParentName == 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);
}
columns[i] = new QueryResultColumn(fieldName, result.TableInfo[i]);
}
}