public static IEnumerable <object> ServerCursorToValue(IServerProcess process, IServerCursor cursor) { NativeTableValue nativeTable = NativeMarshal.TableVarToNativeTableValue(process, cursor.Plan.TableVar); var table = new List <object>(); IRow currentRow = cursor.Plan.RequestRow(); try { bool[] valueTypes = new bool[nativeTable.Columns.Length]; for (int index = 0; index < nativeTable.Columns.Length; index++) { valueTypes[index] = currentRow.DataType.Columns[index].DataType is IScalarType; } while (cursor.Next()) { cursor.Select(currentRow); var row = new Dictionary <string, object>(); for (int index = 0; index < nativeTable.Columns.Length; index++) { if (valueTypes[index]) { row.Add(nativeTable.Columns[index].Name, currentRow[index]); } else { row.Add(nativeTable.Columns[index].Name, DataValueToValue(process, currentRow.GetValue(index))); } } table.Add(row); } } finally { cursor.Plan.ReleaseRow(currentRow); } return(table); }
public static object DataValueToValue(IServerProcess process, IDataValue dataValue) { if (dataValue == null) { return(null); } IScalar scalar = dataValue as IScalar; if (scalar != null) { return(ScalarTypeNameToValue(dataValue.DataType.Name, scalar)); } ListValue list = dataValue as ListValue; if (list != null) { var listValue = new List <object>(); if (!list.IsNil) { for (int index = 0; index < list.Count(); index++) { listValue.Add(DataValueToValue(process, list.GetValue(index))); } } return(listValue); } IRow row = dataValue as IRow; if (row != null) { var rowValue = new Dictionary <string, object>(); if (!row.IsNil) { for (int index = 0; index < row.DataType.Columns.Count; index++) { var data = row.GetValue(index); data.DataType.Name = NativeMarshal.DataTypeToDataTypeName(process.DataTypes, row.DataType.Columns[index].DataType); rowValue.Add(row.DataType.Columns[index].Name, DataValueToValue(process, data)); } } return(rowValue); } TableValue tableValue = dataValue as TableValue; TableValueScan scan = null; try { if (tableValue != null) { scan = new TableValueScan(tableValue); scan.Open(); dataValue = scan; } ITable table = dataValue as ITable; if (table != null) { var nativeTable = new NativeTableValue(); var resultTable = new List <object>(); if (!table.BOF()) { table.First(); } bool[] valueTypes = new bool[table.DataType.Columns.Count]; for (int index = 0; index < table.DataType.Columns.Count; index++) { valueTypes[index] = table.DataType.Columns[index].DataType is IScalarType; } while (table.Next()) { using (IRow currentRow = table.Select()) { object[] nativeRow = new object[table.DataType.Columns.Count]; for (int index = 0; index < table.DataType.Columns.Count; index++) { if (valueTypes[index]) { resultTable.Add(currentRow[index]); } else { resultTable.Add(DataValueToValue(process, currentRow.GetValue(index))); } } } } return(resultTable); } } finally { if (scan != null) { scan.Dispose(); } } throw new NotSupportedException(string.Format("Values of type \"{0}\" are not supported.", dataValue.DataType.Name)); }