Пример #1
0
        protected override System.Array DecodeSlice(byte[] slice)
        {
            DbDataType dbType     = DbDataType.Array;
            Array      sliceData  = null;
            Array      tempData   = null;
            Type       systemType = this.GetSystemType();

            int[] lengths     = new int[this.Descriptor.Dimensions];
            int[] lowerBounds = new int[this.Descriptor.Dimensions];
            int   type        = 0;
            int   index       = 0;

            // Get upper and lower bounds of each dimension
            for (int i = 0; i < this.Descriptor.Dimensions; i++)
            {
                lowerBounds[i] = this.Descriptor.Bounds[i].LowerBound;
                lengths[i]     = this.Descriptor.Bounds[i].UpperBound;

                if (lowerBounds[i] == 0)
                {
                    lengths[i]++;
                }
            }

            // Create arrays
#if     (NETCF)
            sliceData = Array.CreateInstance(systemType, lengths);
#else
            sliceData = Array.CreateInstance(systemType, lengths, lowerBounds);
#endif
            tempData = Array.CreateInstance(systemType, sliceData.Length);

            // Infer Firebird and Db datatypes
            type   = TypeHelper.GetFbType(this.Descriptor.DataType);
            dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, 0, this.Descriptor.Scale);

            // Decode slice	data
            XdrStream xdr = new XdrStream(slice, this.db.Charset);

            while (xdr.Position < xdr.Length)
            {
                switch (dbType)
                {
                case DbDataType.Char:
                    tempData.SetValue(xdr.ReadString(this.Descriptor.Length), index);
                    break;

                case DbDataType.VarChar:
                    tempData.SetValue(xdr.ReadString(), index);
                    break;

                case DbDataType.SmallInt:
                    tempData.SetValue(xdr.ReadInt16(), index);
                    break;

                case DbDataType.Integer:
                    tempData.SetValue(xdr.ReadInt32(), index);
                    break;

                case DbDataType.BigInt:
                    tempData.SetValue(xdr.ReadInt64(), index);
                    break;

                case DbDataType.Numeric:
                case DbDataType.Decimal:
                    tempData.SetValue(xdr.ReadDecimal(type, this.Descriptor.Scale), index);
                    break;

                case DbDataType.Float:
                    tempData.SetValue(xdr.ReadSingle(), index);
                    break;

                case DbDataType.Double:
                    tempData.SetValue(xdr.ReadDouble(), index);
                    break;

                case DbDataType.Date:
                    tempData.SetValue(xdr.ReadDate(), index);
                    break;

                case DbDataType.Time:
                    tempData.SetValue(xdr.ReadTime(), index);
                    break;

                case DbDataType.TimeStamp:
                    tempData.SetValue(xdr.ReadDateTime(), index);
                    break;
                }

                index++;
            }

            if (systemType.IsPrimitive)
            {
                // For primitive types we can use System.Buffer	to copy	generated data to destination array
                Buffer.BlockCopy(tempData, 0, sliceData, 0, Buffer.ByteLength(tempData));
            }
            else
            {
                sliceData = tempData;
            }

            // Close XDR stream
            xdr.Close();

            return(sliceData);
        }
		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);
				}
			}
		}
Пример #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);
                }
            }
        }
Пример #4
0
		protected override System.Array DecodeSlice(byte[] slice)
		{
			DbDataType	dbType		= DbDataType.Array;
			Array		sliceData	= null;
			Array		tempData	= null;
			Type		systemType	= this.GetSystemType();
			int[]		lengths		= new int[this.Descriptor.Dimensions];
			int[]		lowerBounds = new int[this.Descriptor.Dimensions];
			int			type		= 0;
			int			index		= 0;

			// Get upper and lower bounds of each dimension
			for (int i = 0; i < this.Descriptor.Dimensions; i++)
			{
				lowerBounds[i]	= this.Descriptor.Bounds[i].LowerBound;
				lengths[i]		= this.Descriptor.Bounds[i].UpperBound;

				if (lowerBounds[i] == 0)
				{
					lengths[i]++;
				}
			}

			// Create arrays
#if	(NETCF)
			sliceData = Array.CreateInstance(systemType, lengths);
#else
			sliceData = Array.CreateInstance(systemType, lengths, lowerBounds);
#endif
			tempData = Array.CreateInstance(systemType, sliceData.Length);

			// Infer Firebird and Db datatypes
			type	= TypeHelper.GetFbType(this.Descriptor.DataType);
			dbType	= TypeHelper.GetDbDataType(this.Descriptor.DataType, 0, this.Descriptor.Scale);

			// Decode slice	data
			XdrStream xdr = new XdrStream(slice, this.db.Charset);

			while (xdr.Position < xdr.Length)
			{
				switch (dbType)
				{
					case DbDataType.Char:
						tempData.SetValue(xdr.ReadString(this.Descriptor.Length), index);
						break;

					case DbDataType.VarChar:
						tempData.SetValue(xdr.ReadString(), index);
						break;

					case DbDataType.SmallInt:
						tempData.SetValue(xdr.ReadInt16(), index);
						break;

					case DbDataType.Integer:
						tempData.SetValue(xdr.ReadInt32(), index);
						break;

					case DbDataType.BigInt:
						tempData.SetValue(xdr.ReadInt64(), index);
						break;

					case DbDataType.Numeric:
					case DbDataType.Decimal:
						tempData.SetValue(xdr.ReadDecimal(type, this.Descriptor.Scale), index);
						break;

					case DbDataType.Float:
						tempData.SetValue(xdr.ReadSingle(), index);
						break;

					case DbDataType.Double:
						tempData.SetValue(xdr.ReadDouble(), index);
						break;

					case DbDataType.Date:
						tempData.SetValue(xdr.ReadDate(), index);
						break;

					case DbDataType.Time:
						tempData.SetValue(xdr.ReadTime(), index);
						break;

					case DbDataType.TimeStamp:
						tempData.SetValue(xdr.ReadDateTime(), index);
						break;
				}

				index++;
			}

			if (systemType.IsPrimitive)
			{
				// For primitive types we can use System.Buffer	to copy	generated data to destination array
				Buffer.BlockCopy(tempData, 0, sliceData, 0, Buffer.ByteLength(tempData));
			}
			else
			{
				sliceData = tempData;
			}

			// Close XDR stream
			xdr.Close();

			return sliceData;
		}