Class: PG::CopyCoder
- Defined in:
- ext/pg_copy_coder.c,
lib/pg/coder.rb,
ext/pg_copy_coder.c
Overview
This is the base class for all type cast classes for COPY data,
Direct Known Subclasses
Constant Summary
Constants inherited from Coder
PG::Coder::FORMAT_ERROR_MASK, PG::Coder::FORMAT_ERROR_TO_PARTIAL, PG::Coder::FORMAT_ERROR_TO_RAISE, PG::Coder::FORMAT_ERROR_TO_STRING, PG::Coder::TIMESTAMP_APP_LOCAL, PG::Coder::TIMESTAMP_APP_UTC, PG::Coder::TIMESTAMP_DB_LOCAL, PG::Coder::TIMESTAMP_DB_UTC
Instance Attribute Summary
Attributes inherited from Coder
Instance Method Summary collapse
-
#delimiter ⇒ String
The character that separates columns within each row (line) of the file.
-
#delimiter=(String) ⇒ Object
Specifies the character that separates columns within each row (line) of the file.
-
#null_string ⇒ Object
The string that represents a null value.
-
#null_string=(null_string) ⇒ Object
Specifies the string that represents a null value.
- #to_h ⇒ Object
-
#type_map ⇒ PG::TypeMap
The PG::TypeMap that will be used for encoding and decoding of columns.
-
#type_map=(map) ⇒ Object
Defines how single columns are encoded or decoded.
Methods inherited from Coder
#==, #dup, #flags, #flags=, #format, #format=, #initialize, #inspect, #inspect_short, #marshal_dump, #marshal_load, #oid, #oid=
Constructor Details
This class inherits a constructor from PG::Coder
Instance Method Details
#delimiter ⇒ String
The character that separates columns within each row (line) of the file.
79 80 81 82 83 84 |
# File 'ext/pg_copy_coder.c', line 79 static VALUE pg_copycoder_delimiter_get(VALUE self) { t_pg_copycoder *this = DATA_PTR(self); return rb_str_new(&this->delimiter, 1); } |
#delimiter=(String) ⇒ Object
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.
62 63 64 65 66 67 68 69 70 71 |
# File 'ext/pg_copy_coder.c', line 62 static VALUE pg_copycoder_delimiter_set(VALUE self, VALUE delimiter) { t_pg_copycoder *this = DATA_PTR(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; } |
#null_string ⇒ Object
The string that represents a null value.
104 105 106 107 108 109 |
# File 'ext/pg_copy_coder.c', line 104 static VALUE pg_copycoder_null_string_get(VALUE self) { t_pg_copycoder *this = DATA_PTR(self); return this->null_string; } |
#null_string=(null_string) ⇒ Object
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.
92 93 94 95 96 97 98 99 |
# File 'ext/pg_copy_coder.c', line 92 static VALUE pg_copycoder_null_string_set(VALUE self, VALUE null_string) { t_pg_copycoder *this = DATA_PTR(self); StringValue(null_string); this->null_string = null_string; return null_string; } |
#to_h ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/pg/coder.rb', line 88 def to_h super.merge!({ type_map: type_map, delimiter: delimiter, null_string: null_string, }) end |
#type_map ⇒ PG::TypeMap
The PG::TypeMap that will be used for encoding and decoding of columns.
142 143 144 145 146 147 148 |
# File 'ext/pg_copy_coder.c', line 142 static VALUE pg_copycoder_type_map_get(VALUE self) { t_pg_copycoder *this = DATA_PTR( self ); return this->typemap; } |
#type_map=(map) ⇒ Object
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.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'ext/pg_copy_coder.c', line 122 static VALUE pg_copycoder_type_map_set(VALUE self, VALUE type_map) { t_pg_copycoder *this = DATA_PTR( 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; } |