/// <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); }
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); }
/// <summary>Returns the host representation of the given physical value.</summary> public static IDataValue FromPhysical(IValueManager manager, Schema.IDataType dataType, byte[] buffer, int offset) { Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { Scalar scalar = new Scalar(manager, scalarType, null); scalar.ReadFromPhysical(buffer, offset); return(scalar); } Schema.IRowType rowType = dataType as Schema.IRowType; if (rowType != null) { Row row = new Row(manager, rowType); row.ReadFromPhysical(buffer, offset); return(row); } Schema.IListType listType = dataType as Schema.IListType; if (listType != null) { ListValue list = new ListValue(manager, listType); list.ReadFromPhysical(buffer, offset); return(list); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { TableValue table = new TableValue(manager, tableType, null); table.ReadFromPhysical(buffer, offset); return(table); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { CursorValue cursor = new CursorValue(manager, cursorType, -1); cursor.ReadFromPhysical(buffer, offset); return(cursor); } 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); }
/// <summary>Copies the native representation of this value and returns the host representation as the given type.</summary> public IDataValue CopyAs(Schema.IDataType dataType) { // This code is duplicated in the Copy and FromNative methods for performance... object tempValue = CopyNativeAs(dataType); Schema.IScalarType scalarType = dataType as Schema.IScalarType; if (scalarType != null) { if (tempValue is StreamID) { Scalar scalar = new Scalar(Manager, scalarType, (StreamID)tempValue); scalar.ValuesOwned = true; return(scalar); } return(new Scalar(Manager, scalarType, tempValue)); } Schema.IRowType rowType = dataType as Schema.IRowType; if (rowType != null) { Row row = new Row(Manager, rowType, (NativeRow)tempValue); row.ValuesOwned = true; return(row); } Schema.IListType listType = dataType as Schema.IListType; if (listType != null) { ListValue list = new ListValue(Manager, listType, (NativeList)tempValue); list.ValuesOwned = true; return(list); } Schema.ITableType tableType = dataType as Schema.ITableType; if (tableType != null) { TableValue table = new TableValue(Manager, tableType, (NativeTable)tempValue); table.ValuesOwned = true; return(table); } Schema.ICursorType cursorType = dataType as Schema.ICursorType; if (cursorType != null) { return(new CursorValue(Manager, cursorType, (int)tempValue)); } throw new RuntimeException(RuntimeException.Codes.InvalidValueType, dataType == null ? "<null>" : dataType.GetType().Name); }