상속: Stream
예제 #1
0
        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();
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
        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);
                }
            }
        }
예제 #5
0
 protected override void Dispose(bool disposing)
 {
     lob = null;
     base.Dispose(disposing);
 }
예제 #6
0
 public LobInputStream(DeveelDbLob lob)
 {
     this.lob = lob;
 }
예제 #7
0
 protected override void Dispose(bool disposing)
 {
     lob = null;
     base.Dispose(disposing);
 }
예제 #8
0
 public LobInputStream(DeveelDbLob lob)
 {
     this.lob = lob;
 }
예제 #9
0
        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;
        }