pg 0.18.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/BSDL +2 -2
- data/ChangeLog +798 -7
- data/History.rdoc +96 -0
- data/Manifest.txt +0 -18
- data/README.rdoc +16 -11
- data/Rakefile +31 -24
- data/Rakefile.cross +21 -24
- data/ext/errorcodes.def +33 -0
- data/ext/errorcodes.txt +15 -1
- data/ext/extconf.rb +22 -33
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +27 -39
- data/ext/pg.c +18 -50
- data/ext/pg.h +13 -80
- data/ext/pg_binary_decoder.c +3 -1
- data/ext/pg_binary_encoder.c +14 -12
- data/ext/pg_coder.c +31 -10
- data/ext/pg_connection.c +340 -225
- data/ext/pg_copy_coder.c +34 -4
- data/ext/pg_result.c +24 -22
- data/ext/pg_text_decoder.c +3 -1
- data/ext/pg_text_encoder.c +65 -42
- data/ext/pg_type_map.c +20 -13
- data/ext/pg_type_map_by_column.c +7 -7
- data/lib/pg/basic_type_mapping.rb +35 -8
- data/lib/pg/connection.rb +53 -12
- data/lib/pg/result.rb +10 -5
- data/lib/pg/text_decoder.rb +7 -0
- data/lib/pg/text_encoder.rb +8 -0
- data/lib/pg.rb +18 -10
- data/spec/helpers.rb +8 -15
- data/spec/pg/basic_type_mapping_spec.rb +54 -0
- data/spec/pg/connection_spec.rb +390 -209
- data/spec/pg/result_spec.rb +14 -7
- data/spec/pg/type_map_by_class_spec.rb +2 -2
- data/spec/pg/type_map_by_mri_type_spec.rb +1 -1
- data/spec/pg/type_spec.rb +90 -3
- data/spec/pg_spec.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +56 -69
- metadata.gz.sig +0 -0
- data/sample/array_insert.rb +0 -20
- data/sample/async_api.rb +0 -106
- data/sample/async_copyto.rb +0 -39
- data/sample/async_mixed.rb +0 -56
- data/sample/check_conn.rb +0 -21
- data/sample/copyfrom.rb +0 -81
- data/sample/copyto.rb +0 -19
- data/sample/cursor.rb +0 -21
- data/sample/disk_usage_report.rb +0 -186
- data/sample/issue-119.rb +0 -94
- data/sample/losample.rb +0 -69
- data/sample/minimal-testcase.rb +0 -17
- data/sample/notify_wait.rb +0 -72
- data/sample/pg_statistics.rb +0 -294
- data/sample/replication_monitor.rb +0 -231
- data/sample/test_binary_values.rb +0 -33
- data/sample/wal_shipper.rb +0 -434
- data/sample/warehouse_partitions.rb +0 -320
data/ext/pg_coder.c
CHANGED
@@ -105,7 +105,7 @@ pg_composite_decoder_allocate( VALUE klass )
|
|
105
105
|
|
106
106
|
/*
|
107
107
|
* call-seq:
|
108
|
-
* coder.encode( value )
|
108
|
+
* coder.encode( value [, encoding] )
|
109
109
|
*
|
110
110
|
* Encodes the given Ruby object into string representation, without
|
111
111
|
* sending data to/from the database server.
|
@@ -114,13 +114,24 @@ pg_composite_decoder_allocate( VALUE klass )
|
|
114
114
|
*
|
115
115
|
*/
|
116
116
|
static VALUE
|
117
|
-
pg_coder_encode(VALUE
|
117
|
+
pg_coder_encode(int argc, VALUE *argv, VALUE self)
|
118
118
|
{
|
119
119
|
VALUE res;
|
120
120
|
VALUE intermediate;
|
121
|
+
VALUE value;
|
121
122
|
int len, len2;
|
123
|
+
int enc_idx;
|
122
124
|
t_pg_coder *this = DATA_PTR(self);
|
123
125
|
|
126
|
+
if(argc < 1 || argc > 2){
|
127
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%i for 1..2)", argc);
|
128
|
+
}else if(argc == 1){
|
129
|
+
enc_idx = rb_ascii8bit_encindex();
|
130
|
+
}else{
|
131
|
+
enc_idx = rb_to_encoding_index(argv[1]);
|
132
|
+
}
|
133
|
+
value = argv[0];
|
134
|
+
|
124
135
|
if( NIL_P(value) )
|
125
136
|
return Qnil;
|
126
137
|
|
@@ -128,7 +139,7 @@ pg_coder_encode(VALUE self, VALUE value)
|
|
128
139
|
rb_raise(rb_eRuntimeError, "no encoder function defined");
|
129
140
|
}
|
130
141
|
|
131
|
-
len = this->enc_func( this, value, NULL, &intermediate );
|
142
|
+
len = this->enc_func( this, value, NULL, &intermediate, enc_idx );
|
132
143
|
|
133
144
|
if( len == -1 ){
|
134
145
|
/* The intermediate value is a String that can be used directly. */
|
@@ -137,7 +148,8 @@ pg_coder_encode(VALUE self, VALUE value)
|
|
137
148
|
}
|
138
149
|
|
139
150
|
res = rb_str_new(NULL, len);
|
140
|
-
|
151
|
+
PG_ENCODING_SET_NOCHECK(res, enc_idx);
|
152
|
+
len2 = this->enc_func( this, value, RSTRING_PTR(res), &intermediate, enc_idx );
|
141
153
|
if( len < len2 ){
|
142
154
|
rb_bug("%s: result length of first encoder run (%i) is less than second run (%i)",
|
143
155
|
rb_obj_classname( self ), len, len2 );
|
@@ -165,8 +177,8 @@ static VALUE
|
|
165
177
|
pg_coder_decode(int argc, VALUE *argv, VALUE self)
|
166
178
|
{
|
167
179
|
char *val;
|
168
|
-
|
169
|
-
|
180
|
+
int tuple = -1;
|
181
|
+
int field = -1;
|
170
182
|
VALUE res;
|
171
183
|
t_pg_coder *this = DATA_PTR(self);
|
172
184
|
|
@@ -359,10 +371,19 @@ pg_define_coder( const char *name, void *func, VALUE base_klass, VALUE nsp )
|
|
359
371
|
|
360
372
|
|
361
373
|
static int
|
362
|
-
pg_text_enc_in_ruby(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
|
374
|
+
pg_text_enc_in_ruby(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
|
363
375
|
{
|
364
|
-
|
365
|
-
|
376
|
+
int arity = rb_obj_method_arity(conv->coder_obj, s_id_encode);
|
377
|
+
if( arity == 1 ){
|
378
|
+
VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 1, value );
|
379
|
+
StringValue( out_str );
|
380
|
+
*intermediate = rb_str_export_to_enc(out_str, rb_enc_from_index(enc_idx));
|
381
|
+
}else{
|
382
|
+
VALUE enc = rb_enc_from_encoding(rb_enc_from_index(enc_idx));
|
383
|
+
VALUE out_str = rb_funcall( conv->coder_obj, s_id_encode, 2, value, enc );
|
384
|
+
StringValue( out_str );
|
385
|
+
*intermediate = out_str;
|
386
|
+
}
|
366
387
|
return -1;
|
367
388
|
}
|
368
389
|
|
@@ -442,7 +463,7 @@ init_pg_coder()
|
|
442
463
|
* This accessor is only used in PG::Coder#inspect .
|
443
464
|
*/
|
444
465
|
rb_define_attr( rb_cPG_Coder, "name", 1, 1 );
|
445
|
-
rb_define_method( rb_cPG_Coder, "encode", pg_coder_encode, 1 );
|
466
|
+
rb_define_method( rb_cPG_Coder, "encode", pg_coder_encode, -1 );
|
446
467
|
rb_define_method( rb_cPG_Coder, "decode", pg_coder_decode, -1 );
|
447
468
|
|
448
469
|
/* Document-class: PG::SimpleCoder < PG::Coder */
|