internal void CheckConnectionReady() { if (_disposed) { throw new ObjectDisposedException(typeof(NpgsqlConnection).Name); } if (Connector == null) { throw new InvalidOperationException(L10N.ConnNotOpen); } Connector.CheckReadyState(); }
/// <summary> /// Begins a binary COPY FROM STDIN operation, a high-performance data import mechanism to a PostgreSQL table. /// </summary> /// <param name="copyFromCommand">A COPY FROM STDIN SQL command</param> /// <returns>A <see cref="NpgsqlBinaryImporter"/> which can be used to write rows and columns</returns> /// <remarks> /// See http://www.postgresql.org/docs/current/static/sql-copy.html. /// </remarks> public NpgsqlBinaryImporter BeginBinaryImport(string copyFromCommand) { if (copyFromCommand == null) { throw new ArgumentNullException("copyFromCommand"); } if (!copyFromCommand.TrimStart().ToUpper().StartsWith("COPY")) { throw new ArgumentException("Must contain a COPY FROM STDIN command!", "copyFromCommand"); } Contract.EndContractBlock(); CheckConnectionOpen(); Connector.CheckReadyState(); return(new NpgsqlBinaryImporter(Connector, copyFromCommand)); }
/// <summary> /// Begins a textual COPY FROM STDIN operation, a data import mechanism to a PostgreSQL table. /// It is the user's responsibility to parse the textual input according to the format specified /// in <paramref name="copyToCommand"/>. /// </summary> /// <param name="copyToCommand">A COPY TO STDIN SQL command</param> /// <returns> /// A TextReader that can be used to read textual data.</returns> /// <remarks> /// See http://www.postgresql.org/docs/current/static/sql-copy.html. /// </remarks> public TextReader BeginTextExport(string copyToCommand) { if (copyToCommand == null) { throw new ArgumentNullException("copyToCommand"); } if (!copyToCommand.TrimStart().ToUpper().StartsWith("COPY")) { throw new ArgumentException("Must contain a COPY OUT command!", "copyToCommand"); } Contract.EndContractBlock(); CheckConnectionOpen(); Connector.CheckReadyState(); return(new NpgsqlCopyTextReader(new NpgsqlRawCopyStream(Connector, copyToCommand))); }
/// <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); }