pg 0.18.0 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/BSDL +2 -2
  4. data/ChangeLog +1221 -4
  5. data/History.rdoc +200 -0
  6. data/Manifest.txt +5 -18
  7. data/README-Windows.rdoc +15 -26
  8. data/README.rdoc +27 -10
  9. data/Rakefile +33 -24
  10. data/Rakefile.cross +57 -39
  11. data/ext/errorcodes.def +37 -0
  12. data/ext/errorcodes.rb +1 -1
  13. data/ext/errorcodes.txt +16 -1
  14. data/ext/extconf.rb +29 -35
  15. data/ext/gvl_wrappers.c +4 -0
  16. data/ext/gvl_wrappers.h +27 -39
  17. data/ext/pg.c +27 -53
  18. data/ext/pg.h +66 -83
  19. data/ext/pg_binary_decoder.c +75 -6
  20. data/ext/pg_binary_encoder.c +14 -12
  21. data/ext/pg_coder.c +83 -13
  22. data/ext/pg_connection.c +627 -351
  23. data/ext/pg_copy_coder.c +44 -9
  24. data/ext/pg_result.c +364 -134
  25. data/ext/pg_text_decoder.c +605 -46
  26. data/ext/pg_text_encoder.c +95 -76
  27. data/ext/pg_tuple.c +541 -0
  28. data/ext/pg_type_map.c +20 -13
  29. data/ext/pg_type_map_by_column.c +7 -7
  30. data/ext/pg_type_map_by_mri_type.c +2 -2
  31. data/ext/pg_type_map_in_ruby.c +4 -7
  32. data/ext/util.c +7 -7
  33. data/ext/util.h +3 -3
  34. data/lib/pg/basic_type_mapping.rb +105 -45
  35. data/lib/pg/binary_decoder.rb +22 -0
  36. data/lib/pg/coder.rb +1 -1
  37. data/lib/pg/connection.rb +109 -39
  38. data/lib/pg/constants.rb +1 -1
  39. data/lib/pg/exceptions.rb +1 -1
  40. data/lib/pg/result.rb +11 -6
  41. data/lib/pg/text_decoder.rb +25 -20
  42. data/lib/pg/text_encoder.rb +43 -1
  43. data/lib/pg/tuple.rb +30 -0
  44. data/lib/pg/type_map_by_column.rb +1 -1
  45. data/lib/pg.rb +21 -11
  46. data/spec/helpers.rb +50 -25
  47. data/spec/pg/basic_type_mapping_spec.rb +287 -30
  48. data/spec/pg/connection_spec.rb +695 -282
  49. data/spec/pg/connection_sync_spec.rb +41 -0
  50. data/spec/pg/result_spec.rb +59 -17
  51. data/spec/pg/tuple_spec.rb +280 -0
  52. data/spec/pg/type_map_by_class_spec.rb +3 -3
  53. data/spec/pg/type_map_by_column_spec.rb +1 -1
  54. data/spec/pg/type_map_by_mri_type_spec.rb +2 -2
  55. data/spec/pg/type_map_by_oid_spec.rb +1 -1
  56. data/spec/pg/type_map_in_ruby_spec.rb +1 -1
  57. data/spec/pg/type_map_spec.rb +1 -1
  58. data/spec/pg/type_spec.rb +319 -35
  59. data/spec/pg_spec.rb +2 -2
  60. data.tar.gz.sig +0 -0
  61. metadata +68 -68
  62. metadata.gz.sig +0 -0
  63. data/sample/array_insert.rb +0 -20
  64. data/sample/async_api.rb +0 -106
  65. data/sample/async_copyto.rb +0 -39
  66. data/sample/async_mixed.rb +0 -56
  67. data/sample/check_conn.rb +0 -21
  68. data/sample/copyfrom.rb +0 -81
  69. data/sample/copyto.rb +0 -19
  70. data/sample/cursor.rb +0 -21
  71. data/sample/disk_usage_report.rb +0 -186
  72. data/sample/issue-119.rb +0 -94
  73. data/sample/losample.rb +0 -69
  74. data/sample/minimal-testcase.rb +0 -17
  75. data/sample/notify_wait.rb +0 -72
  76. data/sample/pg_statistics.rb +0 -294
  77. data/sample/replication_monitor.rb +0 -231
  78. data/sample/test_binary_values.rb +0 -33
  79. data/sample/wal_shipper.rb +0 -434
  80. data/sample/warehouse_partitions.rb +0 -320
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg_text_encoder.c - PG::TextEncoder module
3
- * $Id: pg_text_encoder.c,v 1a13e7eafeb7 2014/12/12 20:57:39 lars $
3
+ * $Id: pg_text_encoder.c,v e57f6b452eb3 2018/08/18 10:58:52 lars $
4
4
  *
5
5
  */
6
6
 
@@ -28,6 +28,7 @@
28
28
  * intermediate - Pointer to a VALUE that might be set by the encoding function to some
29
29
  * value in the first call that can be retrieved later in the second call.
30
30
  * This VALUE is not yet initialized by the caller.
31
+ * enc_idx - Index of the output Encoding that strings should be converted to.
31
32
  *
32
33
  * Returns:
33
34
  * >= 0 - If out==NULL the encoder function must return the expected output buffer size.
@@ -41,14 +42,16 @@
41
42
 
42
43
  #include "pg.h"
43
44
  #include "util.h"
45
+ #ifdef HAVE_INTTYPES_H
44
46
  #include <inttypes.h>
47
+ #endif
45
48
  #include <math.h>
46
49
 
47
50
  VALUE rb_mPG_TextEncoder;
48
51
  static ID s_id_encode;
49
52
  static ID s_id_to_i;
50
53
 
51
- static int pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate);
54
+ static int pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx);
52
55
 
53
56
  VALUE
54
57
  pg_obj_to_i( VALUE value )
@@ -74,7 +77,7 @@ pg_obj_to_i( VALUE value )
74
77
  *
75
78
  */
76
79
  static int
77
- pg_text_enc_boolean(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate)
80
+ pg_text_enc_boolean(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx)
78
81
  {
79
82
  switch( TYPE(value) ){
80
83
  case T_FALSE:
@@ -92,10 +95,10 @@ pg_text_enc_boolean(t_pg_coder *this, VALUE value, char *out, VALUE *intermediat
92
95
  if(out) *out = '1';
93
96
  return 1;
94
97
  } else {
95
- return pg_text_enc_integer(this, value, out, intermediate);
98
+ return pg_text_enc_integer(this, value, out, intermediate, enc_idx);
96
99
  }
97
100
  default:
98
- return pg_coder_enc_to_s(this, value, out, intermediate);
101
+ return pg_coder_enc_to_s(this, value, out, intermediate, enc_idx);
99
102
  }
100
103
  /* never reached */
101
104
  return 0;
@@ -111,9 +114,14 @@ pg_text_enc_boolean(t_pg_coder *this, VALUE value, char *out, VALUE *intermediat
111
114
  *
112
115
  */
113
116
  int
114
- pg_coder_enc_to_s(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate)
117
+ pg_coder_enc_to_s(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx)
115
118
  {
116
- *intermediate = rb_obj_as_string(value);
119
+ VALUE str = rb_obj_as_string(value);
120
+ if( ENCODING_GET(str) == enc_idx ){
121
+ *intermediate = str;
122
+ }else{
123
+ *intermediate = rb_str_export_to_enc(str, rb_enc_from_index(enc_idx));
124
+ }
117
125
  return -1;
118
126
  }
119
127
 
@@ -127,11 +135,11 @@ pg_coder_enc_to_s(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate)
127
135
  *
128
136
  */
129
137
  static int
130
- pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate)
138
+ pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx)
131
139
  {
132
140
  if(out){
133
141
  if(TYPE(*intermediate) == T_STRING){
134
- return pg_coder_enc_to_s(this, value, out, intermediate);
142
+ return pg_coder_enc_to_s(this, value, out, intermediate, enc_idx);
135
143
  }else{
136
144
  char *start = out;
137
145
  int len;
@@ -204,13 +212,13 @@ pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediat
204
212
  if( ll < 100000000000000LL ){
205
213
  len = ll < 10000000000000LL ? 13 : 14;
206
214
  }else{
207
- return pg_coder_enc_to_s(this, *intermediate, NULL, intermediate);
215
+ return pg_coder_enc_to_s(this, *intermediate, NULL, intermediate, enc_idx);
208
216
  }
209
217
  }
210
218
  }
211
219
  return sll < 0 ? len+1 : len;
212
220
  }else{
213
- return pg_coder_enc_to_s(this, *intermediate, NULL, intermediate);
221
+ return pg_coder_enc_to_s(this, *intermediate, NULL, intermediate, enc_idx);
214
222
  }
215
223
  }
216
224
  }
@@ -223,7 +231,7 @@ pg_text_enc_integer(t_pg_coder *this, VALUE value, char *out, VALUE *intermediat
223
231
  *
224
232
  */
225
233
  static int
226
- pg_text_enc_float(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
234
+ pg_text_enc_float(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
227
235
  {
228
236
  if(out){
229
237
  double dvalue = NUM2DBL(value);
@@ -263,7 +271,7 @@ static const char hextab[] = {
263
271
  *
264
272
  */
265
273
  static int
266
- pg_text_enc_bytea(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
274
+ pg_text_enc_bytea(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
267
275
  {
268
276
  if(out){
269
277
  size_t strlen = RSTRING_LEN(*intermediate);
@@ -299,7 +307,7 @@ quote_array_buffer( void *_this, char *p_in, int strlen, char *p_out ){
299
307
  /* count data plus backslashes; detect chars needing quotes */
300
308
  if (strlen == 0)
301
309
  needquote = 1; /* force quotes for empty string */
302
- else if (strlen == 4 && pg_strncasecmp(p_in, "NULL", strlen) == 0)
310
+ else if (strlen == 4 && rbpg_strncasecmp(p_in, "NULL", strlen) == 0)
303
311
  needquote = 1; /* force quotes for literal NULL */
304
312
  else
305
313
  needquote = 0;
@@ -342,13 +350,13 @@ quote_array_buffer( void *_this, char *p_in, int strlen, char *p_out ){
342
350
  }
343
351
 
344
352
  static char *
345
- quote_string(t_pg_coder *this, VALUE value, VALUE string, char *current_out, int with_quote, t_quote_func quote_buffer, void *func_data)
353
+ quote_string(t_pg_coder *this, VALUE value, VALUE string, char *current_out, int with_quote, t_quote_func quote_buffer, void *func_data, int enc_idx)
346
354
  {
347
355
  int strlen;
348
356
  VALUE subint;
349
357
  t_pg_coder_enc_func enc_func = pg_coder_enc_func(this);
350
358
 
351
- strlen = enc_func(this, value, NULL, &subint);
359
+ strlen = enc_func(this, value, NULL, &subint, enc_idx);
352
360
 
353
361
  if( strlen == -1 ){
354
362
  /* we can directly use String value in subint */
@@ -374,20 +382,20 @@ quote_string(t_pg_coder *this, VALUE value, VALUE string, char *current_out, int
374
382
  current_out = pg_rb_str_ensure_capa( string, 2 * strlen + 2, current_out, NULL );
375
383
 
376
384
  /* Place the unescaped string at current output position. */
377
- strlen = enc_func(this, value, current_out, &subint);
385
+ strlen = enc_func(this, value, current_out, &subint, enc_idx);
378
386
 
379
387
  current_out += quote_buffer( func_data, current_out, strlen, current_out );
380
388
  }else{
381
389
  /* size of the unquoted string */
382
390
  current_out = pg_rb_str_ensure_capa( string, strlen, current_out, NULL );
383
- current_out += enc_func(this, value, current_out, &subint);
391
+ current_out += enc_func(this, value, current_out, &subint, enc_idx);
384
392
  }
385
393
  }
386
394
  return current_out;
387
395
  }
388
396
 
389
397
  static char *
390
- write_array(t_pg_composite_coder *this, VALUE value, char *current_out, VALUE string, int quote)
398
+ write_array(t_pg_composite_coder *this, VALUE value, char *current_out, VALUE string, int quote, int enc_idx)
391
399
  {
392
400
  int i;
393
401
 
@@ -405,7 +413,7 @@ write_array(t_pg_composite_coder *this, VALUE value, char *current_out, VALUE st
405
413
 
406
414
  switch(TYPE(entry)){
407
415
  case T_ARRAY:
408
- current_out = write_array(this, entry, current_out, string, quote);
416
+ current_out = write_array(this, entry, current_out, string, quote, enc_idx);
409
417
  break;
410
418
  case T_NIL:
411
419
  current_out = pg_rb_str_ensure_capa( string, 4, current_out, NULL );
@@ -415,7 +423,7 @@ write_array(t_pg_composite_coder *this, VALUE value, char *current_out, VALUE st
415
423
  *current_out++ = 'L';
416
424
  break;
417
425
  default:
418
- current_out = quote_string( this->elem, entry, string, current_out, quote, quote_array_buffer, this );
426
+ current_out = quote_string( this->elem, entry, string, current_out, quote, quote_array_buffer, this, enc_idx );
419
427
  }
420
428
  }
421
429
  current_out = pg_rb_str_ensure_capa( string, 1, current_out, NULL );
@@ -437,57 +445,53 @@ write_array(t_pg_composite_coder *this, VALUE value, char *current_out, VALUE st
437
445
  *
438
446
  */
439
447
  static int
440
- pg_text_enc_array(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
448
+ pg_text_enc_array(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
441
449
  {
442
450
  char *end_ptr;
443
451
  t_pg_composite_coder *this = (t_pg_composite_coder *)conv;
444
452
 
445
453
  if( TYPE(value) == T_ARRAY){
446
- *intermediate = rb_str_new(NULL, 0);
454
+ VALUE out_str = rb_str_new(NULL, 0);
455
+ PG_ENCODING_SET_NOCHECK(out_str, enc_idx);
447
456
 
448
- end_ptr = write_array(this, value, RSTRING_PTR(*intermediate), *intermediate, this->needs_quotation);
457
+ end_ptr = write_array(this, value, RSTRING_PTR(out_str), out_str, this->needs_quotation, enc_idx);
449
458
 
450
- rb_str_set_len( *intermediate, end_ptr - RSTRING_PTR(*intermediate) );
459
+ rb_str_set_len( out_str, end_ptr - RSTRING_PTR(out_str) );
460
+ *intermediate = out_str;
451
461
 
452
462
  return -1;
453
463
  } else {
454
- return pg_coder_enc_to_s( conv, value, out, intermediate );
464
+ return pg_coder_enc_to_s( conv, value, out, intermediate, enc_idx );
455
465
  }
456
466
  }
457
467
 
458
- static int
459
- quote_identifier_buffer( void *_this, char *p_in, int strlen, char *p_out ){
460
- char *ptr1;
461
- char *ptr2;
462
- int backslashs = 0;
463
-
464
- /* count required backlashs */
465
- for(ptr1 = p_in; ptr1 != p_in + strlen; ptr1++) {
466
- if (*ptr1 == '"'){
467
- backslashs++;
468
+ static char *
469
+ quote_identifier( VALUE value, VALUE out_string, char *current_out ){
470
+ char *p_in = RSTRING_PTR(value);
471
+ size_t strlen = RSTRING_LEN(value);
472
+ char *p_inend = p_in + strlen;
473
+ char *end_capa = current_out;
474
+
475
+ PG_RB_STR_ENSURE_CAPA( out_string, strlen + 2, current_out, end_capa );
476
+ *current_out++ = '"';
477
+ for(; p_in != p_inend; p_in++) {
478
+ char c = *p_in;
479
+ if (c == '"'){
480
+ PG_RB_STR_ENSURE_CAPA( out_string, p_inend - p_in + 2, current_out, end_capa );
481
+ *current_out++ = '"';
482
+ } else if (c == 0){
483
+ rb_raise(rb_eArgError, "string contains null byte");
468
484
  }
485
+ *current_out++ = c;
469
486
  }
487
+ PG_RB_STR_ENSURE_CAPA( out_string, 1, current_out, end_capa );
488
+ *current_out++ = '"';
470
489
 
471
- ptr1 = p_in + strlen;
472
- ptr2 = p_out + strlen + backslashs + 2;
473
- /* Write end quote */
474
- *--ptr2 = '"';
475
-
476
- /* Then store the escaped string on the final position, walking
477
- * right to left, until all backslashs are placed. */
478
- while( ptr1 != p_in ) {
479
- *--ptr2 = *--ptr1;
480
- if(*ptr2 == '"'){
481
- *--ptr2 = '"';
482
- }
483
- }
484
- /* Write start quote */
485
- *p_out = '"';
486
- return strlen + backslashs + 2;
490
+ return current_out;
487
491
  }
488
492
 
489
493
  static char *
490
- pg_text_enc_array_identifier(t_pg_composite_coder *this, VALUE value, VALUE string, char *out)
494
+ pg_text_enc_array_identifier(VALUE value, VALUE string, char *out, int enc_idx)
491
495
  {
492
496
  int i;
493
497
  int nr_elems;
@@ -498,7 +502,11 @@ pg_text_enc_array_identifier(t_pg_composite_coder *this, VALUE value, VALUE stri
498
502
  for( i=0; i<nr_elems; i++){
499
503
  VALUE entry = rb_ary_entry(value, i);
500
504
 
501
- out = quote_string(this->elem, entry, string, out, this->needs_quotation, quote_identifier_buffer, this);
505
+ StringValue(entry);
506
+ if( ENCODING_GET(entry) != enc_idx ){
507
+ entry = rb_str_export_to_enc(entry, rb_enc_from_index(enc_idx));
508
+ }
509
+ out = quote_identifier(entry, string, out);
502
510
  if( i < nr_elems-1 ){
503
511
  out = pg_rb_str_ensure_capa( string, 1, out, NULL );
504
512
  *out++ = '.';
@@ -508,29 +516,37 @@ pg_text_enc_array_identifier(t_pg_composite_coder *this, VALUE value, VALUE stri
508
516
  }
509
517
 
510
518
  /*
511
- * Document-class: PG::TextEncoder::Identifier < PG::CompositeEncoder
519
+ * Document-class: PG::TextEncoder::Identifier < PG::SimpleEncoder
512
520
  *
513
521
  * This is the encoder class for PostgreSQL identifiers.
514
522
  *
515
523
  * An Array value can be used for "schema.table.column" type identifiers:
516
524
  * PG::TextEncoder::Identifier.new.encode(['schema', 'table', 'column'])
517
- * => "schema"."table"."column"
525
+ * => '"schema"."table"."column"'
518
526
  *
527
+ * This encoder can also be used per PG::Connection#quote_ident .
519
528
  */
520
- static int
521
- pg_text_enc_identifier(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
529
+ int
530
+ pg_text_enc_identifier(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx)
522
531
  {
523
- t_pg_composite_coder *this = (t_pg_composite_coder *)conv;
524
-
525
- *intermediate = rb_str_new(NULL, 0);
526
- out = RSTRING_PTR(*intermediate);
527
-
532
+ VALUE out_str;
533
+ UNUSED( this );
528
534
  if( TYPE(value) == T_ARRAY){
529
- out = pg_text_enc_array_identifier(this, value, *intermediate, out);
535
+ out_str = rb_str_new(NULL, 0);
536
+ out = RSTRING_PTR(out_str);
537
+ out = pg_text_enc_array_identifier(value, out_str, out, enc_idx);
530
538
  } else {
531
- out = quote_string(this->elem, value, *intermediate, out, this->needs_quotation, quote_identifier_buffer, this);
539
+ StringValue(value);
540
+ if( ENCODING_GET(value) != enc_idx ){
541
+ value = rb_str_export_to_enc(value, rb_enc_from_index(enc_idx));
542
+ }
543
+ out_str = rb_str_new(NULL, RSTRING_LEN(value) + 2);
544
+ out = RSTRING_PTR(out_str);
545
+ out = quote_identifier(value, out_str, out);
532
546
  }
533
- rb_str_set_len( *intermediate, out - RSTRING_PTR(*intermediate) );
547
+ rb_str_set_len( out_str, out - RSTRING_PTR(out_str) );
548
+ PG_ENCODING_SET_NOCHECK(out_str, enc_idx);
549
+ *intermediate = out_str;
534
550
  return -1;
535
551
  }
536
552
 
@@ -576,14 +592,16 @@ quote_literal_buffer( void *_this, char *p_in, int strlen, char *p_out ){
576
592
  *
577
593
  */
578
594
  static int
579
- pg_text_enc_quoted_literal(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
595
+ pg_text_enc_quoted_literal(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
580
596
  {
581
597
  t_pg_composite_coder *this = (t_pg_composite_coder *)conv;
598
+ VALUE out_str = rb_str_new(NULL, 0);
599
+ PG_ENCODING_SET_NOCHECK(out_str, enc_idx);
582
600
 
583
- *intermediate = rb_str_new(NULL, 0);
584
- out = RSTRING_PTR(*intermediate);
585
- out = quote_string(this->elem, value, *intermediate, out, this->needs_quotation, quote_literal_buffer, this);
586
- rb_str_set_len( *intermediate, out - RSTRING_PTR(*intermediate) );
601
+ out = RSTRING_PTR(out_str);
602
+ out = quote_string(this->elem, value, out_str, out, this->needs_quotation, quote_literal_buffer, this, enc_idx);
603
+ rb_str_set_len( out_str, out - RSTRING_PTR(out_str) );
604
+ *intermediate = out_str;
587
605
  return -1;
588
606
  }
589
607
 
@@ -594,7 +612,7 @@ pg_text_enc_quoted_literal(t_pg_coder *conv, VALUE value, char *out, VALUE *inte
594
612
  *
595
613
  */
596
614
  static int
597
- pg_text_enc_to_base64(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate)
615
+ pg_text_enc_to_base64(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
598
616
  {
599
617
  int strlen;
600
618
  VALUE subint;
@@ -603,13 +621,13 @@ pg_text_enc_to_base64(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedi
603
621
 
604
622
  if(out){
605
623
  /* Second encoder pass, if required */
606
- strlen = enc_func(this->elem, value, out, intermediate);
624
+ strlen = enc_func(this->elem, value, out, intermediate, enc_idx);
607
625
  base64_encode( out, out, strlen );
608
626
 
609
627
  return BASE64_ENCODED_SIZE(strlen);
610
628
  } else {
611
629
  /* First encoder pass */
612
- strlen = enc_func(this->elem, value, NULL, &subint);
630
+ strlen = enc_func(this->elem, value, NULL, &subint, enc_idx);
613
631
 
614
632
  if( strlen == -1 ){
615
633
  /* Encoded string is returned in subint */
@@ -617,6 +635,7 @@ pg_text_enc_to_base64(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedi
617
635
 
618
636
  strlen = RSTRING_LENINT(subint);
619
637
  out_str = rb_str_new(NULL, BASE64_ENCODED_SIZE(strlen));
638
+ PG_ENCODING_SET_NOCHECK(out_str, enc_idx);
620
639
 
621
640
  base64_encode( RSTRING_PTR(out_str), RSTRING_PTR(subint), strlen);
622
641
  *intermediate = out_str;
@@ -651,11 +670,11 @@ init_pg_text_encoder()
651
670
  pg_define_coder( "String", pg_coder_enc_to_s, rb_cPG_SimpleEncoder, rb_mPG_TextEncoder );
652
671
  /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "Bytea", rb_cPG_SimpleEncoder ); */
653
672
  pg_define_coder( "Bytea", pg_text_enc_bytea, rb_cPG_SimpleEncoder, rb_mPG_TextEncoder );
673
+ /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "Identifier", rb_cPG_SimpleEncoder ); */
674
+ pg_define_coder( "Identifier", pg_text_enc_identifier, rb_cPG_SimpleEncoder, rb_mPG_TextEncoder );
654
675
 
655
676
  /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "Array", rb_cPG_CompositeEncoder ); */
656
677
  pg_define_coder( "Array", pg_text_enc_array, rb_cPG_CompositeEncoder, rb_mPG_TextEncoder );
657
- /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "Identifier", rb_cPG_CompositeEncoder ); */
658
- pg_define_coder( "Identifier", pg_text_enc_identifier, rb_cPG_CompositeEncoder, rb_mPG_TextEncoder );
659
678
  /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "QuotedLiteral", rb_cPG_CompositeEncoder ); */
660
679
  pg_define_coder( "QuotedLiteral", pg_text_enc_quoted_literal, rb_cPG_CompositeEncoder, rb_mPG_TextEncoder );
661
680
  /* dummy = rb_define_class_under( rb_mPG_TextEncoder, "ToBase64", rb_cPG_CompositeEncoder ); */