protected void WriteRawParameter(XdrBinaryWriter xdr, DbField field) { if (field.DbDataType != DbDataType.Null) { field.FixNull(); switch (field.DbDataType) { case DbDataType.Char: if (field.Charset.IsOctetsCharset) { xdr.WriteOpaque(field.DbValue.GetBinary(), field.Length); } else { var svalue = field.DbValue.GetString(); if ((field.Length % field.Charset.BytesPerCharacter) == 0 && svalue.Length > field.CharCount) { throw IscException.ForErrorCodes(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation }); } xdr.WriteOpaque(field.Charset.GetBytes(svalue), field.Length); } break; case DbDataType.VarChar: if (field.Charset.IsOctetsCharset) { xdr.WriteBuffer(field.DbValue.GetBinary()); } else { var svalue = field.DbValue.GetString(); if ((field.Length % field.Charset.BytesPerCharacter) == 0 && svalue.Length > field.CharCount) { throw IscException.ForErrorCodes(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation }); } xdr.WriteBuffer(field.Charset.GetBytes(svalue)); } break; case DbDataType.SmallInt: xdr.Write(field.DbValue.GetInt16()); break; case DbDataType.Integer: xdr.Write(field.DbValue.GetInt32()); break; case DbDataType.BigInt: case DbDataType.Array: case DbDataType.Binary: case DbDataType.Text: xdr.Write(field.DbValue.GetInt64()); break; case DbDataType.Decimal: case DbDataType.Numeric: xdr.Write(field.DbValue.GetDecimal(), field.DataType, field.NumericScale); break; case DbDataType.Float: xdr.Write(field.DbValue.GetFloat()); break; case DbDataType.Guid: xdr.WriteOpaque(field.DbValue.GetGuid().ToByteArray()); break; case DbDataType.Double: xdr.Write(field.DbValue.GetDouble()); break; case DbDataType.Date: xdr.Write(field.DbValue.GetDate()); break; case DbDataType.Time: xdr.Write(field.DbValue.GetTime()); break; case DbDataType.TimeStamp: xdr.Write(field.DbValue.GetDate()); xdr.Write(field.DbValue.GetTime()); break; case DbDataType.Boolean: xdr.Write(Convert.ToBoolean(field.Value)); break; default: throw IscException.ForStrParam($"Unknown SQL data type: {field.DataType}."); } } }
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 (var stream = new MemoryStream()) { var writer = new XdrBinaryWriter(stream); for (int i = 0; i < elements; i++) { byte[] buffer = _database.XdrStream.ReadOpaque(_database.XdrStream.ReadInt32()); writer.WriteBuffer(buffer, buffer.Length); } return(stream.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); } }