示例#1
0
        private byte[] EncodeSliceArray(Array sourceArray)
        {
            IEnumerator i       = sourceArray.GetEnumerator();
            DbDataType  dbType  = DbDataType.Array;
            Charset     charset = this.db.Charset;
            XdrStream   xdr     = new XdrStream(this.db.Charset);
            int         type    = 0;
            int         subtype = (this.Descriptor.Scale < 0) ? 2 : 0;

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

            while (i.MoveNext())
            {
                switch (dbType)
                {
                case DbDataType.Char:
                    byte[] buffer = charset.GetBytes(i.Current.ToString());
                    xdr.WriteOpaque(buffer, this.Descriptor.Length);
                    break;

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

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

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

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

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

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

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

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

                case DbDataType.Time:
                    xdr.WriteTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
                    break;

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

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

            return(xdr.ToArray());
        }
示例#2
0
        private byte[] ReceiveSliceResponse(ArrayDesc desc)
        {
            try
            {
                int operation = this.db.ReadOperation();

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

                    length = this.db.Receive.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 = this.db.Receive.ReadOpaque(
                                this.db.Receive.ReadInt32());

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

                        return(xdr.ToArray());
                    }
                    else
                    {
                        return(this.db.Receive.ReadOpaque(length));
                    }
                }
                else
                {
                    this.db.SetOperation(operation);
                    this.db.ReadGenericResponse();

                    return(null);
                }
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_net_read_err);
            }
        }
示例#3
0
        public override void Execute()
        {
            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statment is not correctly created.");
            }

            // Clear data
            this.Clear();

            lock (this.db)
            {
                try
                {
                    byte[] descriptor = null;
                    if (this.parameters != null)
                    {
                        XdrStream xdr = new XdrStream(this.db.Charset);
                        xdr.Write(this.parameters);

                        descriptor = xdr.ToArray();

                        xdr.Close();
                    }

                    if (this.statementType == DbStatementType.StoredProcedure)
                    {
                        this.db.Send.Write(IscCodes.op_execute2);
                    }
                    else
                    {
                        this.db.Send.Write(IscCodes.op_execute);
                    }

                    this.db.Send.Write(this.handle);
                    this.db.Send.Write(this.transaction.Handle);

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

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

                    this.db.Send.Flush();

                    if (this.db.NextOperation() == IscCodes.op_sql_response)
                    {
                        // This	would be an	Execute	procedure
                        this.outputParams.Enqueue(this.ReceiveSqlResponse());
                    }

                    this.db.ReadGenericResponse();

                    // Updated number of records affected by the statement execution
                    if (this.StatementType == DbStatementType.Insert ||
                        this.StatementType == DbStatementType.Delete ||
                        this.StatementType == DbStatementType.Update ||
                        this.StatementType == DbStatementType.StoredProcedure)
                    {
                        this.recordsAffected = this.GetRecordsAffected();
                    }
                    else
                    {
                        this.recordsAffected = -1;
                    }

                    this.state = StatementState.Executed;
                }
                catch (IOException)
                {
                    this.state = StatementState.Error;
                    throw new IscException(IscCodes.isc_net_read_err);
                }
            }
        }
		public override void Execute()
		{
			if (this.state == StatementState.Deallocated)
			{
				throw new InvalidOperationException("Statment is not correctly created.");
			}

			// Clear data
			this.Clear();

			lock (this.db)
			{
				try
				{
					byte[] descriptor = null;
					if (this.parameters != null)
					{
						XdrStream xdr = new XdrStream(this.db.Charset);
						xdr.Write(this.parameters);

						descriptor = xdr.ToArray();

						xdr.Close();
					}

					if (this.statementType == DbStatementType.StoredProcedure)
					{
						this.db.Send.Write(IscCodes.op_execute2);
					}
					else
					{
						this.db.Send.Write(IscCodes.op_execute);
					}

					this.db.Send.Write(this.handle);
					this.db.Send.Write(this.transaction.Handle);

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

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

					this.db.Send.Flush();

					if (this.db.NextOperation() == IscCodes.op_sql_response)
					{
						// This	would be an	Execute	procedure
						this.outputParams.Enqueue(this.ReceiveSqlResponse());
					}

					this.db.ReadGenericResponse();

					// Updated number of records affected by the statement execution			
					if (this.StatementType == DbStatementType.Insert ||
						this.StatementType == DbStatementType.Delete ||
						this.StatementType == DbStatementType.Update ||
                        this.StatementType == DbStatementType.StoredProcedure)
					{
						this.recordsAffected = this.GetRecordsAffected();
					}
					else
					{
						this.recordsAffected = -1;
					}

					this.state = StatementState.Executed;
				}
				catch (IOException)
				{
					this.state = StatementState.Error;
					throw new IscException(IscCodes.isc_net_read_err);
				}
			}
		}
		private byte[] EncodeSliceArray(Array sourceArray)
		{
			IEnumerator i		= sourceArray.GetEnumerator();
			DbDataType	dbType	= DbDataType.Array;
			Charset		charset = this.db.Charset;
			XdrStream	xdr		= new XdrStream(this.db.Charset);
			int			type	= 0;
			int			subtype = (this.Descriptor.Scale < 0) ? 2 : 0;

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

			while (i.MoveNext())
			{
				switch (dbType)
				{
					case DbDataType.Char:
						byte[] buffer = charset.GetBytes(i.Current.ToString());
						xdr.WriteOpaque(buffer, this.Descriptor.Length);
						break;

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

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

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

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

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

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

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

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

					case DbDataType.Time:
						xdr.WriteTime(Convert.ToDateTime(i.Current, CultureInfo.CurrentCulture.DateTimeFormat));
						break;

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

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

			return xdr.ToArray();
		}
		private byte[] ReceiveSliceResponse(ArrayDesc desc)
		{
			try
			{
				int operation = this.db.ReadOperation();

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

					length = this.db.Receive.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 = this.db.Receive.ReadOpaque(
								this.db.Receive.ReadInt32());

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

						return xdr.ToArray();
					}
					else
					{
						return this.db.Receive.ReadOpaque(length);
					}
				}
				else
				{
					this.db.SetOperation(operation);
					this.db.ReadGenericResponse();

					return null;
				}
			}
			catch (IOException)
			{
				throw new IscException(IscCodes.isc_net_read_err);
			}
		}