Class: PG::TextEncoder::CopyRow
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
PG::CopyEncoder
|
Defined in: | ext/pg_copy_coder.c |
Overview
This class encodes one row of arbitrary columns for transmission as COPY data in text format. See the COPY command for description of the format.
It is intended to be used in conjunction with Connection#put_copy_data .
The columns are expected as Array
of values. The single values are encoded as defined in the assigned #type_map
. If no type_map was assigned, all values are converted to strings by String
.
Example with default type map ( ::PG::TypeMapAllStrings
):
conn.exec "create table my_table (a text,b int,c bool)"
enco = PG::TextEncoder::CopyRow.new
conn.copy_data "COPY my_table FROM STDIN", enco do
conn.put_copy_data ["astring", 7, false]
conn.put_copy_data ["string2", 42, true]
end
This creates my_table
and inserts two rows.
It is possible to manually assign a type encoder for each column per ::PG::TypeMapByColumn
, or to make use of ::PG::BasicTypeMapBasedOnResult
to assign them based on the table OIDs.
See also ::PG::TextDecoder::CopyRow
for the decoding direction with Connection#get_copy_data . And see ::PG::BinaryEncoder::CopyRow
for an encoder of the COPY binary format.
Constant Summary
::PG::Coder
- Inherited
FORMAT_ERROR_MASK, FORMAT_ERROR_TO_PARTIAL, FORMAT_ERROR_TO_RAISE, FORMAT_ERROR_TO_STRING, TIMESTAMP_APP_LOCAL, TIMESTAMP_APP_UTC, TIMESTAMP_DB_LOCAL, TIMESTAMP_DB_UTC
Class Method Summary
::PG::Coder
- Inherited
.new | Create a new coder object based on the attribute Hash. |
Instance Attribute Summary
::PG::CopyCoder
- Inherited
#delimiter | The character that separates columns within each row (line) of the file. |
#delimiter= | Specifies the character that separates columns within each row (line) of the file. |
#null_string | The string that represents a null value. |
#null_string= | Specifies the string that represents a null value. |
#type_map | The |
#type_map= | Defines how single columns are encoded or decoded. |
::PG::Coder
- Inherited
#flags | Get current bitwise OR-ed coder flags. |
#flags= | Set coder specific bitwise OR-ed flags. |
#format | The format code that is sent alongside with an encoded query parameter value. |
#format= | Specifies the format code that is sent alongside with an encoded query parameter value. |
#name | Name of the coder or the corresponding data type. |
#oid | The type OID that is sent alongside with an encoded query parameter value. |
#oid= | Specifies the type OID that is sent alongside with an encoded query parameter value. |
Instance Method Summary
::PG::CopyCoder
- Inherited
::PG::Coder
- Inherited
#==, #dup, #inspect, #inspect_short, #marshal_dump, #marshal_load, | |
#to_h | Returns coder attributes as Hash. |
Constructor Details
This class inherits a constructor from PG::Coder