예제 #1
4
        /// <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);
        }
예제 #2
0
 public NativeRow(int columnCount) : base()
 {
                 #if USEDATATYPESINNATIVEROW
     _dataTypes = new Schema.IDataType[columnCount];
                 #endif
     _values = new object[columnCount];
 }
예제 #3
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            // We need to construct a new TableVar here because otherwise the native table
            // will be constructed with the keys inferred for the source, resulting in
            // incorrect access plans (see Defect #33978 for more).
            Schema.ResultTableVar tableVar = new Schema.ResultTableVar(Node);
            tableVar.Owner = Program.Plan.User;
            tableVar.EnsureTableVarColumns();
            Program.EnsureKey(tableVar);

            if (!Active)
            {
                Open();
            }
            else
            {
                Reset();
            }

            NativeTable nativeTable = new NativeTable(Manager, tableVar);

            while (Next())
            {
                using (IRow row = Select())
                {
                    nativeTable.Insert(Manager, row);
                }
            }

            return(nativeTable);
        }
예제 #4
0
 public Symbol(string AName, Schema.IDataType ADataType)
 {
     FName       = AName;
     FDataType   = ADataType;
     FIsConstant = false;
     FIsModified = false;
 }
예제 #5
0
        /// <summary>Disposes the given native value.</summary>
        public static void DisposeNative(IValueManager manager, Schema.IDataType dataType, object tempValue)
        {
            if (tempValue == null)
            {
                return;
            }

            Schema.IScalarType scalarType = dataType as Schema.IScalarType;
            if (scalarType != null)
            {
                if (tempValue is StreamID)
                {
                    manager.StreamManager.Deallocate((StreamID)tempValue);
                }

                if (scalarType.IsCompound)
                {
                    DisposeNative(manager, scalarType.CompoundRowType, tempValue);
                }

                return;
            }

            using (IDataValue dataValue = DataValue.FromNative(manager, dataType, tempValue))
            {
                dataValue.ValuesOwned = true;
            }
        }
예제 #6
0
 public DataParam(string name, Schema.IDataType dataType, Modifier modifier, object tempValue)
 {
     Name     = name;
     DataType = dataType;
     Value    = tempValue;
     Modifier = modifier;
 }
예제 #7
0
 public Symbol(string AName, Schema.IDataType ADataType, bool AIsConstant, bool AIsModified)
 {
     FName       = AName;
     FDataType   = ADataType;
     FIsConstant = AIsConstant;
     FIsModified = AIsModified;
 }
예제 #8
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            NativeList newList = new NativeList();

            for (int index = 0; index < _list.DataTypes.Count; index++)
            {
                newList.DataTypes.Add(_list.DataTypes[index]);
                newList.Values.Add(DataValue.CopyNative(Manager, _list.DataTypes[index], _list.Values[index]));
            }
            return(newList);
        }
예제 #9
0
 public void Dispose()
 {
     if (_manager != null)
     {
                         #if USEFINALIZER
         System.GC.SuppressFinalize(this);
                         #endif
         Dispose(true);
         _manager  = null;
         _dataType = null;
     }
 }
예제 #10
0
        /// <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);
        }
예제 #11
0
        /// <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);
        }
예제 #12
0
        /// <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);
        }
예제 #13
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            NativeTable newTable = new NativeTable(Manager, _table.TableVar);

            using (Scan scan = new Scan(Manager, _table, _table.ClusteredIndex, ScanDirection.Forward, null, null))
            {
                scan.Open();
                while (scan.Next())
                {
                    using (IRow row = scan.GetRow())
                    {
                        newTable.Insert(Manager, row);
                    }
                }
            }
            return(newTable);
        }
예제 #14
0
        /// <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);
        }
예제 #15
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            if (_row == null)
            {
                return(null);
            }

            if (Object.ReferenceEquals(DataType, dataType))
            {
                NativeRow newRow = new NativeRow(DataType.Columns.Count);
                if (_row != null)
                {
                    for (int index = 0; index < DataType.Columns.Count; index++)
                    {
                                                #if USEDATATYPESINNATIVEROW
                        newRow.DataTypes[index] = _row.DataTypes[index];
                        newRow.Values[index]    = CopyNative(Manager, _row.DataTypes[index], _row.Values[index]);
                                                #else
                        newRow.Values[index] = CopyNative(Manager, DataType.Columns[index].DataType, FRow.Values[index]);
                                                #endif
                    }
                }
                return(newRow);
            }
            else
            {
                NativeRow newRow           = new NativeRow(DataType.Columns.Count);
                Schema.IRowType newRowType = (Schema.IRowType)dataType;
                if (_row != null)
                {
                    for (int index = 0; index < DataType.Columns.Count; index++)
                    {
                        int newIndex = newRowType.Columns.IndexOfName(DataType.Columns[index].Name);
                                                #if USEDATATYPESINNATIVEROW
                        newRow.DataTypes[newIndex] = _row.DataTypes[index];
                        newRow.Values[newIndex]    = CopyNative(Manager, _row.DataTypes[index], _row.Values[index]);
                                                #else
                        newRow.Values[newIndex] = CopyNative(Manager, DataType.Columns[index].DataType, FRow.Values[index]);
                                                #endif
                    }
                }
                return(newRow);
            }
        }
예제 #16
0
 internal static object InternalCopy(Program program, Schema.IDataType dataType, TableNode sourceTable, TableNode targetTable, string keyColumnNames, bool insertOnly)
 {
     return
         (IntegrationHelper.Copy
          (
              program,
              sourceTable,
              targetTable,
              delegate(TableNode ASourceTableInner, TableNode ATargetTableInner, Expression ATargetExpression)
     {
         return
         IntegrationHelper.GenerateConditionedInsertStatement
         (
             program,
             ASourceTableInner,
             ATargetTableInner,
             ATargetExpression,
             insertOnly,
             keyColumnNames
         );
     }
          ));
 }
예제 #17
0
        public override object CopyNativeAs(Schema.IDataType dataType)
        {
            if (IsNative)
            {
                ICloneable cloneable = Value as ICloneable;
                if (cloneable != null)
                {
                    return(cloneable.Clone());
                }

                if (DataType.IsCompound)
                {
                    return(DataValue.CopyNative(Manager, DataType.CompoundRowType, Value));
                }

                return(Value);
            }

            if (StreamID == StreamID.Null)
            {
                return(StreamID);
            }
            return(Manager.StreamManager.Reference(StreamID));
        }
예제 #18
0
 public DataParam(string name, Schema.IDataType dataType, Modifier modifier)
 {
     Name     = name;
     DataType = dataType;
     Modifier = modifier;
 }
예제 #19
0
 public Schema.Sort GetUniqueSort(Schema.IDataType type)
 {
     return(Compiler.GetUniqueSort(_plan, type));
 }
예제 #20
0
 public DataValue(IValueManager manager, Schema.IDataType dataType) : base()
 {
     _manager  = manager;
     _dataType = dataType;
 }
예제 #21
0
 public Schema.Sort GetEqualitySort(Schema.IDataType type)
 {
     return(Compiler.GetEqualitySort(_plan, type));
 }
예제 #22
0
        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);
        }
예제 #23
0
 public void Add(Schema.IDataType dataType)
 {
     _dataTypes.Add(dataType);
 }
예제 #24
0
        /// <summary>
        /// Converts the C# host representation of a value to the "Native" representation (using NativeLists, NativeRows, and NativeTables)
        /// </summary>
        /// <param name="dataType">The target data type for the conversion.</param>
        /// <param name="value">The source value to be converted.</param>
        /// <returns>The value in its "Native" representation.</returns>
        public static object ToNativeOf(IValueManager valueManager, Schema.IDataType dataType, object value)
        {
            if (value != null)
            {
                var scalarType = dataType as Schema.IScalarType;
                if (scalarType != null)
                {
                    if (scalarType.Equals(valueManager.DataTypes.SystemString) && !(value is String))
                    {
                        return(value.ToString());                        // The usual scenario would be an enumerated type...
                    }
                    if (scalarType.Equals(valueManager.DataTypes.SystemDateTime) && value is DateTimeOffset)
                    {
                        return(new DateTime(((DateTimeOffset)value).Ticks));
                    }

                    return(value);                    // Otherwise, return the C# representation directly
                }

                var listType = dataType as Schema.IListType;
                if (listType != null && value != null)
                {
                    var listValue = value as ListValue;
                    if (listValue != null)
                    {
                        return(listValue);
                    }

                    var nativeList = value as NativeList;
                    if (nativeList != null)
                    {
                        return(nativeList);
                    }

                    var iList = value as IList;
                    if (iList != null)
                    {
                        var newList = new NativeList();
                        for (int index = 0; index < iList.Count; index++)
                        {
                            newList.DataTypes.Add(listType.ElementType);
                            newList.Values.Add(ToNativeOf(valueManager, listType.ElementType, iList[index]));
                        }

                        return(newList);
                    }

                    throw new RuntimeException(RuntimeException.Codes.InternalError, String.Format("Unexpected type for property: {0}", value.GetType().FullName));
                }

                var tableType = dataType as Schema.ITableType;
                if (tableType != null && value != null)
                {
                    var tableValue = value as TableValue;
                    if (tableValue != null)
                    {
                        return(tableValue);
                    }

                    var nativeTable = value as NativeTable;
                    if (nativeTable != null)
                    {
                        return(nativeTable);
                    }

                    var iDictionary = value as IDictionary;
                    if (iDictionary != null)
                    {
                        var newTableVar = new Schema.BaseTableVar(tableType);
                        newTableVar.EnsureTableVarColumns();
                        // Assume the first column is the key, this is potentially problematic, but without key information in table types, not much else we can do....
                        // The assumption here is that the C# representation of a "table" is a dictionary
                        newTableVar.Keys.Add(new Schema.Key(new Schema.TableVarColumn[] { newTableVar.Columns[0] }));
                        var newTable = new NativeTable(valueManager, newTableVar);
                        foreach (DictionaryEntry entry in iDictionary)
                        {
                            using (Row row = new Row(valueManager, newTableVar.DataType.RowType))
                            {
                                row[0] = ToNativeOf(valueManager, tableType.Columns[0].DataType, entry.Key);
                                row[1] = ToNativeOf(valueManager, tableType.Columns[1].DataType, entry.Value);
                                newTable.Insert(valueManager, row);
                            }
                        }

                        return(newTable);
                    }

                    throw new RuntimeException(RuntimeException.Codes.InternalError, String.Format("Unexpected type for property: {0}", value.GetType().FullName));
                }
            }

            return(value);
        }
예제 #25
0
 public abstract object CopyNativeAs(Schema.IDataType dataType);
예제 #26
0
 public void PushTypeContext(Schema.IDataType dataType)
 {
     _typeStack.Push(dataType);
 }
예제 #27
0
 public void PopTypeContext(Schema.IDataType dataType)
 {
     Error.AssertFail(_typeStack.Count > 0, "Type stack underflow");
     _typeStack.Pop();
 }
예제 #28
0
 public override object CopyNativeAs(Schema.IDataType dataType)
 {
     return(_iD);
 }
예제 #29
0
 public void Insert(int index, Schema.IDataType dataType)
 {
     _dataTypes.Insert(index, dataType);
 }