Esempio n. 1
0
        public void SetParameters(VirtuosoParameterCollection parameters)
        {
            this.parameters = parameters;
            if (parameters == null)
            {
                parameterValues = new object[0];
                return;
            }

            parameterValues = new object[parameters.Count];
            for (int i = 0; i < parameters.Count; i++)
            {
                VirtuosoParameter param = (VirtuosoParameter)parameters[i];
                Debug.WriteLineIf(Switch.Enabled, "  param: " + param.paramName);

                object value = null;
                if (param.Direction == ParameterDirection.Input ||
                    param.Direction == ParameterDirection.InputOutput)
                {
                    value = param.Value;
                    if (param.bufferType == null)
                    {
                        if (param.paramType != null)
                        {
                            param.bufferType = param.paramType.bufferType;
                        }
                        else if (value == null || Convert.IsDBNull(value))
                        {
                            param.bufferType = VirtuosoParameter.defaultType.bufferType;
                        }
                        else
                        {
                            param.bufferType = BufferTypes.InferBufferType(value);
                        }
                        if (param.bufferType == null)
                        {
                            throw new InvalidOperationException("Cannot infer parameter type");
                        }
                    }
                    value = param.bufferType.ConvertValue(param.Value);
                }
                Debug.WriteLineIf(Switch.Enabled, "  value: " + param.Value);
                if (value is System.String)
                {
                    BoxTag tag = (param.DbType == DbType.AnsiString ? BoxTag.DV_STRING : BoxTag.DV_WIDE);
                    parameterValues[i] = ExplicitString.CreateExplicitString((String)value, tag, connection);
                }
                else
                {
                    parameterValues[i] = value;
                }
            }
        }
Esempio n. 2
0
        public void GetParameters()
        {
            if (parameters != null && parameters.Count > 0)
            {
                while (GetNextResult())
                {
                    ;
                }
                for (int i = 0; i < parameters.Count; i++)
                {
                    VirtuosoParameter param = (VirtuosoParameter)parameters[i];
                    if (param.Direction == ParameterDirection.ReturnValue ||
                        param.Direction == ParameterDirection.Output ||
                        param.Direction == ParameterDirection.InputOutput)
                    {
                        object data = parameterValues[i];
                        if (param.bufferType == null)
                        {
                            if (param.paramType != null)
                            {
                                param.bufferType = param.paramType.bufferType;
                            }
                            else if (data == null || Convert.IsDBNull(data))
                            {
                                param.bufferType = VirtuosoParameter.defaultType.bufferType;
                            }
                            else
                            {
                                param.bufferType = BufferTypes.InferBufferType(data);
                            }
                            if (param.bufferType == null)
                            {
                                throw new InvalidOperationException("Cannot infer parameter type");
                            }
                        }

                        data            = param.bufferType.ConvertValue(data);
                        param.paramData = data;
                    }
                }
            }
        }
        private void Initialize()
        {
            offset = new int[parameters.Count];
            length = new int[parameters.Count];
            int totalLength = 4 * parameters.Count;

            for (int i = 0; i < parameters.Count; i++)
            {
                VirtuosoParameter param = (VirtuosoParameter)parameters[i];

                object value = param.Value;
                if (param.bufferType == null)
                {
                    if (param.paramType != null)
                    {
                        param.bufferType = param.paramType.bufferType;
                    }
                    else if (value == null || Convert.IsDBNull(value))
                    {
                        param.bufferType = VirtuosoParameter.defaultType.bufferType;
                    }
                    else
                    {
                        param.bufferType = BufferTypes.InferBufferType(value);
                        if (param.bufferType == null)
                        {
                            throw new InvalidOperationException("Cannot infer parameter type");
                        }
                    }
                }
                value = param.bufferType.ConvertValue(value);

                int paramLength = 0;
                if (param.Direction == ParameterDirection.Input)
                {
                    if (value == null || Convert.IsDBNull(value))
                    {
                        continue;
                    }

                    int valueLength = param.bufferType.GetBufferSize(value);
                    if (param.Size == 0)
                    {
                        paramLength = valueLength;
                    }
                    else
                    {
                        paramLength = param.bufferType.GetBufferSize(param.Size);
                        if (paramLength > valueLength)
                        {
                            paramLength = valueLength;
                        }
                    }
                }
                else
                {
                    if (param.Size == 0)
                    {
                        if (!param.bufferType.isFixedSize)
                        {
                            if (param.Direction != ParameterDirection.InputOutput ||
                                value == null || Convert.IsDBNull(value))
                            {
                                throw new InvalidOperationException("Cannot determine the parameter size.");
                            }
                        }
                        paramLength = param.bufferType.GetBufferSize(value);
                    }
                    else
                    {
                        paramLength = param.bufferType.GetBufferSize(param.Size);
                    }
                }

                if (param.bufferType.alignment > 1)
                {
                    totalLength += param.bufferType.alignment - 1;
                    totalLength -= totalLength % param.bufferType.alignment;
                }

                offset[i]    = totalLength;
                length[i]    = paramLength;
                totalLength += paramLength;
            }

            buffer = new MemoryHandle(totalLength);
        }