public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) { var value = GetRawValue(ordinal); if (value is SqlBinary) { var binary = (SqlBinary)value; var input = binary.GetInput(); input.Seek(dataOffset, SeekOrigin.Begin); return(input.Read(buffer, bufferOffset, length)); } if (value is IObjectRef) { var objRef = ((IObjectRef)value); var lob = new DeveelDbLob(command.Connection, objRef.ObjectId, objRef.Size); if (!lob.CanRead) { throw new NotSupportedException(); } lob.Seek(dataOffset, SeekOrigin.Begin); return(lob.Read(buffer, bufferOffset, length)); } throw new NotSupportedException(); }
internal static ObjectId Upload(DeveelDbConnection connection, DeveelDbLob lob) { if (connection == null) { throw new InvalidOperationException("An open connection is required to upload the LOB"); } var objId = connection.CreateLargeObject(lob.Length); using (var channel = connection.OpenLargeObjectChannel(objId)) { const int bufferSize = 2048; var copyBuffer = new byte[bufferSize]; int readCount; long copyOffset = 0; lob.writeStream.Seek(0, SeekOrigin.Begin); while ((readCount = lob.writeStream.Read(copyBuffer, 0, bufferSize)) > 0) { channel.PushData(copyOffset, copyBuffer, readCount); copyOffset += readCount; } } return(objId); }
private void PrepareCommand() { if (Parameters != null && Parameters.Count > 0) { preparedParameters = new List <QueryParameter>(Parameters.Count); foreach (DeveelDbParameter parameter in Parameters) { DeveelDbLob lob = null; if (parameter.Value is DeveelDbLob) { lob = (DeveelDbLob)parameter.Value; } else if (parameter.Value is Stream) { var stream = (Stream)parameter.Value; lob = new DeveelDbLob(parameter.Size); stream.CopyTo(lob); } if (lob != null) { var objId = DeveelDbLob.Upload(connection, lob); } var sqlType = parameter.GetSqlType(); var queryParam = new QueryParameter(parameter.ParameterName, sqlType); queryParam.Value = sqlType.CreateFrom(parameter.Value); preparedParameters.Add(queryParam); } } }
private void PrepareCommand() { if (Parameters != null && Parameters.Count > 0) { preparedParameters = new List<QueryParameter>(Parameters.Count); foreach (DeveelDbParameter parameter in Parameters) { DeveelDbLob lob = null; if (parameter.Value is DeveelDbLob) { lob = (DeveelDbLob) parameter.Value; } else if (parameter.Value is Stream) { var stream = (Stream) parameter.Value; lob = new DeveelDbLob(parameter.Size); stream.CopyTo(lob); } if (lob != null) { var objId = DeveelDbLob.Upload(connection, lob); } var sqlType = parameter.GetSqlType(); var queryParam = new QueryParameter(parameter.ParameterName, sqlType); queryParam.Value = sqlType.CreateFrom(parameter.Value); preparedParameters.Add(queryParam); } } }
protected override void Dispose(bool disposing) { lob = null; base.Dispose(disposing); }
public LobInputStream(DeveelDbLob lob) { this.lob = lob; }
internal static ObjectId Upload(DeveelDbConnection connection, DeveelDbLob lob) { if (connection == null) throw new InvalidOperationException("An open connection is required to upload the LOB"); var objId = connection.CreateLargeObject(lob.Length); using (var channel = connection.OpenLargeObjectChannel(objId)) { const int bufferSize = 2048; var copyBuffer = new byte[bufferSize]; int readCount; long copyOffset = 0; lob.writeStream.Seek(0, SeekOrigin.Begin); while ((readCount = lob.writeStream.Read(copyBuffer, 0, bufferSize)) > 0) { channel.PushData(copyOffset, copyBuffer, readCount); copyOffset += readCount; } } return objId; }