pg 0.18.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/BSDL +2 -2
  4. data/ChangeLog +798 -7
  5. data/History.rdoc +96 -0
  6. data/Manifest.txt +0 -18
  7. data/README.rdoc +16 -11
  8. data/Rakefile +31 -24
  9. data/Rakefile.cross +21 -24
  10. data/ext/errorcodes.def +33 -0
  11. data/ext/errorcodes.txt +15 -1
  12. data/ext/extconf.rb +22 -33
  13. data/ext/gvl_wrappers.c +4 -0
  14. data/ext/gvl_wrappers.h +27 -39
  15. data/ext/pg.c +18 -50
  16. data/ext/pg.h +13 -80
  17. data/ext/pg_binary_decoder.c +3 -1
  18. data/ext/pg_binary_encoder.c +14 -12
  19. data/ext/pg_coder.c +31 -10
  20. data/ext/pg_connection.c +340 -225
  21. data/ext/pg_copy_coder.c +34 -4
  22. data/ext/pg_result.c +24 -22
  23. data/ext/pg_text_decoder.c +3 -1
  24. data/ext/pg_text_encoder.c +65 -42
  25. data/ext/pg_type_map.c +20 -13
  26. data/ext/pg_type_map_by_column.c +7 -7
  27. data/lib/pg/basic_type_mapping.rb +35 -8
  28. data/lib/pg/connection.rb +53 -12
  29. data/lib/pg/result.rb +10 -5
  30. data/lib/pg/text_decoder.rb +7 -0
  31. data/lib/pg/text_encoder.rb +8 -0
  32. data/lib/pg.rb +18 -10
  33. data/spec/helpers.rb +8 -15
  34. data/spec/pg/basic_type_mapping_spec.rb +54 -0
  35. data/spec/pg/connection_spec.rb +390 -209
  36. data/spec/pg/result_spec.rb +14 -7
  37. data/spec/pg/type_map_by_class_spec.rb +2 -2
  38. data/spec/pg/type_map_by_mri_type_spec.rb +1 -1
  39. data/spec/pg/type_spec.rb +90 -3
  40. data/spec/pg_spec.rb +1 -1
  41. data.tar.gz.sig +0 -0
  42. metadata +56 -69
  43. metadata.gz.sig +0 -0
  44. data/sample/array_insert.rb +0 -20
  45. data/sample/async_api.rb +0 -106
  46. data/sample/async_copyto.rb +0 -39
  47. data/sample/async_mixed.rb +0 -56
  48. data/sample/check_conn.rb +0 -21
  49. data/sample/copyfrom.rb +0 -81
  50. data/sample/copyto.rb +0 -19
  51. data/sample/cursor.rb +0 -21
  52. data/sample/disk_usage_report.rb +0 -186
  53. data/sample/issue-119.rb +0 -94
  54. data/sample/losample.rb +0 -69
  55. data/sample/minimal-testcase.rb +0 -17
  56. data/sample/notify_wait.rb +0 -72
  57. data/sample/pg_statistics.rb +0 -294
  58. data/sample/replication_monitor.rb +0 -231
  59. data/sample/test_binary_values.rb +0 -33
  60. data/sample/wal_shipper.rb +0 -434
  61. 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 self, VALUE 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
- len2 = this->enc_func( this, value, RSTRING_PTR(res), &intermediate);
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
- VALUE tuple = -1;
169
- VALUE field = -1;
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
- *intermediate = rb_funcall( conv->coder_obj, s_id_encode, 1, value );
365
- StringValue( *intermediate );
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 */