public virtual void Detach() { lock (SyncObject) { if (TransactionCount > 0) { throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount); } try { if (_handle != 0) { XdrStream.Write(IscCodes.op_detach); XdrStream.Write(_handle); } XdrStream.Write(IscCodes.op_disconnect); XdrStream.Flush(); // Close the Event Manager CloseEventManager(); // Disconnect CloseConnection(); #warning Here // Close Input and Output streams _xdrStream?.Close(); // Clear members _transactionCount = 0; _handle = 0; _dialect = 0; _packetSize = 0; _xdrStream = null; _charset = null; _connection = null; _serverVersion = null; } catch (IOException ex) { try { CloseConnection(); } catch (IOException ex2) { throw IscException.ForErrorCode(IscCodes.isc_network_error, ex2); } throw IscException.ForErrorCode(IscCodes.isc_network_error, ex); } } }
protected override System.Array DecodeSlice(byte[] slice) { DbDataType dbType = DbDataType.Array; Array sliceData = null; Array tempData = null; Type systemType = GetSystemType(); int[] lengths = new int[Descriptor.Dimensions]; int[] lowerBounds = new int[Descriptor.Dimensions]; int type = 0; int index = 0; // Get upper and lower bounds of each dimension for (int i = 0; i < Descriptor.Dimensions; i++) { lowerBounds[i] = Descriptor.Bounds[i].LowerBound; lengths[i] = Descriptor.Bounds[i].UpperBound; if (lowerBounds[i] == 0) { lengths[i]++; } } // Create arrays sliceData = Array.CreateInstance(systemType, lengths, lowerBounds); tempData = Array.CreateInstance(systemType, sliceData.Length); // Infer Firebird and Db datatypes type = TypeHelper.GetSqlTypeFromBlrType(Descriptor.DataType); dbType = TypeHelper.GetDbDataTypeFromBlrType(Descriptor.DataType, 0, Descriptor.Scale); // Decode slice data XdrStream xdr = new XdrStream(slice, _database.Charset); while (xdr.Position < xdr.Length) { switch (dbType) { case DbDataType.Char: tempData.SetValue(xdr.ReadString(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, 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); }
protected override System.Array DecodeSlice(byte[] slice) { DbDataType dbType = DbDataType.Array; Array sliceData = null; Array tempData = null; Type systemType = GetSystemType(); int[] lengths = new int[Descriptor.Dimensions]; int[] lowerBounds = new int[Descriptor.Dimensions]; int type = 0; int index = 0; // Get upper and lower bounds of each dimension for (int i = 0; i < Descriptor.Dimensions; i++) { lowerBounds[i] = Descriptor.Bounds[i].LowerBound; lengths[i] = Descriptor.Bounds[i].UpperBound; if (lowerBounds[i] == 0) { lengths[i]++; } } // Create arrays sliceData = Array.CreateInstance(systemType, lengths, lowerBounds); tempData = Array.CreateInstance(systemType, sliceData.Length); // Infer Firebird and Db datatypes type = TypeHelper.GetFbType(Descriptor.DataType); dbType = TypeHelper.GetDbDataType(Descriptor.DataType, 0, Descriptor.Scale); // Decode slice data XdrStream xdr = new XdrStream(slice, _database.Charset); while (xdr.Position < xdr.Length) { switch (dbType) { case DbDataType.Char: tempData.SetValue(xdr.ReadString(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, 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 virtual void Detach() { lock (SyncObject) { if (TransactionCount > 0) { throw new IscException(IscCodes.isc_open_trans, TransactionCount); } try { if (_handle != 0) { Write(IscCodes.op_detach); Write(_handle); } Write(IscCodes.op_disconnect); Flush(); // Close the Event Manager CloseEventManager(); // Disconnect CloseConnection(); // Close Input and Output streams if (_inputStream != null) { _inputStream.Close(); } if (_outputStream != null) { _outputStream.Close(); } // Clear members _transactionCount = 0; _handle = 0; _dialect = 0; _packetSize = 0; _operation = 0; _outputStream = null; _inputStream = null; _charset = null; _connection = null; _serverVersion = null; } catch (IOException) { try { CloseConnection(); } catch (IOException) { throw new IscException(IscCodes.isc_network_error); } throw new IscException(IscCodes.isc_network_error); } } }