本文整理汇总了C#中ITable.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ITable.GetValue方法的具体用法?C# ITable.GetValue怎么用?C# ITable.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITable
的用法示例。
在下文中一共展示了ITable.GetValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Result
public static SqlObject[] Result(ITable table)
{
if (!(table is FunctionResultTable))
throw new ArgumentException("The table must be the result of a function execution.", "table");
int cols = table.Columns.Count;
SqlObject[] result = new SqlObject[cols];
for (int i = 0; i < cols; ++i) {
result[i] = table.GetValue(i, new RowId(0));
}
return result;
}
示例2: ToColumns
private static String[] ToColumns(ITable table, IEnumerable<int> cols)
{
var colList = cols.ToList();
int size = colList.Count;
var list = new String[size];
// for each n of the output list
for (int n = 0; n < size; ++n) {
// for each i of the input list
for (int i = 0; i < size; ++i) {
int rowIndex = colList[i];
int seqNo = ((SqlNumber)table.GetValue(rowIndex,2).Value).ToInt32();
if (seqNo == n) {
list[n] = table.GetValue(rowIndex, 1).Value.ToString();
break;
}
}
}
return list;
}
示例3: IsUniqueColumns
private static bool IsUniqueColumns(ITable table, int rindex, string[] cols, bool nullsAllowed)
{
var tableInfo = table.TableInfo;
// 'identical_rows' keeps a tally of the rows that match our added cell.
IList<int> identicalRows = null;
// Resolve the list of column names to column indexes
var colIndexes = tableInfo.IndexOfColumns(cols).ToList();
// If the value being tested for uniqueness contains NULL, we return true
// if nulls are allowed.
if (colIndexes.Select(x => table.GetValue(rindex, x)).Any(x => x.IsNull))
return nullsAllowed;
foreach (var colIndex in colIndexes) {
var value = table.GetValue(rindex, colIndex);
// We are assured of uniqueness if 'identicalRows != null &&
// identicalRows.Count == 0' This is because 'identicalRows' keeps
// a running tally of the rows in the table that contain unique columns
// whose cells match the record being added.
if (identicalRows == null || identicalRows.Count > 0) {
// Ask SelectableScheme to return pointers to row(s) if there is
// already a cell identical to this in the table.
var index = table.GetIndex(colIndex);
var list = index.SelectEqual(value).ToList();
// If 'identical_rows' hasn't been set up yet then set it to 'ivec'
// (the list of rows where there is a cell which is equal to the one
// being added)
// If 'identical_rows' has been set up, then perform an
// 'intersection' operation on the two lists (only keep the numbers
// that are repeated in both lists). Therefore we keep the rows
// that match the row being added.
if (identicalRows == null) {
identicalRows = list;
} else {
list.Sort();
int rowIndex = identicalRows.Count - 1;
while (rowIndex >= 0) {
int val = identicalRows[rowIndex];
int foundIndex = list.BinarySearch(val);
// If we _didn't_ find the index in the array
if (foundIndex < 0 ||
list[foundIndex] != val) {
identicalRows.RemoveAt(rowIndex);
}
--rowIndex;
}
}
}
}
// If there is 1 (the row we added) then we are unique, otherwise we are
// not.
if (identicalRows != null) {
int sz = identicalRows.Count;
if (sz == 1)
return true;
if (sz > 1)
return false;
if (sz == 0)
throw new InvalidOperationException("Assertion failed: We must be able to find the " +
"row we are testing uniqueness against!");
}
return true;
}
示例4: CheckFieldConstraintViolations
public static void CheckFieldConstraintViolations(this ITransaction transaction, ITable table, int[] rowIndices)
{
if (rowIndices == null || rowIndices.Length == 0)
return;
// Check for any bad cells - which are either cells that are 'null' in a
// column declared as 'not null', or duplicated in a column declared as
// unique.
var tableInfo = table.TableInfo;
// Check not-null columns are not null. If they are null, throw an
// error. Additionally check that OBJECT columns are correctly
// typed.
// Check each field of the added rows
int len = tableInfo.ColumnCount;
for (int i = 0; i < len; ++i) {
// Get the column definition and the cell being inserted,
var columnInfo = tableInfo[i];
// For each row added to this column
for (int rn = 0; rn < rowIndices.Length; ++rn) {
var value = table.GetValue(rowIndices[rn], i);
// Check: Column defined as not null and cell being inserted is
// not null.
if (columnInfo.IsNotNull && value.IsNull) {
throw new ConstraintViolationException(
SqlModelErrorCodes.NullableViolation,
"Attempt to set NULL value to column '" +
tableInfo[i].ColumnName +
"' which is declared as NOT NULL");
}
// Check: If column is an object, then deserialize and check the
// object is an instance of the class constraint,
if (!value.IsNull &&
columnInfo.ColumnType.SqlType == SqlTypeCode.Object) {
throw new NotImplementedException(); // TODO:
}
}
}
}
示例5: CopyFrom
public void CopyFrom(ITable table, int row)
{
NewRow();
var columnNames = new ObjectName[table.ColumnCount()];
for (int i = 0; i < columnNames.Length; ++i) {
columnNames[i] = table.GetResolvedColumnName(i);
}
for (int i = 0; i < ColumnCount; ++i) {
var v = GetResolvedColumnName(i);
var colName = v.Name;
try {
int columnOffset = -1;
for (int n = 0; n < columnNames.Length || columnOffset == -1; ++n) {
if (columnNames[n].Name.Equals(colName)) {
columnOffset = n;
}
}
var value = table.GetValue(row, columnOffset);
SetValue(rowCount-1, i, value);
} catch (Exception e) {
throw new InvalidOperationException(e.Message, e);
}
}
}
示例6: CreateValue
private static SqlObject CreateValue(ITable table, RowId rowid, IList<string> columns)
{
int sz = columns.Count;
if (sz == 0)
throw new ArgumentException();
// If there's just 1 column reference, we fetch the TObject and return
// it.
if (sz == 1) {
string columnName = columns[0];
int columnOffset = table.Columns.IndexOf(columnName);
return table.GetValue(columnOffset, rowid);
}
// Otherwise we make a composite object
// Make the composite type
SqlObject[] val = new SqlObject[sz];
for (int i = 0; i < sz; ++i) {
int columnOffset = table.Columns.IndexOf(columns[i]);
val[i] = table.GetValue(columnOffset, rowid);
}
// Create the composite type and return the object
return SqlObject.MakeComposite(val);
}
示例7: SelectIntoTable
private void SelectIntoTable(IMutableTable table, ITable result)
{
if (!AreCompatible(table.TableInfo, result.TableInfo))
throw new InvalidOperationException();
for (int i = 0; i < result.RowCount; i++) {
var newRow = table.NewRow();
for (int j = 0; j < result.ColumnCount(); j++) {
var value = result.GetValue(i, j);
newRow.SetValue(j, value);
}
table.AddRow(newRow);
}
}
示例8: 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;
}
示例9: Construct
public object Construct(ITable table, int rowOffset)
{
var obj = Activator.CreateInstance(ElementType, true);
var members = ElementType.FindMembers(MemberTypes.Field | MemberTypes.Property,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, FilterColumns, null);
foreach (var member in members) {
string columnName;
if (!memberMapping.TryGetValue(member.Name, out columnName))
continue;
int offset;
if (!columnOffsets.TryGetValue(columnName, out offset))
continue;
Type memberType;
if (member is PropertyInfo) {
memberType = ((PropertyInfo) member).PropertyType;
} else {
memberType = ((FieldInfo) member).FieldType;
}
var value = table.GetValue(rowOffset, offset);
var finalValue = ToMemberValue(value, memberType);
if (member is PropertyInfo) {
((PropertyInfo)member).SetValue(obj, finalValue, null);
} else {
((FieldInfo)member).SetValue(obj, finalValue);
}
}
return obj;
}
示例10: 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]);
}
}