Exemple #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;
                }
            }
        }
Exemple #2
0
        internal static object UnmarshalBlobHandle(Stream stream, BoxTag tag)
        {
            int    ask       = UnmarshalLongInt(stream);
            int    page      = UnmarshalLongInt(stream);
            int    length    = UnmarshalLongInt(stream);
            int    keyId     = UnmarshalLongInt(stream);
            int    fragNo    = UnmarshalLongInt(stream);
            int    dirPage   = UnmarshalLongInt(stream);
            int    timeStamp = UnmarshalLongInt(stream);
            object pages     = Unmarshal(stream, null);

            return(new BlobHandle(ask, page, length, keyId, fragNo, dirPage, timeStamp, pages, tag));
        }
Exemple #3
0
        internal static IMarshal CreateExplicitString(string s, BoxTag tag, ManagedConnection connection)
        {
            switch (tag)
            {
            case BoxTag.DV_WIDE:
            case BoxTag.DV_LONG_WIDE:
            case BoxTag.DV_BLOB_WIDE:
            {
                byte[] bytes = Encoding.UTF8.GetBytes(s);
                return((bytes.Length < 256)
                                        ? (IMarshal) new ShortWideString(bytes)
                                        : (IMarshal) new LongWideString(bytes));
            }

            case BoxTag.DV_STRING:
            case BoxTag.DV_SHORT_STRING_SERIAL:
            case BoxTag.DV_STRICT_STRING:
            case BoxTag.DV_C_STRING:
            case BoxTag.DV_BLOB:
            {
                byte[] bytes;
                if (connection.charset_utf8)
                {
                    bytes = Encoding.UTF8.GetBytes(s);
                }
                else
                {
                    bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(s);
                }
                return((bytes.Length < 256)
                                        ? (IMarshal) new ShortString(bytes)
                                        : (IMarshal) new LongString(bytes));
            }

            case BoxTag.DV_BIN:
            case BoxTag.DV_BLOB_BIN:
            {
                byte[] bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(s);
                return((bytes.Length < 256)
                                        ? (IMarshal) new ShortString(bytes)
                                        : (IMarshal) new LongString(bytes));
            }

            default:
                // TODO:
                break;
            }

            return(null);
        }
Exemple #4
0
        internal static object UnmarshalStrses(Stream stream)
        {
            StringBuilder sb = new StringBuilder();

            int flags = ReadByte(stream);

            System.Text.Encoding enc = System.Text.Encoding.GetEncoding(
                (flags & 0x1) != 0 ? "utf-8" : "iso-8859-1");
            do
            {
                BoxTag part_tag = (BoxTag)ReadByte(stream);

                if (part_tag != BoxTag.DV_STRING &&
                    part_tag != BoxTag.DV_SHORT_STRING_SERIAL)
                {
                    throw new SystemException(
                              "Invalid data (tag=" +
                              part_tag +
                              ") in deserializing a string session");
                }
                int n = (part_tag == BoxTag.DV_STRING) ?
                        UnmarshalLongInt(stream) : ReadByte(stream);

                if (n > 0)
                {
                    byte [] buffer = new byte[n];
                    for (int ofs = stream.Read(buffer, 0, n);
                         ofs != n;
                         ofs += stream.Read(buffer, ofs, n - ofs))
                    {
                        ;
                    }

                    sb.Append(enc.GetString(buffer));
                }
                else
                {
                    break;
                }
            }while (true);
            return(sb.ToString());
        }
Exemple #5
0
        internal static DataType MapDvType(BoxTag tag)
        {
            switch (tag)
            {
            case BoxTag.DV_SHORT_INT:               return(SmallInt);

            case BoxTag.DV_LONG_INT:                return(Integer);

            case BoxTag.DV_DOUBLE_FLOAT:            return(Double);

            case BoxTag.DV_SINGLE_FLOAT:            return(Real);

            case BoxTag.DV_NUMERIC:                 return(Numeric);

            case BoxTag.DV_BLOB:
            case BoxTag.DV_BLOB_XPER:               return(LongVarChar);

            case BoxTag.DV_BLOB_BIN:                return(LongVarBinary);

            case BoxTag.DV_BLOB_WIDE:               return(NLongVarChar);

            case BoxTag.DV_DATE:                    return(Date);

            case BoxTag.DV_TIME:                    return(Time);

            case BoxTag.DV_DATETIME:                return(DateTime);

            case BoxTag.DV_TIMESTAMP:               return(Timestamp);

            case BoxTag.DV_BIN:                     return(VarBinary);

            case BoxTag.DV_RDF:
            case BoxTag.DV_BOX_FLAGS:
            case BoxTag.DV_WIDE:
            case BoxTag.DV_LONG_WIDE:               return(NVarChar);

            case BoxTag.DV_INT64:                   return(BigInt);
            }
            return(VarChar);
        }
Exemple #6
0
 internal BlobHandle(
     int ask,
     int page,
     int length,
     int keyId,
     int fragNo,
     int dirPage,
     int timeStamp,
     object pages,
     BoxTag tag)
 {
     this.ask       = ask;
     this.page      = page;
     this.length    = length;
     this.keyId     = keyId;
     this.fragNo    = fragNo;
     this.dirPage   = dirPage;
     this.timeStamp = timeStamp;
     this.pages     = pages;
     this.tag       = tag;
     Rewind();
 }
		internal BlobHandle (
			int ask,
			int page,
			int length,
			int keyId,
			int fragNo,
			int dirPage,
			int timeStamp,
			object pages,
			BoxTag tag)
		{
			this.ask = ask;
			this.page = page;
			this.length = length;
			this.keyId = keyId;
			this.fragNo = fragNo;
			this.dirPage = dirPage;
			this.timeStamp = timeStamp;
			this.pages = pages;
			this.tag = tag;
			Rewind ();
		}
		internal static IMarshal CreateExplicitString (string s, BoxTag tag, ManagedConnection connection)
		{
			switch (tag)
			{
			case BoxTag.DV_WIDE:
			case BoxTag.DV_LONG_WIDE:
			case BoxTag.DV_BLOB_WIDE:
			{
				byte[] bytes = Encoding.UTF8.GetBytes (s);
				return ((bytes.Length < 256)
					? (IMarshal) new ShortWideString (bytes)
					: (IMarshal) new LongWideString (bytes));
			}

			case BoxTag.DV_STRING:
			case BoxTag.DV_SHORT_STRING_SERIAL:
			case BoxTag.DV_STRICT_STRING:
			case BoxTag.DV_C_STRING:
			case BoxTag.DV_BLOB:
			{
				byte[] bytes;
				if (connection.charset_utf8) 
					bytes = Encoding.UTF8.GetBytes (s);
				else
					bytes = Encoding.GetEncoding ("iso-8859-1").GetBytes (s);
				return ((bytes.Length < 256)
					? (IMarshal) new ShortString (bytes)
					: (IMarshal) new LongString (bytes));
			}

			case BoxTag.DV_BIN:
			case BoxTag.DV_BLOB_BIN:
			{
				byte[] bytes = Encoding.GetEncoding ("iso-8859-1").GetBytes (s);
				return ((bytes.Length < 256)
					? (IMarshal) new ShortString (bytes)
					: (IMarshal) new LongString (bytes));
			}

			default:
				// TODO:
				break;
			}

			return null;
		}
			internal Argument (BoxTag type, bool nullable)
			{
				this.type = type;
				this.nullable = nullable;
			}
Exemple #10
0
        internal static int UnmarshalInt(Stream stream)
        {
            BoxTag tag = (BoxTag)ReadByte(stream);

            return(tag == BoxTag.DV_SHORT_INT ? UnmarshalShortInt(stream) : UnmarshalLongInt(stream));
        }
Exemple #11
0
        internal static object Unmarshal(Stream stream, ManagedConnection connection)
        {
            string table = connection == null ? null : connection.charsetTable;

            Debug.WriteLineIf(CLI.FnTrace.Enabled, "Marshaler.Unmarshal ()");

            BoxTag tag = (BoxTag)ReadByte(stream);

            Debug.WriteLineIf(marshalSwitch.Enabled, "tag: " + tag);

            switch (tag)
            {
            case BoxTag.DV_NULL:
#if false
                return(null);
#else
                return(0);
#endif

            case BoxTag.DV_DB_NULL:
                return(DBNull.Value);

            case BoxTag.DV_ARRAY_OF_POINTER:
            case BoxTag.DV_LIST_OF_POINTER:
            {
                int      n     = UnmarshalInt(stream);
                object[] array = new object[n];
                Debug.WriteLineIf(marshalSwitch.Enabled, "array start [" + n + "] {");
                for (int i = 0; i < n; i++)
                {
                    array[i] = Unmarshal(stream, connection);
                }
                Debug.WriteLineIf(marshalSwitch.Enabled, "array end");
                return(array);
            }

            case BoxTag.DV_ARRAY_OF_LONG:
            {
                int   n     = UnmarshalInt(stream);
                int[] array = new int[n];
                Debug.WriteLineIf(marshalSwitch.Enabled, "array start [" + n + "] {");
                for (int i = 0; i < n; i++)
                {
                    array[i] = UnmarshalLongInt(stream);
                }
                Debug.WriteLineIf(marshalSwitch.Enabled, "array end");
                return(array);
            }

            case BoxTag.DV_ARRAY_OF_LONG_PACKED:
            {
                int   n     = UnmarshalInt(stream);
                int[] array = new int[n];
                Debug.WriteLineIf(marshalSwitch.Enabled, "array start [" + n + "] {");
                for (int i = 0; i < n; i++)
                {
                    array[i] = UnmarshalLongInt(stream);
                }
                Debug.WriteLineIf(marshalSwitch.Enabled, "array end");
                return(array);
            }

            case BoxTag.DV_ARRAY_OF_FLOAT:
            {
                int     n     = UnmarshalInt(stream);
                float[] array = new float[n];
                Debug.WriteLineIf(marshalSwitch.Enabled, "array start [" + n + "] {");
                for (int i = 0; i < n; i++)
                {
                    array[i] = UnmarshalSingle(stream);
                }
                Debug.WriteLineIf(marshalSwitch.Enabled, "array end");
                return(array);
            }

            case BoxTag.DV_ARRAY_OF_DOUBLE:
            {
                int      n     = UnmarshalInt(stream);
                double[] array = new double[n];
                Debug.WriteLineIf(marshalSwitch.Enabled, "array start [" + n + "] {");
                for (int i = 0; i < n; i++)
                {
                    array[i] = UnmarshalDouble(stream);
                }
                Debug.WriteLineIf(marshalSwitch.Enabled, "array end");
                return(array);
            }

            case BoxTag.DV_LONG_WIDE:
            {
                int    i = 0, n = UnmarshalLongInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
                return(Encoding.UTF8.GetString(bytes));
            }

            case BoxTag.DV_WIDE:
            {
                int    i = 0, n = UnmarshalShortInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
                return(Encoding.UTF8.GetString(bytes));
            }

            case BoxTag.DV_C_STRING:
            case BoxTag.DV_STRING:
            case BoxTag.DV_LONG_CONT_STRING:
            {
                int    i = 0, n = UnmarshalLongInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
#if IGNORE_ENCODING
                return(Encoding.GetEncoding("iso-8859-1").GetString(bytes));
#else
                if (connection.charset_utf8)
                {
                    return(Encoding.UTF8.GetString(bytes));
                }
                else
                {
                    return(Decode(table, bytes));
                }
#endif
            }

            case BoxTag.DV_BOX_FLAGS:
            {
                int    flags = UnmarshalLongInt(stream);
                object str   = Unmarshal(stream, connection);
                return(new SqlExtendedString(str.ToString(), flags));
            }

            case BoxTag.DV_RDF:
            {
                int    flags = ReadByte(stream);
                object box;
                short  type;
                short  lang;
                bool   is_complete = false;
                long   ro_id       = 0L;

                if (0 != (flags & (int)SqlRdfBoxFlags.RBS_CHKSUM))
                {
                    throw new SystemException("Invalid rdf box received.");
                }

                box = Unmarshal(stream, connection);
                if (0 != (flags & (int)SqlRdfBoxFlags.RBS_OUTLINED))
                {
                    if (0 != (flags & (int)SqlRdfBoxFlags.RBS_64))
                    {
                        ro_id = UnmarshalInt64(stream);
                    }
                    else
                    {
                        ro_id = UnmarshalLongInt(stream);
                    }
                }

                if (0 != (flags & (int)SqlRdfBoxFlags.RBS_COMPLETE))
                {
                    is_complete = true;
                }

                if (0 != (flags & (int)SqlRdfBoxFlags.RBS_HAS_TYPE))
                {
                    type = UnmarshalShort(stream);
                }
                else
                {
                    type = SqlRdfBox.DEFAULT_TYPE;
                }

                if (0 != (flags & (int)SqlRdfBoxFlags.RBS_HAS_LANG))
                {
                    lang = UnmarshalShort(stream);
                }
                else
                {
                    lang = SqlRdfBox.DEFAULT_LANG;
                }
                return(new SqlRdfBox(connection, box, is_complete, type, lang, ro_id));
            }

            case BoxTag.DV_C_SHORT:
            case BoxTag.DV_SHORT_STRING_SERIAL:
            case BoxTag.DV_SHORT_CONT_STRING:
            {
                int    i = 0, n = UnmarshalShortInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
#if IGNORE_ENCODING
                return(Encoding.GetEncoding("iso-8859-1").GetString(bytes));
#else
                if (connection.charset_utf8)
                {
                    return(Encoding.UTF8.GetString(bytes));
                }
                else
                {
                    return(Decode(table, bytes));
                }
#endif
            }

            case BoxTag.DV_LONG_BIN:
            {
                int    i = 0, n = UnmarshalLongInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
                return(bytes);
            }

            case BoxTag.DV_BIN:
            {
                int    i = 0, n = UnmarshalShortInt(stream);
                byte[] bytes = new byte[n];
                while (i < n)
                {
                    i += stream.Read(bytes, i, n - i);
                }
                return(bytes);
            }

            case BoxTag.DV_SINGLE_FLOAT:
                return(UnmarshalSingle(stream));

            case BoxTag.DV_IRI_ID:
                return(UnmarshalLongInt(stream));

            case BoxTag.DV_IRI_ID_8:
            case BoxTag.DV_INT64:
                return(UnmarshalInt64(stream));

            case BoxTag.DV_DOUBLE_FLOAT:
                return(UnmarshalDouble(stream));

            case BoxTag.DV_SHORT_INT:
            {
                int i = UnmarshalShortInt(stream);
                if (i > 127)
                {
                    i -= 256;
                }
                return(i);
            }

            case BoxTag.DV_LONG_INT:
                return(UnmarshalLongInt(stream));

            case BoxTag.DV_DATETIME:
            case BoxTag.DV_DATE:
            case BoxTag.DV_TIME:
            case BoxTag.DV_TIMESTAMP:
            case BoxTag.DV_TIMESTAMP_OBJ:
                return(DateTimeMarshaler.UnmarshalDate(stream));

            case BoxTag.DV_NUMERIC:
                return(UnmarshalNumeric(stream));

            case BoxTag.DV_BLOB_HANDLE:
            case BoxTag.DV_BLOB_WIDE_HANDLE:
                return(UnmarshalBlobHandle(stream, tag));

            case BoxTag.DV_OBJECT:
                return(UnmarshalObject(stream));

            case BoxTag.DV_STRING_SESSION:
                return(UnmarshalStrses(stream));

            default:
                throw new SystemException("Unknown data type " + tag + ".");
            }
        }
		internal static DataType MapDvType (BoxTag tag)
		{
			switch (tag)
			{
			case BoxTag.DV_SHORT_INT:		return SmallInt;
			case BoxTag.DV_LONG_INT:		return Integer;
			case BoxTag.DV_DOUBLE_FLOAT:		return Double;
			case BoxTag.DV_SINGLE_FLOAT:		return Real;
			case BoxTag.DV_NUMERIC:			return Numeric;
			case BoxTag.DV_BLOB:
			case BoxTag.DV_BLOB_XPER:		return LongVarChar;
			case BoxTag.DV_BLOB_BIN:		return LongVarBinary;
			case BoxTag.DV_BLOB_WIDE:		return NLongVarChar;
			case BoxTag.DV_DATE:			return Date;
			case BoxTag.DV_TIME:			return Time;
			case BoxTag.DV_DATETIME:		return DateTime;
			case BoxTag.DV_TIMESTAMP:		return Timestamp;
			case BoxTag.DV_BIN:			return VarBinary;
			case BoxTag.DV_RDF:
			case BoxTag.DV_BOX_FLAGS:
			case BoxTag.DV_WIDE:
			case BoxTag.DV_LONG_WIDE:		return NVarChar;
			case BoxTag.DV_INT64:			return BigInt;
			}
			return VarChar;
		}
		internal static object UnmarshalBlobHandle (Stream stream, BoxTag tag)
		{
			int ask = UnmarshalLongInt (stream);
			int page = UnmarshalLongInt (stream);
			int length = UnmarshalLongInt (stream);
			int keyId = UnmarshalLongInt (stream);
			int fragNo = UnmarshalLongInt (stream);
			int dirPage = UnmarshalLongInt (stream);
			int timeStamp = UnmarshalLongInt (stream);
			object pages  = Unmarshal (stream, null);
			return new BlobHandle (ask, page, length, keyId, fragNo, dirPage, timeStamp, pages, tag);
		}
 internal Argument(BoxTag type, bool nullable)
 {
     this.type     = type;
     this.nullable = nullable;
 }