Пример #1
0
        protected virtual byte[] WriteParameters()
        {
            if (_parameters == null)
            {
                return(null);
            }

            using (var xdr = new XdrStream(_database.Charset))
            {
                for (var i = 0; i < _parameters.Count; i++)
                {
                    var field = _parameters[i];
                    try
                    {
                        WriteRawParameter(xdr, field);
                        xdr.Write(field.NullFlag);
                    }
                    catch (IOException ex)
                    {
                        throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
                    }
                }

                return(xdr.ToArray());
            }
        }
Пример #2
0
        protected void SendExecuteToBuffer()
        {
            // this may throw error, so it needs to be before any writing
            byte[] descriptor = null;
            if (this.parameters != null)
            {
                using (XdrStream xdr = new XdrStream(this.database.Charset))
                {
                    xdr.Write(this.parameters);
                    descriptor = xdr.ToArray();
                }
            }

            // Write the message
            if (this.statementType == DbStatementType.StoredProcedure)
            {
                this.database.Write(IscCodes.op_execute2);
            }
            else
            {
                this.database.Write(IscCodes.op_execute);
            }

            this.database.Write(this.handle);
            this.database.Write(this.transaction.Handle);

            if (this.parameters != null)
            {
                this.database.WriteBuffer(this.parameters.ToBlrArray());
                this.database.Write(0); // Message number
                this.database.Write(1); // Number of messages
                this.database.Write(descriptor, 0, descriptor.Length);
            }
            else
            {
                this.database.WriteBuffer(null);
                this.database.Write(0);
                this.database.Write(0);
            }

            if (this.statementType == DbStatementType.StoredProcedure)
            {
                this.database.WriteBuffer((this.fields == null) ? null : this.fields.ToBlrArray());
                this.database.Write(0); // Output message number
            }
        }
Пример #3
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());
            }
        }
Пример #4
0
        private byte[] ReceiveSliceResponse(ArrayDesc desc)
        {
            try
            {
                int operation = _database.ReadOperation();

                if (operation == IscCodes.op_slice)
                {
                    bool isVariying = false;
                    int  elements   = 0;
                    int  length     = _database.XdrStream.ReadInt32();

                    length = _database.XdrStream.ReadInt32();

                    switch (desc.DataType)
                    {
                    case IscCodes.blr_text:
                    case IscCodes.blr_text2:
                    case IscCodes.blr_cstring:
                    case IscCodes.blr_cstring2:
                        elements = length / desc.Length;
                        length  += elements * ((4 - desc.Length) & 3);
                        break;

                    case IscCodes.blr_varying:
                    case IscCodes.blr_varying2:
                        elements   = length / desc.Length;
                        isVariying = true;
                        break;

                    case IscCodes.blr_short:
                        length = length * desc.Length;
                        break;
                    }

                    if (isVariying)
                    {
                        using (XdrStream xdr = new XdrStream())
                        {
                            for (int i = 0; i < elements; i++)
                            {
                                byte[] buffer = _database.XdrStream.ReadOpaque(_database.XdrStream.ReadInt32());

                                xdr.WriteBuffer(buffer, buffer.Length);
                            }

                            return(xdr.ToArray());
                        }
                    }
                    else
                    {
                        return(_database.XdrStream.ReadOpaque(length));
                    }
                }
                else
                {
                    _database.SetOperation(operation);
                    _database.ReadResponse();

                    return(null);
                }
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
		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();
		}
		private byte[] ReceiveSliceResponse(ArrayDesc desc)
		{
			try
			{
				int operation = _database.ReadOperation();

				if (operation == IscCodes.op_slice)
				{
					// Read	slice length
					bool	isVariying = false;
					int		elements = 0;
					int		length = _database.ReadInt32();

					length = _database.ReadInt32();

					switch (desc.DataType)
					{
						case IscCodes.blr_text:
						case IscCodes.blr_text2:
						case IscCodes.blr_cstring:
						case IscCodes.blr_cstring2:
							elements = length / desc.Length;
							length += elements * ((4 - desc.Length) & 3);
							break;

						case IscCodes.blr_varying:
						case IscCodes.blr_varying2:
							elements = length / desc.Length;
							isVariying = true;
							break;

						case IscCodes.blr_short:
							length = length * desc.Length;
							break;
					}

					if (isVariying)
					{
						XdrStream xdr = new XdrStream();

						for (int i = 0; i < elements; i++)
						{
							byte[] buffer = _database.ReadOpaque(_database.ReadInt32());

							xdr.WriteBuffer(buffer, buffer.Length);
						}

						return xdr.ToArray();
					}
					else
					{
						return _database.ReadOpaque(length);
					}
				}
				else
				{
					_database.SetOperation(operation);
					_database.ReadResponse();

					return null;
				}
			}
			catch (IOException)
			{
				throw new IscException(IscCodes.isc_net_read_err);
			}
		}
Пример #7
0
		protected void SendExecuteToBuffer()
		{
			// this may throw error, so it needs to be before any writing
			byte[] descriptor = null;
			if (this.parameters != null)
			{
				using (XdrStream xdr = new XdrStream(this.database.Charset))
				{
					xdr.Write(this.parameters);
					descriptor = xdr.ToArray();
				}
			}

			// Write the message
			if (this.statementType == DbStatementType.StoredProcedure)
			{
				this.database.Write(IscCodes.op_execute2);
			}
			else
			{
				this.database.Write(IscCodes.op_execute);
			}

			this.database.Write(this.handle);
			this.database.Write(this.transaction.Handle);

			if (this.parameters != null)
			{
				this.database.WriteBuffer(this.parameters.ToBlrArray());
				this.database.Write(0);	// Message number
				this.database.Write(1);	// Number of messages
				this.database.Write(descriptor, 0, descriptor.Length);
			}
			else
			{
				this.database.WriteBuffer(null);
				this.database.Write(0);
				this.database.Write(0);
			}

			if (this.statementType == DbStatementType.StoredProcedure)
			{
				this.database.WriteBuffer((this.fields == null) ? null : this.fields.ToBlrArray());
				this.database.Write(0);	// Output message number
			}
		}