/// <summary>Returns the host representation of the given native value. This is a by-reference operation.</summary> public static IDataValue FromNative(IValueManager manager, Schema.IDataType dataType, object tempValue) { // This code is duplicated in the Copy method and the FromNative overloads for performance Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { if (tempValue is StreamID) { return(new Scalar(manager, scalarType, (StreamID)tempValue)); } if (scalarType.IsGeneric) { return(new Scalar(manager, (Schema.ScalarType)manager.GetRuntimeType(tempValue.GetType()), tempValue)); } return(new Scalar(manager, scalarType, tempValue)); } if (tempValue == null) { return(null); } Schema.IRowType rowType = dataType as Schema.IRowType; if (rowType != null) { return(new Row(manager, rowType, (NativeRow)tempValue)); } Schema.IListType listType = dataType as Schema.IListType; if (listType != null) { return(new ListValue(manager, listType, (NativeList)tempValue)); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { return(new TableValue(manager, tableType, (NativeTable)tempValue)); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { return(new CursorValue(manager, cursorType, (int)tempValue)); } var runtimeType = manager.GetRuntimeType(tempValue); if (runtimeType != null) { return(FromNative(manager, runtimeType, tempValue)); } throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name); }
/// <summary>Returns the host representation of the given native value. This is a by-reference operation.</summary> public static IDataValue FromNativeRow(IValueManager manager, Schema.IRowType rowType, NativeRow nativeRow, int nativeRowIndex) { // This code is duplicated in the Copy method and the FromNative overloads for performance #if USEDATATYPESINNATIVEROW Schema.IDataType dataType = nativeRow.DataTypes[nativeRowIndex]; if (dataType == null) { dataType = rowType.Columns[nativeRowIndex].DataType; } #else Schema.IDataType dataType = ARowType.Columns[ANativeRowIndex].DataType; #endif Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { return(new RowInternedScalar(manager, scalarType, nativeRow, nativeRowIndex)); } Schema.IRowType localRowType = dataType as Schema.IRowType; if (localRowType != null) { return(new Row(manager, localRowType, (NativeRow)nativeRow.Values[nativeRowIndex])); } Schema.IListType listType = dataType as Schema.IListType; if (listType != null) { return(new ListValue(manager, listType, (NativeList)nativeRow.Values[nativeRowIndex])); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { return(new TableValue(manager, tableType, (NativeTable)nativeRow.Values[nativeRowIndex])); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { return(new CursorValue(manager, cursorType, (int)nativeRow.Values[nativeRowIndex])); } var runtimeType = manager.GetRuntimeType(nativeRow.Values[nativeRowIndex]); if (runtimeType != null) { return(new RowInternedScalar(manager, (Schema.IScalarType)runtimeType, nativeRow, nativeRowIndex)); } throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name); }
public static IDataValue FromNative(IValueManager manager, object tempValue) { if (tempValue == null) { return(new Scalar(manager, manager.DataTypes.SystemScalar, null)); } if (tempValue is StreamID) { return(new Scalar(manager, manager.DataTypes.SystemScalar, (StreamID)tempValue)); } return(new Scalar(manager, (Schema.ScalarType)manager.GetRuntimeType(tempValue.GetType()), tempValue)); }
/// <summary>Returns the host representation of the given native value. This is a by-reference operation.</summary> public static IDataValue FromNativeList(IValueManager manager, Schema.IListType listType, NativeList nativeList, int nativeListIndex) { // This code is duplicated in the Copy method and the FromNative overloads for performance Schema.IDataType dataType = nativeList.DataTypes[nativeListIndex]; if (dataType == null) { dataType = listType.ElementType; } Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { return(new ListInternedScalar(manager, scalarType, nativeList, nativeListIndex)); } Schema.IRowType rowType = dataType as Schema.IRowType; if (rowType != null) { return(new Row(manager, rowType, (NativeRow)nativeList.Values[nativeListIndex])); } Schema.IListType localListType = dataType as Schema.IListType; if (localListType != null) { return(new ListValue(manager, localListType, (NativeList)nativeList.Values[nativeListIndex])); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { return(new TableValue(manager, tableType, (NativeTable)nativeList.Values[nativeListIndex])); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { return(new CursorValue(manager, cursorType, (int)nativeList.Values[nativeListIndex])); } var runtimeType = manager.GetRuntimeType(nativeList.Values[nativeListIndex]); if (runtimeType != null) { return(new ListInternedScalar(manager, (Schema.IScalarType)runtimeType, nativeList, nativeListIndex)); } throw new RuntimeException(RuntimeException.Codes.InvalidValueType, nativeList.DataTypes[nativeListIndex] == null ? "<null>" : nativeList.DataTypes[nativeListIndex].GetType().Name); }
public static object CopyNative(IValueManager manager, Schema.IDataType dataType, object tempValue) { // This code is duplicated in the descendent CopyNative methods for performance if (tempValue == null) { return(tempValue); } Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { if (tempValue is StreamID) { return(manager.StreamManager.Reference((StreamID)tempValue)); } ICloneable cloneable = tempValue as ICloneable; if (cloneable != null) { return(cloneable.Clone()); } if (scalarType.IsCompound) { return(CopyNative(manager, scalarType.CompoundRowType, tempValue)); } return(tempValue); } Schema.IRowType rowType = dataType as Schema.IRowType; if (rowType != null) { NativeRow nativeRow = (NativeRow)tempValue; NativeRow newRow = new NativeRow(rowType.Columns.Count); for (int index = 0; index < rowType.Columns.Count; index++) { #if USEDATATYPESINNATIVEROW newRow.DataTypes[index] = nativeRow.DataTypes[index]; newRow.Values[index] = CopyNative(manager, nativeRow.DataTypes[index], nativeRow.Values[index]); #else newRow.Values[index] = CopyNative(AManager, rowType.Columns[index].DataType, nativeRow.Values[index]); #endif } return(newRow); } Schema.IListType listType = dataType as Schema.IListType; if (listType != null) { NativeList nativeList = (NativeList)tempValue; NativeList newList = new NativeList(); for (int index = 0; index < nativeList.DataTypes.Count; index++) { newList.DataTypes.Add(nativeList.DataTypes[index]); newList.Values.Add(CopyNative(manager, nativeList.DataTypes[index], nativeList.Values[index])); } return(newList); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { NativeTable nativeTable = (NativeTable)tempValue; NativeTable newTable = new NativeTable(manager, nativeTable.TableVar); using (Scan scan = new Scan(manager, nativeTable, nativeTable.ClusteredIndex, ScanDirection.Forward, null, null)) { scan.Open(); while (scan.Next()) { using (IRow row = scan.GetRow()) { newTable.Insert(manager, row); } } } return(newTable); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { return(tempValue); } var runtimeType = manager.GetRuntimeType(tempValue); if (runtimeType != null) { return(CopyNative(manager, runtimeType, tempValue)); } throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name); }