Exemplo n.º 1
0
        private byte[] EncodeSliceArray(Array sourceArray)
        {
            DbDataType dbType  = DbDataType.Array;
            Charset    charset = _database.Charset;
            int        subType = (Descriptor.Scale < 0) ? 2 : 0;
            int        type    = 0;

            using (XdrStream xdr = new XdrStream(_database.Charset))
            {
                type   = TypeHelper.GetSqlTypeFromBlrType(Descriptor.DataType);
                dbType = TypeHelper.GetDbDataTypeFromBlrType(Descriptor.DataType, subType, Descriptor.Scale);

                foreach (object source in sourceArray)
                {
                    switch (dbType)
                    {
                    case DbDataType.Char:
                        byte[] buffer = charset.GetBytes(source.ToString());
                        xdr.WriteOpaque(buffer, Descriptor.Length);
                        break;

                    case DbDataType.VarChar:
                        xdr.Write((string)source);
                        break;

                    case DbDataType.SmallInt:
                        xdr.Write((short)source);
                        break;

                    case DbDataType.Integer:
                        xdr.Write((int)source);
                        break;

                    case DbDataType.BigInt:
                        xdr.Write((long)source);
                        break;

                    case DbDataType.Decimal:
                    case DbDataType.Numeric:
                        xdr.Write((decimal)source, type, Descriptor.Scale);
                        break;

                    case DbDataType.Float:
                        xdr.Write((float)source);
                        break;

                    case DbDataType.Double:
                        xdr.Write((double)source);
                        break;

                    case DbDataType.Date:
                        xdr.WriteDate(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
                        break;

                    case DbDataType.Time:
                        xdr.WriteTime((TimeSpan)source);
                        break;

                    case DbDataType.TimeStamp:
                        xdr.Write(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
                        break;

                    default:
                        throw TypeHelper.InvalidDataType((int)dbType);
                    }
                }

                return(xdr.ToArray());
            }
        }
		private byte[] EncodeSliceArray(Array sourceArray)
		{
			DbDataType	dbType	= DbDataType.Array;
			Charset		charset = _database.Charset;
			XdrStream	xdr		= new XdrStream(_database.Charset);
			int         subType = (Descriptor.Scale < 0) ? 2 : 0;
			int			type	= 0;

			type = TypeHelper.GetFbType(Descriptor.DataType);
			dbType = TypeHelper.GetDbDataType(Descriptor.DataType, subType, Descriptor.Scale);

			foreach (object source in sourceArray)
			{
				switch (dbType)
				{
					case DbDataType.Char:
						byte[] buffer = charset.GetBytes(source.ToString());
						xdr.WriteOpaque(buffer, Descriptor.Length);
						break;

					case DbDataType.VarChar:
						xdr.Write((string)source);
						break;

					case DbDataType.SmallInt:
						xdr.Write((short)source);
						break;

					case DbDataType.Integer:
						xdr.Write((int)source);
						break;

					case DbDataType.BigInt:
						xdr.Write((long)source);
						break;

					case DbDataType.Decimal:
					case DbDataType.Numeric:
						xdr.Write((decimal)source, type, Descriptor.Scale);
						break;

					case DbDataType.Float:
						xdr.Write((float)source);
						break;

					case DbDataType.Double:
						xdr.Write((double)source);
						break;

					case DbDataType.Date:
						xdr.WriteDate(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

					case DbDataType.Time:
						xdr.WriteTime((TimeSpan)source);
						break;

					case DbDataType.TimeStamp:
						xdr.Write(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

					default:
						throw new NotSupportedException("Unknown data type");
				}
			}

			return xdr.ToArray();
		}