示例#1
0
        /// <summary>
        /// Begins a textual COPY FROM STDIN operation, a data import mechanism to a PostgreSQL table.
        /// It is the user's responsibility to send the textual input according to the format specified
        /// in <paramref name="copyFromCommand"/>.
        /// </summary>
        /// <param name="copyFromCommand">A COPY FROM STDIN SQL command</param>
        /// <returns>
        /// A TextWriter that can be used to send textual data.</returns>
        /// <remarks>
        /// See http://www.postgresql.org/docs/current/static/sql-copy.html.
        /// </remarks>
        public TextWriter BeginTextImport(string copyFromCommand)
        {
            if (copyFromCommand == null)
            {
                throw new ArgumentNullException("copyFromCommand");
            }
            if (!copyFromCommand.TrimStart().ToUpper().StartsWith("COPY"))
            {
                throw new ArgumentException("Must contain a COPY IN command!", "copyFromCommand");
            }
            Contract.EndContractBlock();

            CheckConnectionOpen();
            Connector.StartUserAction(ConnectorState.Copy);
            var writer = new NpgsqlCopyTextWriter(new NpgsqlRawCopyStream(Connector, copyFromCommand));

            Connector.CurrentCopyOperation = writer;
            return(writer);
        }
 public NpgsqlCopyTextWriterWrapper(NpgsqlCopyTextWriter writer)
 {
     this.writer = writer;
 }