PG::

CopyCoder

class
Superclass
PG::Coder

This is the base class for all type cast classes for COPY data,

Public Instance Methods

anchor
delimiter → String

The character that separates columns within each row (line) of the file.

static VALUE
pg_copycoder_delimiter_get(VALUE self)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA(self);
        return rb_str_new(&this->delimiter, 1);
}
anchor
delimiter = String

Specifies the character that separates columns within each row (line) of the file. The default is a tab character in text format, a comma in CSV format. This must be a single one-byte character. This option is ignored when using binary format.

static VALUE
pg_copycoder_delimiter_set(VALUE self, VALUE delimiter)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA(self);
        StringValue(delimiter);
        if(RSTRING_LEN(delimiter) != 1)
                rb_raise( rb_eArgError, "delimiter size must be one byte");
        this->delimiter = *RSTRING_PTR(delimiter);
        return delimiter;
}
anchor
null_string()

The string that represents a null value.

static VALUE
pg_copycoder_null_string_get(VALUE self)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA(self);
        return this->null_string;
}
anchor
null_string=(p1)

Specifies the string that represents a null value. The default is \N (backslash-N) in text format, and an unquoted empty string in CSV format. You might prefer an empty string even in text format for cases where you don’t want to distinguish nulls from empty strings. This option is ignored when using binary format.

static VALUE
pg_copycoder_null_string_set(VALUE self, VALUE null_string)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA(self);
        StringValue(null_string);
        this->null_string = null_string;
        return null_string;
}
anchor
to_h()
# File lib/pg/coder.rb, line 87
def to_h
        super.merge!({
                type_map: type_map,
                delimiter: delimiter,
                null_string: null_string,
        })
end
anchor
type_map → PG::TypeMap

The PG::TypeMap that will be used for encoding and decoding of columns.

static VALUE
pg_copycoder_type_map_get(VALUE self)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA( self );

        return this->typemap;
}
anchor
type_map = map

Defines how single columns are encoded or decoded. map must be a kind of PG::TypeMap .

Defaults to a PG::TypeMapAllStrings , so that PG::TextEncoder::String respectively PG::TextDecoder::String is used for encoding/decoding of each column.

static VALUE
pg_copycoder_type_map_set(VALUE self, VALUE type_map)
{
        t_pg_copycoder *this = RTYPEDDATA_DATA( self );

        if ( !rb_obj_is_kind_of(type_map, rb_cTypeMap) ){
                rb_raise( rb_eTypeError, "wrong elements type %s (expected some kind of PG::TypeMap)",
                                rb_obj_classname( type_map ) );
        }
        this->typemap = type_map;

        return type_map;
}