CopyIn

class CopyIn(stream: PgStream) : CopyOperation

A COPY ... FROM STDIN in progress: write chunks with writeToCopy, finish with endCopy.

The connection is in copy mode for the whole of it and will run nothing else, which is what makes the handle single-use — endCopy or cancelCopy ends the transfer and the handle with it, and the next one comes from the CopyManager again.

Errors in the data are the server's to find, and it finds them on its own schedule. What it can check as it reads a row - a value that does not parse, a wrong column count, NOT NULL, CHECK - ends the copy there and then, and the next writeToCopy reports it. Foreign keys are checked when the statement ends, so endCopy reports those, and a duplicate key surfaces when the server writes out the rows it has buffered, which on a small copy is the end as well.

Constructors

Link copied to clipboard
internal constructor(stream: PgStream)

Properties

Link copied to clipboard
open override var isActive: Boolean

Whether the transfer is still in progress, and with it whether the connection is still in copy mode and unusable for ordinary queries.

Functions

Link copied to clipboard
open override fun cancelCopy()

Abandons the transfer and returns the connection to a usable state.

Link copied to clipboard
open override fun close()

Cancels the transfer if it is still running, so use { } cannot leave a connection in copy mode.

Link copied to clipboard
fun endCopy(): Long

Ends the COPY IN operation and returns the number of rows affected.

Link copied to clipboard
fun writeToCopy(data: ByteArray, offset: Int = 0, length: Int = data.size)

Writes a chunk of data to the server.