public void DeleteVersionShouldExecuteDeleteDataExpression()
        {
            var processor = new Mock <IMigrationProcessor>();
            var runner    = new Mock <IMigrationRunner>();

            runner.SetupGet(r => r.Processor).Returns(processor.Object);

            var conventions = new MigrationConventions();
            var asm         = Assembly.GetExecutingAssembly();
            var loader      = new VersionLoader(runner.Object, asm, conventions);

            Func <IDataDefinition, bool> predicate =
                definition =>
            {
                if (definition is ExplicitDataDefinition)
                {
                    IDataValue kvp = ((ExplicitDataDefinition)definition).Data.First();

                    return(kvp.ColumnName == loader.VersionTableMetaData.ColumnName && kvp.Value.Equals(1L));
                }
                else
                {
                    return(false);
                }
            };

            processor.Setup(p => p.Process(It.Is <DeleteDataExpression>(expression =>
                                                                        expression.SchemaName == loader.VersionTableMetaData.SchemaName &&
                                                                        expression.TableName == loader.VersionTableMetaData.TableName &&
                                                                        expression.Rows.All(predicate)))).Verifiable();

            loader.DeleteVersion(1);

            processor.VerifyAll();
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
 private Image LoadImage(string imageExpression)
 {
     try
     {
         using (IDataValue imageData = FrontendSession.Pipe.RequestDocument(imageExpression))
         {
             var    streamCopy = new MemoryStream();
             Stream stream     = imageData.OpenStream();
             try
             {
                 StreamUtility.CopyStream(stream, streamCopy);
             }
             finally
             {
                 stream.Close();
             }
             return(Image.FromStream(streamCopy));
         }
     }
     catch (Exception exception)
     {
         Dataphoria.Warnings.AppendError(this, exception, true);
         // Don't rethrow
     }
     return(null);
 }
 public CombinedVariant([NotNull] IDataValue value, [NotNull] Variable variable,
                        [NotNull] IReadOnlyList <VariableVariant> source, [NotNull] AnalysisContext context)
     : base(variable, context)
 {
     Value   = value ?? throw new ArgumentNullException(nameof(value));
     Storage = new CombinedVariableVariant(source);
 }
        private IDataValue ConditionAssign(IValue right,
                                           [NotNull] AnalysisContext context,
                                           [NotNull] IDataValue oldValue)
        {
            var rightRange = context.ResolveToRange(right);

            switch (right)
            {
            case {} when rightRange != null:
            {
                return(new DataValueInterval(rightRange, oldValue.Constraints));
            }

            case LiteralBase rightLiteral:
            {
                return(new DataValueLiteral(rightLiteral, oldValue.Constraints));
            }

            case IVariantWithStorageVariable rightVariant:
            {
                return(new DataValueLValueRef(rightVariant.StorageVariable,
                                              oldValue.Constraints));
            }
            }

            return(null);
        }
Esempio n. 6
0
        /// <summary>This is a by-reference access of the value, changes made to the resulting DataValue will be refelected in the actual row.</summary>
        public object this[int index]
        {
            get
            {
                                #if USEDATATYPESINNATIVEROW
                if (_row.DataTypes[index] is Schema.IScalarType)
                                #else
                if (DataType.Columns[AIndex].DataType is Schema.IScalarType)
                                #endif
                { return(_row.Values[index]); }
                return(FromNativeRow(Manager, DataType, _row, index));
            }
            set
            {
                if (_row.Values[index] != null)
                                        #if USEDATATYPESINNATIVEROW
                { DataValue.DisposeNative(Manager, _row.DataTypes[index], _row.Values[index]); }
                                        #else
                { DataValue.DisposeNative(Manager, DataType.Columns[AIndex].DataType, FRow.Values[AIndex]); }
                                        #endif

                IDataValue tempValue = value as IDataValue;
                if (tempValue != null)
                {
                                        #if USEDATATYPESINNATIVEROW
                    _row.DataTypes[index] = tempValue.DataType;
                                        #endif
                    _row.Values[index] = tempValue.CopyNative();
                }
                else if (value != null)
                {
                                        #if USEDATATYPESINNATIVEROW
                    if ((DataType.Columns[index].DataType.Equals(Manager.DataTypes.SystemGeneric)) || (DataType.Columns[index].DataType.Equals(Manager.DataTypes.SystemScalar)))
                    {
                        _row.DataTypes[index] = Manager.GetRuntimeType(value.GetType());
                    }
                    else
                    {
                        _row.DataTypes[index] = DataType.Columns[index].DataType;
                    }
                    _row.Values[index] = DataValue.CopyNative(Manager, _row.DataTypes[index], value);
                                        #else
                    FRow.Values[AIndex] = DataValue.CopyNative(Manager, DataType.Columns[AIndex].DataType, value);
                                        #endif
                }
                else
                {
                                        #if USEDATATYPESINNATIVEROW
                    _row.DataTypes[index] = DataType.Columns[index].DataType;
                                        #endif
                    _row.Values[index] = null;
                }

                if (_row.ModifiedFlags != null)
                {
                    _row.ModifiedFlags[index] = true;
                }
            }
        }
Esempio n. 7
0
        public override bool TryGetValue(string key, out IDataValue value)
        {
            TDataValue v;
            var        ret = Dictionary.TryGetValue(key, out v);

            value = v;
            return(ret);
        }
Esempio n. 8
0
        public override bool TryGetValue(string key, out IDataValue value)
        {
            string v;
            var    ret = Dictionary.TryGetValue(key, out v);

            value = CommonExtensions.ToDataValue <TDataValue>(v);
            return(ret);
        }
Esempio n. 9
0
 internal Exemplar(DateTimeOffset timestamp, IDataValue value, ActivityTraceId traceId, ActivitySpanId spanId, KeyValuePair <string, object>[] filteredTags)
 {
     this.Timestamp    = timestamp;
     this.FilteredTags = filteredTags;
     this.SpanId       = spanId;
     this.TraceId      = traceId;
     this.value        = value;
 }
Esempio n. 10
0
 public void Update <T>(T value)
     where T : struct
 {
     lock (this.lockUpdate)
     {
         this.value = new DataValue <T>(value);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Converts an <see cref="IDataValue"/> instance to a contact with a concrete type.
 /// </summary>
 /// <typeparam name="TDataValue">The concrete contact type.</typeparam>
 /// <param name="value">The <see cref="IDataValue"/> to convert</param>
 /// <returns>The converted contact.</returns>
 public static TDataValue ToDataValue <TDataValue>(this IDataValue value)
     where TDataValue : class, IDataValue, new()
 {
     return(value == null
         ? null
         : value as TDataValue ?? new TDataValue {
         Item = value.Item
     });
 }
Esempio n. 12
0
 internal static void checkValuedPropertyValue(IDataValue propValue, DataType expectedType)
 {
     // check the expected values when the property value has an actual value
     Assert.AreEqual(expectedType,
                     propValue.ValueType,
                     string.Format("ValueType should be {0}", Enum.GetName(typeof(DataType), expectedType)));
     Assert.IsNotNull(propValue.Value, "Value should not be null");
     Assert.IsFalse(propValue.IsIndeterminate, "The value should not be indeterminate");
     Assert.IsFalse(propValue.IsVaries, "The value should not vary");
 }
Esempio n. 13
0
 internal static void checkDefaultPropertyValue(IDataValue propValue, DataType expectedType)
 {
     // check the expected default values
     Assert.AreEqual(expectedType,
                     propValue.ValueType,
                     string.Format("ValueType should be {0}", Enum.GetName(typeof(DataType), expectedType)));
     Assert.IsNull(propValue.Value, "Value should be null");
     Assert.IsTrue(propValue.IsIndeterminate, "The value should be indeterminate");
     Assert.IsFalse(propValue.IsVaries, "The value should not vary");
 }
        protected override int compareValue(object obj)
        {
            // handle comparison based on the IDataValue interface
            if (obj is IDataValue)
            {
                IDataValue dataValueObj = obj as IDataValue;
                return(m_value.CompareTo(dataValueObj.AsBoolean()));
            }

            return(m_value.CompareTo(obj));
        }
Esempio n. 15
0
        protected override int compareValue(object obj)
        {
            // handle comparison based on the IDataValue interface
            if (obj is IDataValue)
            {
                IDataValue dataValueObj = obj as IDataValue;
                return(m_value.CompareTo(dataValueObj.AsDouble()));
            }

            // TODO: needs fuzzy equality support
            return(m_value.CompareTo(obj));
        }
 public CombinedItemVariant([NotNull] IDataValue value, [NotNull] Variable arrayStorage,
                            [NotNull] TypeReference typeRef, [NotNull] ValueInterval index,
                            [NotNull] IReadOnlyList <ItemValueVariantBase> source, [NotNull] AnalysisContext context)
     : base(arrayStorage, typeRef, context)
 {
     Index  = index ?? throw new ArgumentNullException(nameof(index));
     Value  = value ?? throw new ArgumentNullException(nameof(value));
     Values = source ?? throw new ArgumentNullException(nameof(source));
     if (source.Count == 0)
     {
         throw new ArgumentException("Value cannot be an empty collection.", nameof(source));
     }
 }
 public IEnumerable <ItemValueVariantBase> this[AnalysisContext context, IDataValue item]
 {
     get
     {
         var range = context.ResolveToRange(item);
         return(this[context, range]);
     }
     set
     {
         var range = context.ResolveToRange(item);
         this[context, range] = value;
     }
 }
Esempio n. 18
0
        public override void WriteToPhysical(byte[] buffer, int offset, bool expandStreams)
        {
            // Write scalar header
            byte header = (byte)(IsNil ? 0 : 1);

            header        |= (byte)(IsNative ? 2 : 0);
            header        |= (byte)(expandStreams ? 4 : 0);
            buffer[offset] = header;
            offset++;

            if (!IsNil)
            {
                if (IsNative)
                {
                    if (DataType.IsCompound)
                    {
                        _writeValue.WriteToPhysical(buffer, offset, expandStreams);
                        _writeValue.Dispose();
                        _writeValue = null;
                    }
                    else
                    {
                        Streams.IConveyor conveyor = Manager.GetConveyor(DataType);
                        if (conveyor.IsStreaming)
                        {
                            _writeStream.Position = 0;
                            _writeStream.Read(buffer, offset, (int)_writeStream.Length);
                            _writeStream.Close();
                        }
                        else
                        {
                            conveyor.Write(Value, buffer, offset);
                        }
                    }
                }
                else
                {
                    if (expandStreams)
                    {
                        _writeStream.Position = 0;
                        _writeStream.Read(buffer, offset, (int)_writeStream.Length);
                        _writeStream.Close();
                    }
                    else
                    {
                        ((StreamID)Value).Write(buffer, offset);
                    }
                }
            }
        }
        private static int ReadResult(StringBuilder LResult, IServerExpressionPlan LPlan)
        {
            int rowCount;

            if (LPlan.DataType is DAE.Schema.ITableType)
            {
                IServerCursor cursor = LPlan.Open(null);
                try
                {
                    rowCount = ResultsFromCursor(cursor, LResult);
                    LResult.Append("\r\n");
                }
                finally
                {
                    LPlan.Close(cursor);
                }
            }
            else
            {
                IDataValue value = LPlan.Evaluate(null);
                rowCount = -1;                 // row count not applicable
                if ((value == null) || value.IsNil)
                {
                    LResult.Append(Strings.Get("NoValue"));
                }
                else
                if (LPlan.DataType is DAE.Schema.IRowType)
                {
                    ResultsFromRow((IRow)value, LResult);
                }
                else if (LPlan.DataType is DAE.Schema.IListType)
                {
                    ResultsFromList((ListValue)value, LResult);
                }
                else if (LPlan.DataType is DAE.Schema.IScalarType)
                {
                    LResult.Append(((IScalar)value).AsDisplayString);
                }
                else
                {
                    LResult.Append(String.Format("<Unknown Result Type: {0}>", LPlan.DataType.Name));
                }
                LResult.Append("\r\n");
            }
            return(rowCount);
        }
Esempio n. 20
0
        public int CompareTo(object obj)
        {
            // check for reference equality first
            if (object.ReferenceEquals(this, obj))
            {
                return(CompareResult.Equal);
            }

            // check for null reference
            if (obj == null)
            {
                return(CompareResult.GreaterThan);
            }

            // handle comparison based on the IDataValue interface
            if (obj is IDataValue)
            {
                IDataValue dataValueObj = obj as IDataValue;

                // first check for the indeterminate state
                if (IsIndeterminate == true)
                {
                    return(dataValueObj.IsIndeterminate ? CompareResult.Equal : CompareResult.LessThan);
                }
                else if (dataValueObj.IsIndeterminate)
                {
                    return(CompareResult.GreaterThan);
                }

                // then check for the varies state
                if (IsVaries == true)
                {
                    return(dataValueObj.IsVaries ? CompareResult.Equal : CompareResult.LessThan);
                }
                else if (dataValueObj.IsVaries)
                {
                    return(CompareResult.GreaterThan);
                }
            }

            // the values are neither indeterminate or varies,
            // so let the subclas to compare the values
            return(compareValue(obj));
        }
Esempio n. 21
0
        public static void DisposeValue(IValueManager manager, object tempValue)
        {
            IDataValue localTempValue = tempValue as IDataValue;

            if (localTempValue != null)
            {
                localTempValue.Dispose();
                return;
            }

            if (tempValue is StreamID)
            {
                manager.StreamManager.Deallocate((StreamID)tempValue);
                return;
            }

            NativeRow nativeRow = tempValue as NativeRow;

            if (nativeRow != null)
            {
                for (int index = 0; index < nativeRow.Values.Length; index++)
                {
                    DisposeValue(manager, nativeRow.Values[index]);
                }
                return;
            }

            NativeList nativeList = tempValue as NativeList;

            if (nativeList != null)
            {
                for (int index = 0; index < nativeList.Values.Count; index++)
                {
                    DisposeValue(manager, nativeList.Values[index]);
                }
            }

            NativeTable nativeTable = tempValue as NativeTable;

            if (nativeTable != null)
            {
                DisposeNative(manager, nativeTable.TableType, nativeTable);
            }
        }
Esempio n. 22
0
        protected override bool EvaluateCondition()
        {
            bool result = false;

            if (Condition != String.Empty)
            {
                DAE.Runtime.DataParams localParamsValue = BaseArgument.CollectArguments(this);
                DAE.IServerProcess     process          = HostNode.Session.DataSession.ServerSession.StartProcess(new DAE.ProcessInfo(HostNode.Session.DataSession.ServerSession.SessionInfo));
                try
                {
                    ErrorList         errors = new ErrorList();
                    DAE.IServerScript script = process.PrepareScript(String.Format("select {0}", Condition));
                    try
                    {
                        DAE.IServerBatch          batch = script.Batches[0];
                        DAE.IServerExpressionPlan plan  = batch.PrepareExpression(localParamsValue);
                        try
                        {
                            errors.AddRange(plan.Messages);
                            using (IDataValue dataValue = plan.Evaluate(localParamsValue))
                                result = dataValue == null ? false : (bool)dataValue.AsNative;
                        }
                        finally
                        {
                            batch.UnprepareExpression(plan);
                        }
                    }
                    finally
                    {
                        process.UnprepareScript(script);
                    }

                    HostNode.Session.ReportErrors(HostNode, errors);
                }
                finally
                {
                    HostNode.Session.DataSession.ServerSession.StopProcess(process);
                }

                BaseArgument.ApplyArguments(this, localParamsValue);
            }
            return(result);
        }
Esempio n. 23
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            IDataValue tempValue = arguments[0] as IDataValue;

            if (tempValue == null)
            {
                tempValue = DataValue.FromNative(program.ValueManager, arguments[0]);
            }

            if (tempValue.IsPhysicalStreaming)
            {
                using (Stream stream = tempValue.OpenStream())
                {
                    return((int)CRC32Utility.GetCRC32(stream));
                }
            }
            else
            {
                byte[] physical = new byte[tempValue.GetPhysicalSize(true)];
                tempValue.WriteToPhysical(physical, 0, true);
                return((int)CRC32Utility.GetCRC32(physical));
            }
        }
Esempio n. 24
0
        private IDataValue _writeValue;      // saves the row instantiated to write the compound value if this is a compound scalar

        public override int GetPhysicalSize(bool expandStreams)
        {
            int size = 1;             // Scalar header

            if (!IsNil)
            {
                if (IsNative)
                {
                    if (DataType.IsCompound)
                    {
                        _writeValue = DataValue.FromNative(Manager, DataType.CompoundRowType, Value);
                        return(size + _writeValue.GetPhysicalSize(expandStreams));
                    }
                    else
                    {
                        Streams.IConveyor conveyor = Manager.GetConveyor(DataType);
                        if (conveyor.IsStreaming)
                        {
                            _writeStream = new MemoryStream(64);
                            conveyor.Write(Value, _writeStream);
                            return(size + (int)_writeStream.Length);
                        }
                        return(size + conveyor.GetSize(Value));
                    }
                }

                if (expandStreams)
                {
                    _writeStream = Manager.StreamManager.Open(StreamID, LockMode.Exclusive);
                    return(size + (int)_writeStream.Length);
                }

                return(size + StreamID.CSizeOf);
            }
            return(size);
        }
Esempio n. 25
0
 public byte[] Evaluate(ref RemoteParamData paramsValue, out ProgramStatistics executeTime, ProcessCallInfo callInfo)
 {
     _process.ProcessCallInfo(callInfo);
     try
     {
         DataParams localParamsValue = _process.RemoteParamDataToDataParams(paramsValue);
         IDataValue tempValue        = ServerExpressionPlan.Evaluate(localParamsValue);
         _process.DataParamsToRemoteParamData(localParamsValue, ref paramsValue);
         executeTime = ServerExpressionPlan.ProgramStatistics;
         if (tempValue == null)
         {
             return(null);
         }
         if (ServerExpressionPlan.DataType.Equivalent(tempValue.DataType))
         {
             return(tempValue.AsPhysical);
         }
         return(tempValue.CopyAs(ServerExpressionPlan.DataType).AsPhysical);
     }
     catch (Exception E)
     {
         throw WrapException(E);
     }
 }
 /// <summary>
 /// Writes <see cref="IDataValue" /> using the provided encoder <see cref="IBinaryEncoder" />.
 /// </summary>
 /// <param name="encoder">The encoder - an object implementing the <see cref="IBinaryEncoder" /> interface.</param>
 /// <param name="value">The value to be encoded.</param>
 public abstract void Write(IBinaryEncoder encoder, IDataValue value);
Esempio n. 27
0
        // Delete
        protected override void InternalExecuteDelete(Program program, IRow row, bool checkConcurrency, bool uncheckedValue)
        {
            base.InternalExecuteDelete(program, row, checkConcurrency, uncheckedValue);

            if (PropagateDelete)
            {
                PushRow(program, row);
                try
                {
                    int columnIndex;
                    for (int index = 1; index < Nodes.Count; index++)
                    {
                        Schema.TableVarColumn column = TableVar.Columns[_extendColumnOffset + index - 1];
                        if (column.ColumnType == Schema.TableVarColumnType.Stored)
                        {
                            columnIndex = row.DataType.Columns.IndexOfName(column.Column.Name);
                            if (columnIndex >= 0)
                            {
                                TableNode tableNode = Nodes[index] as TableNode;
                                if (tableNode == null)
                                {
                                    ExtractRowNode extractRowNode = Nodes[index] as ExtractRowNode;
                                    if (extractRowNode != null)
                                    {
                                        tableNode = (TableNode)extractRowNode.Nodes[0];
                                    }
                                }

                                if (tableNode == null)
                                {
                                    throw new RuntimeException(RuntimeException.Codes.InternalError, "Could not determine update path for extend column.");
                                }

                                IDataValue oldValue = row.GetValue(columnIndex);
                                if (!oldValue.IsNil)
                                {
                                    IRow oldRowValue = oldValue as IRow;
                                    if (oldRowValue != null)
                                    {
                                        tableNode.Delete(program, oldRowValue, checkConcurrency, uncheckedValue);
                                    }
                                    else
                                    {
                                        TableValue oldTableValue = (TableValue)oldValue;
                                        using (ITable oldTableCursor = oldTableValue.OpenCursor())
                                        {
                                            while (oldTableCursor.Next())
                                            {
                                                using (IRow oldTableCursorRow = oldTableCursor.Select())
                                                {
                                                    tableNode.Delete(program, oldTableCursorRow, checkConcurrency, uncheckedValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    PopRow(program);
                }
            }
        }
Esempio n. 28
0
        // Insert
        protected override void InternalExecuteInsert(Program program, IRow oldRow, IRow newRow, BitArray valueFlags, bool uncheckedValue)
        {
            base.InternalExecuteInsert(program, oldRow, newRow, valueFlags, uncheckedValue);

            if (PropagateInsert != PropagateAction.False)
            {
                PushRow(program, newRow);
                try
                {
                    int columnIndex;
                    for (int index = 1; index < Nodes.Count; index++)
                    {
                        Schema.TableVarColumn column = TableVar.Columns[_extendColumnOffset + index - 1];
                        if (column.ColumnType == Schema.TableVarColumnType.Stored)
                        {
                            columnIndex = newRow.DataType.Columns.IndexOfName(column.Column.Name);
                            if (columnIndex >= 0)
                            {
                                TableNode tableNode = Nodes[index] as TableNode;
                                if (tableNode == null)
                                {
                                    ExtractRowNode extractRowNode = Nodes[index] as ExtractRowNode;
                                    if (extractRowNode != null)
                                    {
                                        tableNode = (TableNode)extractRowNode.Nodes[0];
                                    }
                                }

                                if (tableNode == null)
                                {
                                    throw new RuntimeException(RuntimeException.Codes.InternalError, "Could not determine update path for extend column.");
                                }

                                IDataValue newValue = newRow.GetValue(columnIndex);
                                if (!newValue.IsNil)
                                {
                                    IRow newRowValue = newValue as IRow;
                                    if (newRowValue != null)
                                    {
                                        PerformInsert(program, tableNode, null, newRowValue, null, uncheckedValue);
                                    }
                                    else
                                    {
                                        TableValue newTableValue = (TableValue)newValue;
                                        using (ITable newTableCursor = newTableValue.OpenCursor())
                                        {
                                            while (newTableCursor.Next())
                                            {
                                                using (IRow newTableCursorRow = newTableCursor.Select())
                                                {
                                                    PerformInsert(program, tableNode, null, newTableCursorRow, null, uncheckedValue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    PopRow(program);
                }
            }
        }
Esempio n. 29
0
 public void Write(IBinaryEncoder encoder, IDataValue value)
 {
     _encoder.Write(this, value);
 }
Esempio n. 30
0
 public string QuoteDataValue(IDataValue dataValue)
 {
     return dataValue.QuoteValue ? QuoteValue(dataValue.Value) : dataValue.Value.ToString();
 }
 public override void Write(IBinaryEncoder encoder, IDataValue value)
 {
     throw new NotImplementedException();
 }
 public DataKeyValuePair(IDataLiteral name, IDataValue value)
 {
     Key   = name;
     Value = value;
 }