public void LookupDesc() { // Initializa array descriptor information this.descriptor = new ArrayDesc(); // Create statement for retrieve information StatementBase lookup = this.DB.CreateStatement(this.Transaction); lookup.Prepare(this.GetArrayDesc()); lookup.Execute(); DbValue[] values = lookup.Fetch(); if (values != null && values.Length > 0) { this.descriptor.RelationName = tableName; this.descriptor.FieldName = fieldName; this.descriptor.DataType = values[0].GetByte(); this.descriptor.Scale = values[1].GetInt16(); this.descriptor.Length = values[2].GetInt16(); this.descriptor.Dimensions = values[3].GetInt16(); this.descriptor.Flags = 0; this.rdbFieldName = values[4].GetString().Trim(); } else { throw new InvalidOperationException(); } lookup.Release(); lookup = null; }
private async Task LookupDesc(AsyncWrappingCommonArgs async) { var lookup = Database.CreateStatement(Transaction); try { await lookup.Prepare(GetArrayDesc(), async).ConfigureAwait(false); await lookup.Execute(async).ConfigureAwait(false); _descriptor = new ArrayDesc(); var values = await lookup.Fetch(async).ConfigureAwait(false); if (values != null && values.Length > 0) { _descriptor.RelationName = _tableName; _descriptor.FieldName = _fieldName; _descriptor.DataType = await values[0].GetByte(async).ConfigureAwait(false); _descriptor.Scale = await values[1].GetInt16(async).ConfigureAwait(false); _descriptor.Length = await values[2].GetInt16(async).ConfigureAwait(false); _descriptor.Dimensions = await values[3].GetInt16(async).ConfigureAwait(false); _descriptor.Flags = 0; _rdbFieldName = (await values[4].GetString(async).ConfigureAwait(false)).Trim(); } else { throw new InvalidOperationException(); } } finally { await lookup.Dispose2(async).ConfigureAwait(false); } }
public void LookupDesc() { using (StatementBase lookup = DB.CreateStatement(Transaction)) { lookup.Prepare(GetArrayDesc()); lookup.Execute(); _descriptor = new ArrayDesc(); DbValue[] values = lookup.Fetch(); if (values != null && values.Length > 0) { _descriptor.RelationName = _tableName; _descriptor.FieldName = _fieldName; _descriptor.DataType = values[0].GetByte(); _descriptor.Scale = values[1].GetInt16(); _descriptor.Length = values[2].GetInt16(); _descriptor.Dimensions = values[3].GetInt16(); _descriptor.Flags = 0; _rdbFieldName = values[4].GetString().Trim(); } else { throw new InvalidOperationException(); } } }
private void LookupDesc() { var lookup = Database.CreateStatement(Transaction); try { lookup.Prepare(GetArrayDesc()); lookup.Execute(); _descriptor = new ArrayDesc(); var values = lookup.Fetch(); if (values != null && values.Length > 0) { _descriptor.RelationName = _tableName; _descriptor.FieldName = _fieldName; _descriptor.DataType = values[0].GetByte(); _descriptor.Scale = values[1].GetInt16(); _descriptor.Length = values[2].GetInt16(); _descriptor.Dimensions = values[3].GetInt16(); _descriptor.Flags = 0; _rdbFieldName = (values[4].GetString()).Trim(); } else { throw new InvalidOperationException(); } } finally { lookup.Dispose2(); } }
private async ValueTask LookupDescAsync(CancellationToken cancellationToken = default) { var lookup = Database.CreateStatement(Transaction); try { await lookup.PrepareAsync(GetArrayDesc(), cancellationToken).ConfigureAwait(false); await lookup.ExecuteAsync(cancellationToken).ConfigureAwait(false); _descriptor = new ArrayDesc(); var values = await lookup.FetchAsync(cancellationToken).ConfigureAwait(false); if (values != null && values.Length > 0) { _descriptor.RelationName = _tableName; _descriptor.FieldName = _fieldName; _descriptor.DataType = values[0].GetByte(); _descriptor.Scale = values[1].GetInt16(); _descriptor.Length = values[2].GetInt16(); _descriptor.Dimensions = values[3].GetInt16(); _descriptor.Flags = 0; _rdbFieldName = (await values[4].GetStringAsync(cancellationToken).ConfigureAwait(false)).Trim(); } else { throw new InvalidOperationException(); } } finally { await lookup.Dispose2Async(cancellationToken).ConfigureAwait(false); } }
public IntPtr MarshalManagedToNative(ArrayDesc descriptor) { ArrayDescMarshal arrayDesc = new ArrayDescMarshal(); arrayDesc.DataType = descriptor.DataType; arrayDesc.Scale = (byte)descriptor.Scale; arrayDesc.Length = descriptor.Length; arrayDesc.FieldName = descriptor.FieldName; arrayDesc.RelationName = descriptor.RelationName; arrayDesc.Dimensions = descriptor.Dimensions; arrayDesc.Flags = descriptor.Flags; ArrayBoundMarshal[] arrayBounds = new ArrayBoundMarshal[descriptor.Bounds.Length]; for (int i = 0; i < descriptor.Dimensions; i++) { arrayBounds[i].LowerBound = (short)descriptor.Bounds[i].LowerBound; arrayBounds[i].UpperBound = (short)descriptor.Bounds[i].UpperBound; } return this.MarshalManagedToNative(arrayDesc, arrayBounds); }
private byte[] GenerateSDL(ArrayDesc desc) { int n; int from; int to; int increment; int dimensions; ArrayBound tail; BinaryWriter sdl; dimensions = desc.Dimensions; if (dimensions > 16) { throw new IscException(IscCodes.isc_invalid_dimension); } sdl = new BinaryWriter(new MemoryStream()); Stuff( sdl, 4, IscCodes.isc_sdl_version1, IscCodes.isc_sdl_struct, 1, desc.DataType); switch (desc.DataType) { case IscCodes.blr_short: case IscCodes.blr_long: case IscCodes.blr_int64: case IscCodes.blr_quad: StuffSdl(sdl, (byte)desc.Scale); break; case IscCodes.blr_text: case IscCodes.blr_cstring: case IscCodes.blr_varying: StuffWord(sdl, desc.Length); break; default: break; } StuffString(sdl, IscCodes.isc_sdl_relation, desc.RelationName); StuffString(sdl, IscCodes.isc_sdl_field, desc.FieldName); if ((desc.Flags & IscCodes.ARRAY_DESC_COLUMN_MAJOR) == IscCodes.ARRAY_DESC_COLUMN_MAJOR) { from = dimensions - 1; to = -1; increment = -1; } else { from = 0; to = dimensions; increment = 1; } for (n = from; n != to; n += increment) { tail = desc.Bounds[n]; if (tail.LowerBound == 1) { Stuff(sdl, 2, IscCodes.isc_sdl_do1, n); } else { Stuff(sdl, 2, IscCodes.isc_sdl_do2, n); StuffLiteral(sdl, tail.LowerBound); } StuffLiteral(sdl, tail.UpperBound); } Stuff( sdl, 5, IscCodes.isc_sdl_element, 1, IscCodes.isc_sdl_scalar, 0, dimensions); for (n = 0; n < dimensions; n++) { Stuff(sdl, 2, IscCodes.isc_sdl_variable, n); } StuffSdl(sdl, IscCodes.isc_sdl_eoc); return ((MemoryStream)sdl.BaseStream).ToArray(); }
protected ArrayBase(ArrayDesc descriptor) { this.tableName = descriptor.RelationName; this.fieldName = descriptor.FieldName; this.descriptor = descriptor; }
public ExtArray(ArrayDesc descriptor) : base(descriptor) { }
public abstract ArrayBase CreateArray(ArrayDesc descriptor);
public override ArrayBase CreateArray(ArrayDesc descriptor) { return new ExtArray(descriptor); }
private byte[] EncodeSlice(ArrayDesc desc, Array sourceArray, int length) { BinaryWriter writer = new BinaryWriter(new MemoryStream()); Charset charset = this.db.Charset; DbDataType dbType = DbDataType.Array; int subType = (this.Descriptor.Scale < 0) ? 2 : 0; int type = 0; // Infer data types type = TypeHelper.GetFbType(this.Descriptor.DataType); dbType = TypeHelper.GetDbDataType(this.Descriptor.DataType, subType, this.Descriptor.Scale); foreach (object source in sourceArray) { switch (dbType) { case DbDataType.Char: { string value = source != null ? (string)source : string.Empty; byte[] buffer = charset.GetBytes(value); writer.Write(buffer); if (desc.Length > buffer.Length) { for (int j = buffer.Length; j < desc.Length; j++) { writer.Write((byte)32); } } } break; case DbDataType.VarChar: { string value = source != null ? (string)source : string.Empty; byte[] buffer = charset.GetBytes(value); writer.Write(buffer); if (desc.Length > buffer.Length) { for (int j = buffer.Length; j < desc.Length; j++) { writer.Write((byte)0); } } writer.Write((short)0); } break; case DbDataType.SmallInt: writer.Write((short)source); break; case DbDataType.Integer: writer.Write((int)source); break; case DbDataType.BigInt: writer.Write((long)source); break; case DbDataType.Float: writer.Write((float)source); break; case DbDataType.Double: writer.Write((double)source); break; case DbDataType.Numeric: case DbDataType.Decimal: { object numeric = TypeEncoder.EncodeDecimal((decimal)source, desc.Scale, type); switch (type) { case IscCodes.SQL_SHORT: writer.Write((short)numeric); break; case IscCodes.SQL_LONG: writer.Write((int)numeric); break; case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: writer.Write((long)numeric); break; } } break; case DbDataType.Date: writer.Write(TypeEncoder.EncodeDate(Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat))); break; case DbDataType.Time: writer.Write(TypeEncoder.EncodeTime((TimeSpan)source)); break; case DbDataType.TimeStamp: var dt = Convert.ToDateTime(source, CultureInfo.CurrentCulture.DateTimeFormat); writer.Write(TypeEncoder.EncodeDate(dt)); writer.Write(TypeEncoder.EncodeTime(TypeHelper.DateTimeToTimeSpan(dt))); break; default: throw new NotSupportedException("Unknown data type"); } } return ((MemoryStream)writer.BaseStream).ToArray(); }
protected ArrayBase(ArrayDesc descriptor) { _tableName = descriptor.RelationName; _fieldName = descriptor.FieldName; _descriptor = descriptor; }
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); } }
public abstract Task <ArrayBase> CreateArray(ArrayDesc descriptor, AsyncWrappingCommonArgs async);
public abstract ValueTask <ArrayBase> CreateArrayAsync(ArrayDesc descriptor, CancellationToken cancellationToken = default);
public GdsArray(ArrayDesc descriptor) : base(descriptor) { }
public FesArray(ArrayDesc descriptor) : base(descriptor) { this.statusVector = new IntPtr[IscCodes.ISC_STATUS_LENGTH]; }