コード例 #1
0
ファイル: NpgsqlRawCopyStream.cs プロジェクト: zoroz/npgsql
 internal NpgsqlCopyTextReader(NpgsqlRawCopyStream underlying) : base(underlying)
 {
     if (underlying.IsBinary)
     {
         throw new Exception("Can't use a binary copy stream for text reading");
     }
 }
コード例 #2
0
        /// <summary>
        /// Begins a raw binary COPY operation (TO or FROM), a high-performance data export/import mechanism to a PostgreSQL table.
        /// Note that unlike the other COPY API methods, <see cref="BeginRawBinaryCopy"/> doesn't implement any encoding/decoding
        /// and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque
        /// blob, for the purpose of importing it back later.
        /// </summary>
        /// <param name="copyCommand">A COPY FROM STDIN or COPY TO STDIN SQL command</param>
        /// <returns>A <see cref="NpgsqlRawCopyStream"/> that can be used to read or write raw binary data.</returns>
        /// <remarks>
        /// See http://www.postgresql.org/docs/current/static/sql-copy.html.
        /// </remarks>
        public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand)
        {
            if (copyCommand == null)
            {
                throw new ArgumentNullException("copyCommand");
            }
            if (!copyCommand.TrimStart().ToUpper().StartsWith("COPY"))
            {
                throw new ArgumentException("Must contain a COPY IN command!", "copyCommand");
            }
            Contract.EndContractBlock();

            CheckConnectionOpen();
            Connector.StartUserAction(ConnectorState.Copy);
            try
            {
                var stream = new NpgsqlRawCopyStream(Connector, copyCommand);
                if (!stream.IsBinary)
                {
                    // TODO: Stop the COPY operation gracefully, no breaking
                    Connector.Break();
                    throw new ArgumentException("copyToCommand triggered a text transfer, only binary is allowed", "copyCommand");
                }
                return(stream);
            }
            catch
            {
                Connector.EndUserAction();
                throw;
            }
        }
コード例 #3
0
 internal NpgsqlCopyTextWriter(NpgsqlRawCopyStream underlying) : base(underlying)
 {
     if (underlying.IsBinary)
     {
         throw new Exception("Can't use a binary copy stream for text writing");
     }
     Contract.EndContractBlock();
 }
コード例 #4
0
        /// <summary>
        /// Begins a raw binary COPY operation (TO or FROM), a high-performance data export/import mechanism to a PostgreSQL table.
        /// Note that unlike the other COPY API methods, <see cref="BeginRawBinaryCopy"/> doesn't implement any encoding/decoding
        /// and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque
        /// blob, for the purpose of importing it back later.
        /// </summary>
        /// <param name="copyCommand">A COPY FROM STDIN or COPY TO STDIN SQL command</param>
        /// <returns>A <see cref="NpgsqlRawCopyStream"/> that can be used to read or write raw binary data.</returns>
        /// <remarks>
        /// See http://www.postgresql.org/docs/current/static/sql-copy.html.
        /// </remarks>
        public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand)
        {
            if (copyCommand == null)
            {
                throw new ArgumentNullException("copyCommand");
            }
            if (!copyCommand.TrimStart().ToUpper().StartsWith("COPY"))
            {
                throw new ArgumentException("Must contain a COPY IN command!", "copyCommand");
            }
            Contract.EndContractBlock();

            CheckConnectionOpen();
            Connector.CheckReadyState();

            var stream = new NpgsqlRawCopyStream(Connector, copyCommand);

            if (!stream.IsBinary)
            {
                throw new ArgumentException("copyToCommand triggered a text transfer, only binary is allowed", "copyCommand");
            }
            return(stream);
        }
コード例 #5
0
ファイル: NpgsqlRawCopyStream.cs プロジェクト: Emill/Npgsql
 internal NpgsqlCopyTextReader(NpgsqlRawCopyStream underlying) : base(underlying)
 {
     if (underlying.IsBinary)
         throw new Exception("Can't use a binary copy stream for text reading");
     Contract.EndContractBlock();
 }