pg 1.1.0.pre20180730171000 → 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 (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/ChangeLog +6595 -0
  5. data/History.rdoc +24 -6
  6. data/Manifest.txt +70 -2
  7. data/Rakefile +2 -3
  8. data/Rakefile.cross +3 -3
  9. data/ext/errorcodes.def +4 -0
  10. data/ext/errorcodes.txt +2 -1
  11. data/ext/pg.c +9 -4
  12. data/ext/pg.h +18 -6
  13. data/ext/pg_binary_decoder.c +10 -6
  14. data/ext/pg_binary_encoder.c +1 -1
  15. data/ext/pg_connection.c +31 -29
  16. data/ext/pg_result.c +2 -0
  17. data/ext/pg_text_decoder.c +1 -1
  18. data/ext/pg_text_encoder.c +6 -7
  19. data/ext/pg_tuple.c +4 -3
  20. data/ext/pg_type_map.c +1 -1
  21. data/ext/pg_type_map_all_strings.c +1 -1
  22. data/ext/pg_type_map_by_class.c +1 -1
  23. data/ext/pg_type_map_by_column.c +1 -1
  24. data/ext/pg_type_map_by_mri_type.c +1 -1
  25. data/ext/pg_type_map_by_oid.c +1 -1
  26. data/ext/pg_type_map_in_ruby.c +1 -1
  27. data/ext/util.c +1 -1
  28. data/lib/pg.rb +2 -2
  29. data/spec/helpers.rb +8 -8
  30. data/spec/pg/basic_type_mapping_spec.rb +5 -5
  31. data/spec/pg/connection_spec.rb +131 -17
  32. data/spec/pg/tuple_spec.rb +16 -2
  33. data/spec/pg/type_spec.rb +6 -0
  34. metadata +38 -79
  35. metadata.gz.sig +0 -0
  36. data/.gems +0 -6
  37. data/.hgignore +0 -21
  38. data/.hgsigs +0 -29
  39. data/.hgtags +0 -36
  40. data/.hoerc +0 -2
  41. data/.irbrc +0 -23
  42. data/.pryrc +0 -23
  43. data/.tm_properties +0 -21
  44. data/.travis.yml +0 -41
  45. data/Gemfile +0 -2
  46. data/appveyor.yml +0 -50
  47. data/certs/ged.pem +0 -26
  48. data/misc/openssl-pg-segfault.rb +0 -31
  49. data/misc/postgres/History.txt +0 -9
  50. data/misc/postgres/Manifest.txt +0 -5
  51. data/misc/postgres/README.txt +0 -21
  52. data/misc/postgres/Rakefile +0 -21
  53. data/misc/postgres/lib/postgres.rb +0 -16
  54. data/misc/ruby-pg/History.txt +0 -9
  55. data/misc/ruby-pg/Manifest.txt +0 -5
  56. data/misc/ruby-pg/README.txt +0 -21
  57. data/misc/ruby-pg/Rakefile +0 -21
  58. data/misc/ruby-pg/lib/ruby/pg.rb +0 -16
  59. data/pg.gemspec +0 -61
  60. data/sample/array_insert.rb +0 -20
  61. data/sample/async_api.rb +0 -106
  62. data/sample/async_copyto.rb +0 -39
  63. data/sample/async_mixed.rb +0 -56
  64. data/sample/check_conn.rb +0 -21
  65. data/sample/copydata.rb +0 -71
  66. data/sample/copyfrom.rb +0 -81
  67. data/sample/copyto.rb +0 -19
  68. data/sample/cursor.rb +0 -21
  69. data/sample/disk_usage_report.rb +0 -177
  70. data/sample/issue-119.rb +0 -94
  71. data/sample/losample.rb +0 -69
  72. data/sample/minimal-testcase.rb +0 -17
  73. data/sample/notify_wait.rb +0 -72
  74. data/sample/pg_statistics.rb +0 -285
  75. data/sample/replication_monitor.rb +0 -222
  76. data/sample/test_binary_values.rb +0 -33
  77. data/sample/wal_shipper.rb +0 -434
  78. data/sample/warehouse_partitions.rb +0 -311
@@ -1,12 +1,29 @@
1
- == v2.0.0 - far from release -
1
+ == v1.1.4 [2019-01-08] Michael Granger <ged@FaerieMUD.org>
2
2
 
3
- Removed:
4
- - Removed query method variants deprecated in pg-1.1.0.
3
+ - Fix PG::BinaryDecoder::Timestamp on 32 bit systems. # 284
4
+ - Add new error-codes of PostgreSQL-11.
5
+ - Add ruby-2.6 support for Windows fat binary gems and remove ruby-2.0 and 2.1.
5
6
 
6
7
 
7
- == v1.1.0 [YYYY-MM-DD] Michael Granger <ged@FaerieMUD.org>
8
+ == v1.1.3 [2018-09-06] Michael Granger <ged@FaerieMUD.org>
8
9
 
9
- Deprecated:
10
+ - Revert opimization that was sometimes causing EBADF in rb_wait_for_single_fd().
11
+
12
+
13
+ == v1.1.2 [2018-08-28] Michael Granger <ged@FaerieMUD.org>
14
+
15
+ - Don't generate aliases for JOHAB encoding.
16
+ This avoids linking to deprecated/private function rb_enc(db)_alias().
17
+
18
+
19
+ == v1.1.1 [2018-08-27] Michael Granger <ged@FaerieMUD.org>
20
+
21
+ - Reduce deprecation warnings to only one message per deprecation.
22
+
23
+
24
+ == v1.1.0 [2018-08-24] Michael Granger <ged@FaerieMUD.org>
25
+
26
+ Deprecated (disable warnings per PG_SKIP_DEPRECATION_WARNING=1):
10
27
  - Forwarding conn.exec to conn.exec_params is deprecated.
11
28
  - Forwarding conn.exec_params to conn.exec is deprecated.
12
29
  - Forwarding conn.async_exec to conn.async_exec_params.
@@ -20,10 +37,11 @@ PG::Connection enhancements:
20
37
  They are identical to their syncronous counterpart, but make use of PostgreSQL's async API.
21
38
  - Replace `rb_thread_fd_select()` by faster `rb_wait_for_single_fd()` in `conn.block` and `conn.async_exec` .
22
39
  - Add PG::Connection#discard_results .
40
+ - Raise an ArgumentError for strings containing zero bytes by #escape, #escape_literal, #escape_identifier, #quote_ident and PG::TextEncoder::Identifier. These methods previously truncated strings.
23
41
 
24
42
  Result retrieval enhancements:
25
43
  - Add PG::Result#tuple_values to retrieve all field values of a row as array.
26
- - Add PG::Tuple, PG::Result#tuple_values and PG::Result#stream_each_tuple .
44
+ - Add PG::Tuple, PG::Result#tuple and PG::Result#stream_each_tuple .
27
45
  PG::Tuple offers a way to lazy cast result values.
28
46
  - Estimate PG::Result size allocated by libpq and notify the garbage collector about it when running on Ruby-2.4 or newer.
29
47
  - Make the estimated PG::Result size available to ObjectSpace.memsize_of(result) .
@@ -1,4 +1,72 @@
1
- # Manifest is built per Rakefile as part of `rake gem`.
2
- # These files are required to satisfy Hoe:
1
+ .gemtest
2
+ BSDL
3
+ ChangeLog
4
+ Contributors.rdoc
5
+ History.rdoc
6
+ LICENSE
7
+ Manifest.txt
8
+ POSTGRES
9
+ README-OS_X.rdoc
10
+ README-Windows.rdoc
11
+ README.ja.rdoc
3
12
  README.rdoc
13
+ Rakefile
14
+ Rakefile.cross
15
+ ext/errorcodes.def
16
+ ext/errorcodes.rb
17
+ ext/errorcodes.txt
18
+ ext/extconf.rb
19
+ ext/gvl_wrappers.c
20
+ ext/gvl_wrappers.h
21
+ ext/pg.c
22
+ ext/pg.h
23
+ ext/pg_binary_decoder.c
24
+ ext/pg_binary_encoder.c
25
+ ext/pg_coder.c
26
+ ext/pg_connection.c
27
+ ext/pg_copy_coder.c
28
+ ext/pg_errors.c
29
+ ext/pg_result.c
30
+ ext/pg_text_decoder.c
31
+ ext/pg_text_encoder.c
32
+ ext/pg_tuple.c
33
+ ext/pg_type_map.c
34
+ ext/pg_type_map_all_strings.c
35
+ ext/pg_type_map_by_class.c
36
+ ext/pg_type_map_by_column.c
37
+ ext/pg_type_map_by_mri_type.c
38
+ ext/pg_type_map_by_oid.c
39
+ ext/pg_type_map_in_ruby.c
40
+ ext/util.c
41
+ ext/util.h
42
+ ext/vc/pg.sln
43
+ ext/vc/pg_18/pg.vcproj
44
+ ext/vc/pg_19/pg_19.vcproj
4
45
  lib/pg.rb
46
+ lib/pg/basic_type_mapping.rb
47
+ lib/pg/binary_decoder.rb
48
+ lib/pg/coder.rb
49
+ lib/pg/connection.rb
50
+ lib/pg/constants.rb
51
+ lib/pg/exceptions.rb
52
+ lib/pg/result.rb
53
+ lib/pg/text_decoder.rb
54
+ lib/pg/text_encoder.rb
55
+ lib/pg/tuple.rb
56
+ lib/pg/type_map_by_column.rb
57
+ spec/data/expected_trace.out
58
+ spec/data/random_binary_data
59
+ spec/helpers.rb
60
+ spec/pg/basic_type_mapping_spec.rb
61
+ spec/pg/connection_spec.rb
62
+ spec/pg/connection_sync_spec.rb
63
+ spec/pg/result_spec.rb
64
+ spec/pg/tuple_spec.rb
65
+ spec/pg/type_map_by_class_spec.rb
66
+ spec/pg/type_map_by_column_spec.rb
67
+ spec/pg/type_map_by_mri_type_spec.rb
68
+ spec/pg/type_map_by_oid_spec.rb
69
+ spec/pg/type_map_in_ruby_spec.rb
70
+ spec/pg/type_map_spec.rb
71
+ spec/pg/type_spec.rb
72
+ spec/pg_spec.rb
data/Rakefile CHANGED
@@ -55,14 +55,13 @@ $hoespec = Hoe.spec 'pg' do
55
55
  self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
56
56
  self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
57
57
  self.extra_rdoc_files.include( 'ext/*.c' )
58
- self.spec_extras[:files] = `hg manifest || git ls-files`.split
59
58
  self.license 'BSD-3-Clause'
60
59
 
61
60
  self.developer 'Michael Granger', 'ged@FaerieMUD.org'
62
61
  self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
63
62
 
64
63
  self.dependency 'rake-compiler', '~> 1.0', :developer
65
- self.dependency 'rake-compiler-dock', ['~> 0.6', '>= 0.6.2'], :developer
64
+ self.dependency 'rake-compiler-dock', ['~> 0.7.0'], :developer
66
65
  self.dependency 'hoe-deveiate', '~> 0.9', :developer
67
66
  self.dependency 'hoe-bundler', '~> 1.0', :developer
68
67
  self.dependency 'rspec', '~> 3.5', :developer
@@ -185,7 +184,7 @@ end
185
184
 
186
185
  desc "Update list of server error codes"
187
186
  task :update_error_codes do
188
- URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_10_4"
187
+ URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_11_1"
189
188
 
190
189
  ERRORCODES_TXT = "ext/errorcodes.txt"
191
190
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
@@ -29,8 +29,8 @@ class CrossLibrary < OpenStruct
29
29
  self.host_platform = toolchain
30
30
 
31
31
  # Cross-compilation constants
32
- self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.0h'
33
- self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '10.4'
32
+ self.openssl_version = ENV['OPENSSL_VERSION'] || '1.1.1a'
33
+ self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '11.1'
34
34
 
35
35
  # Check if symlinks work in the current working directory.
36
36
  # This fails, if rake-compiler-dock is running on a Windows box.
@@ -293,6 +293,6 @@ task 'gem:windows' => ['ChangeLog'] do
293
293
  mkdir ~/.gem &&
294
294
  (cp build/gem/gem-*.pem ~/.gem/ || true) &&
295
295
  bundle install --local &&
296
- rake cross native gem RUBY_CC_VERSION=2.5.0:2.4.0:2.3.0:2.2.2:2.1.6:2.0.0 MAKE="make -j`nproc`"
296
+ rake cross native gem MAKE="make -j`nproc`"
297
297
  EOT
298
298
  end
@@ -186,6 +186,10 @@
186
186
  VALUE klass = define_error_class( "InvalidParameterValue", "22" );
187
187
  register_error_class( "22023", klass );
188
188
  }
189
+ {
190
+ VALUE klass = define_error_class( "InvalidPrecedingOrFollowingSize", "22" );
191
+ register_error_class( "22013", klass );
192
+ }
189
193
  {
190
194
  VALUE klass = define_error_class( "InvalidRegularExpression", "22" );
191
195
  register_error_class( "2201B", klass );
@@ -2,7 +2,7 @@
2
2
  # errcodes.txt
3
3
  # PostgreSQL error codes
4
4
  #
5
- # Copyright (c) 2003-2017, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2018, PostgreSQL Global Development Group
6
6
  #
7
7
  # This list serves as the basis for generating source files containing error
8
8
  # codes. It is kept in a common format to make sure all these source files have
@@ -177,6 +177,7 @@ Section: Class 22 - Data Exception
177
177
  22P06 E ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER nonstandard_use_of_escape_character
178
178
  22010 E ERRCODE_INVALID_INDICATOR_PARAMETER_VALUE invalid_indicator_parameter_value
179
179
  22023 E ERRCODE_INVALID_PARAMETER_VALUE invalid_parameter_value
180
+ 22013 E ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE invalid_preceding_or_following_size
180
181
  2201B E ERRCODE_INVALID_REGULAR_EXPRESSION invalid_regular_expression
181
182
  2201W E ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE invalid_row_count_in_limit_clause
182
183
  2201X E ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE invalid_row_count_in_result_offset_clause
data/ext/pg.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id$
3
+ * $Id: pg.c,v 2d334508484a 2018/08/27 11:33:43 lars $
4
4
  *
5
5
  * Author/s:
6
6
  *
@@ -48,6 +48,7 @@
48
48
 
49
49
  #include "pg.h"
50
50
 
51
+ int pg_skip_deprecation_warning;
51
52
  VALUE rb_mPG;
52
53
  VALUE rb_mPGconstants;
53
54
 
@@ -142,9 +143,6 @@ pg_find_or_create_johab(void)
142
143
  }
143
144
 
144
145
  enc_index = rb_define_dummy_encoding(aliases[0]);
145
- for (i = 1; i < sizeof(aliases)/sizeof(aliases[0]); ++i) {
146
- rb_enc_alias(aliases[i], aliases[0]);
147
- }
148
146
  return rb_enc_from_index(enc_index);
149
147
  }
150
148
 
@@ -381,6 +379,13 @@ pg_s_init_ssl(VALUE self, VALUE do_ssl)
381
379
  void
382
380
  Init_pg_ext()
383
381
  {
382
+ if( RTEST(rb_eval_string("ENV['PG_SKIP_DEPRECATION_WARNING']")) ){
383
+ /* Set all bits to disable all deprecation warnings. */
384
+ pg_skip_deprecation_warning = 0xFFFF;
385
+ } else {
386
+ pg_skip_deprecation_warning = 0;
387
+ }
388
+
384
389
  rb_mPG = rb_define_module( "PG" );
385
390
  rb_mPGconstants = rb_define_module_under( rb_mPG, "Constants" );
386
391
 
data/ext/pg.h CHANGED
@@ -21,9 +21,6 @@
21
21
  #include "ruby/st.h"
22
22
  #include "ruby/encoding.h"
23
23
 
24
- /* exported by ruby-1.9.3+ but not declared */
25
- extern int rb_enc_alias(const char *, const char *);
26
-
27
24
  #define PG_ENCODING_SET_NOCHECK(obj,i) \
28
25
  do { \
29
26
  if ((i) < ENCODING_INLINE_MAX) \
@@ -104,11 +101,13 @@ typedef struct {
104
101
  /* Kind of PG::Coder object for casting COPY rows to ruby values */
105
102
  VALUE decoder_for_get_copy_data;
106
103
 
107
- /* The connection socket, used for rb_wait_for_single_fd() */
108
- int socket;
109
-
110
104
  /* enable/disable guessing size of PGresult's allocated memory */
111
105
  int guess_result_memsize;
106
+
107
+ #if defined(_WIN32)
108
+ /* File descriptor to be used for rb_w32_unwrap_io_handle() */
109
+ int ruby_sd;
110
+ #endif
112
111
  } t_pg_connection;
113
112
 
114
113
  typedef struct pg_coder t_pg_coder;
@@ -217,6 +216,7 @@ typedef struct {
217
216
  * Globals
218
217
  **************************************************************************/
219
218
 
219
+ extern int pg_skip_deprecation_warning;
220
220
  extern VALUE rb_mPG;
221
221
  extern VALUE rb_ePGerror;
222
222
  extern VALUE rb_eServerError;
@@ -350,4 +350,16 @@ rb_encoding *pg_conn_enc_get _(( PGconn * ));
350
350
  void notice_receiver_proxy(void *arg, const PGresult *result);
351
351
  void notice_processor_proxy(void *arg, const char *message);
352
352
 
353
+ /* reports if `-W' specified and PG_SKIP_DEPRECATION_WARNING environment variable isn't set
354
+ *
355
+ * message_id identifies the warning, so that it's reported only once.
356
+ */
357
+ #define pg_deprecated(message_id, format_args) \
358
+ do { \
359
+ if( !(pg_skip_deprecation_warning & (1 << message_id)) ){ \
360
+ pg_skip_deprecation_warning |= 1 << message_id; \
361
+ rb_warning format_args; \
362
+ } \
363
+ } while(0);
364
+
353
365
  #endif /* end __pg_h */
@@ -154,7 +154,8 @@ static VALUE
154
154
  pg_bin_dec_timestamp(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
155
155
  {
156
156
  int64_t timestamp;
157
- struct timespec ts;
157
+ int64_t sec;
158
+ int64_t nsec;
158
159
  VALUE t;
159
160
 
160
161
  if( len != sizeof(timestamp) ){
@@ -171,14 +172,17 @@ pg_bin_dec_timestamp(t_pg_coder *conv, const char *val, int len, int tuple, int
171
172
  default:
172
173
  /* PostgreSQL's timestamp is based on year 2000 and Ruby's time is based on 1970.
173
174
  * Adjust the 30 years difference. */
174
- ts.tv_sec = (timestamp / 1000000) + 10957L * 24L * 3600L;
175
- ts.tv_nsec = (timestamp % 1000000) * 1000;
175
+ sec = (timestamp / 1000000) + 10957L * 24L * 3600L;
176
+ nsec = (timestamp % 1000000) * 1000;
176
177
 
177
- #if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 3)) && defined(NEGATIVE_TIME_T)
178
+ #if (RUBY_API_VERSION_MAJOR > 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR >= 3)) && defined(NEGATIVE_TIME_T) && defined(SIZEOF_TIME_T) && SIZEOF_TIME_T >= 8
178
179
  /* Fast path for time conversion */
179
- t = rb_time_timespec_new(&ts, conv->flags & PG_CODER_TIMESTAMP_APP_LOCAL ? INT_MAX : INT_MAX-1);
180
+ {
181
+ struct timespec ts = {sec, nsec};
182
+ t = rb_time_timespec_new(&ts, conv->flags & PG_CODER_TIMESTAMP_APP_LOCAL ? INT_MAX : INT_MAX-1);
183
+ }
180
184
  #else
181
- t = rb_funcall(rb_cTime, rb_intern("at"), 2, LL2NUM(ts.tv_sec), LL2NUM(ts.tv_nsec / 1000));
185
+ t = rb_funcall(rb_cTime, rb_intern("at"), 2, LL2NUM(sec), LL2NUM(nsec / 1000));
182
186
  if( !(conv->flags & PG_CODER_TIMESTAMP_APP_LOCAL) ) {
183
187
  t = rb_funcall(t, rb_intern("utc"), 0);
184
188
  }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg_column_map.c - PG::ColumnMap class extension
3
- * $Id$
3
+ * $Id: pg_binary_encoder.c,v e61a06f1f5ed 2015/12/25 21:14:21 lars $
4
4
  *
5
5
  */
6
6
 
@@ -85,8 +85,7 @@ pgconn_close_socket_io( VALUE self )
85
85
 
86
86
  if ( RTEST(socket_io) ) {
87
87
  #if defined(_WIN32)
88
- int ruby_sd = NUM2INT(rb_funcall( socket_io, rb_intern("fileno"), 0 ));
89
- if( rb_w32_unwrap_io_handle(ruby_sd) ){
88
+ if( rb_w32_unwrap_io_handle(this->ruby_sd) ){
90
89
  rb_raise(rb_eConnectionBad, "Could not unwrap win32 socket handle");
91
90
  }
92
91
  #endif
@@ -165,6 +164,10 @@ pgconn_gc_mark( t_pg_connection *this )
165
164
  static void
166
165
  pgconn_gc_free( t_pg_connection *this )
167
166
  {
167
+ #if defined(_WIN32)
168
+ if ( RTEST(this->socket_io) )
169
+ rb_w32_unwrap_io_handle( this->ruby_sd );
170
+ #endif
168
171
  if (this->pgconn != NULL)
169
172
  PQfinish( this->pgconn );
170
173
 
@@ -198,7 +201,6 @@ pgconn_s_allocate( VALUE klass )
198
201
  this->decoder_for_get_copy_data = Qnil;
199
202
  this->trace_stream = Qnil;
200
203
  this->external_encoding = Qnil;
201
- this->socket = -1;
202
204
  this->guess_result_memsize = 1;
203
205
 
204
206
  return self;
@@ -272,6 +274,7 @@ pgconn_init(int argc, VALUE *argv, VALUE self)
272
274
  this = pg_get_connection( self );
273
275
  conninfo = rb_funcall2( rb_cPGconn, rb_intern("parse_connect_args"), argc, argv );
274
276
  this->pgconn = gvl_PQconnectdb(StringValueCStr(conninfo));
277
+
275
278
  if(this->pgconn == NULL)
276
279
  rb_raise(rb_ePGerror, "PQconnectdb() unable to allocate structure");
277
280
 
@@ -281,10 +284,6 @@ pgconn_init(int argc, VALUE *argv, VALUE self)
281
284
  rb_exc_raise(error);
282
285
  }
283
286
 
284
- this->socket = PQsocket( this->pgconn );
285
- if ( this->socket < 0 )
286
- rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
287
-
288
287
  pgconn_set_default_encoding( self );
289
288
 
290
289
  if (rb_block_given_p()) {
@@ -335,10 +334,6 @@ pgconn_s_connect_start( int argc, VALUE *argv, VALUE klass )
335
334
  rb_exc_raise(error);
336
335
  }
337
336
 
338
- this->socket = PQsocket( this->pgconn );
339
- if ( this->socket < 0 )
340
- rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
341
-
342
337
  if ( rb_block_given_p() ) {
343
338
  return rb_ensure( rb_yield, rb_conn, pgconn_finish, rb_conn );
344
339
  }
@@ -902,6 +897,7 @@ pgconn_socket_io(VALUE self)
902
897
 
903
898
  #ifdef _WIN32
904
899
  ruby_sd = rb_w32_wrap_io_handle((HANDLE)(intptr_t)sd, O_RDWR|O_BINARY|O_NOINHERIT);
900
+ this->ruby_sd = ruby_sd;
905
901
  #else
906
902
  ruby_sd = sd;
907
903
  #endif
@@ -969,7 +965,7 @@ static VALUE pgconn_exec_params( int, VALUE *, VALUE );
969
965
  * conn.exec(sql) {|pg_result| block }
970
966
  *
971
967
  * Sends SQL query request specified by _sql_ to PostgreSQL.
972
- * Returns a PG::Result instance on success.
968
+ * On success, it returns a PG::Result instance with all result rows and columns.
973
969
  * On failure, it raises a PG::Error.
974
970
  *
975
971
  * For backward compatibility, if you pass more than one parameter to this method,
@@ -1006,7 +1002,7 @@ pgconn_exec(int argc, VALUE *argv, VALUE self)
1006
1002
  }
1007
1003
  return rb_pgresult;
1008
1004
  }
1009
- rb_warning("forwarding exec to exec_params is deprecated");
1005
+ pg_deprecated(0, ("forwarding exec to exec_params is deprecated"));
1010
1006
 
1011
1007
  /* Otherwise, just call #exec_params instead for backward-compatibility */
1012
1008
  return pgconn_exec_params( argc, argv, self );
@@ -1321,7 +1317,7 @@ pgconn_exec_params( int argc, VALUE *argv, VALUE self )
1321
1317
  * is passed to #exec
1322
1318
  */
1323
1319
  if ( NIL_P(paramsData.params) ) {
1324
- rb_warning("forwarding exec_params to exec is deprecated");
1320
+ pg_deprecated(1, ("forwarding exec_params to exec is deprecated"));
1325
1321
  return pgconn_exec( 1, argv, self );
1326
1322
  }
1327
1323
  pgconn_query_assign_typemap( self, &paramsData );
@@ -1587,7 +1583,7 @@ pgconn_s_escape(VALUE self, VALUE string)
1587
1583
  int enc_idx;
1588
1584
  int singleton = !rb_obj_is_kind_of(self, rb_cPGconn);
1589
1585
 
1590
- Check_Type(string, T_STRING);
1586
+ StringValueCStr(string);
1591
1587
  enc_idx = ENCODING_GET( singleton ? string : self );
1592
1588
  if( ENCODING_GET(string) != enc_idx ){
1593
1589
  string = rb_str_export_to_enc(string, rb_enc_from_index(enc_idx));
@@ -1703,7 +1699,7 @@ pgconn_escape_literal(VALUE self, VALUE string)
1703
1699
  VALUE result = Qnil;
1704
1700
  int enc_idx = ENCODING_GET(self);
1705
1701
 
1706
- Check_Type(string, T_STRING);
1702
+ StringValueCStr(string);
1707
1703
  if( ENCODING_GET(string) != enc_idx ){
1708
1704
  string = rb_str_export_to_enc(string, rb_enc_from_index(enc_idx));
1709
1705
  }
@@ -1745,7 +1741,7 @@ pgconn_escape_identifier(VALUE self, VALUE string)
1745
1741
  VALUE result = Qnil;
1746
1742
  int enc_idx = ENCODING_GET(self);
1747
1743
 
1748
- Check_Type(string, T_STRING);
1744
+ StringValueCStr(string);
1749
1745
  if( ENCODING_GET(string) != enc_idx ){
1750
1746
  string = rb_str_export_to_enc(string, rb_enc_from_index(enc_idx));
1751
1747
  }
@@ -1851,7 +1847,7 @@ pgconn_send_query(int argc, VALUE *argv, VALUE self)
1851
1847
  return Qnil;
1852
1848
  }
1853
1849
 
1854
- rb_warning("forwarding async_exec to async_exec_params and send_query to send_query_params is deprecated");
1850
+ pg_deprecated(2, ("forwarding async_exec to async_exec_params and send_query to send_query_params is deprecated"));
1855
1851
 
1856
1852
  /* If called with parameters, and optionally result_format,
1857
1853
  * use PQsendQueryParams
@@ -2337,15 +2333,18 @@ pgconn_notifies(VALUE self)
2337
2333
  int rb_w32_wait_events( HANDLE *events, int num, DWORD timeout );
2338
2334
 
2339
2335
  static void *
2340
- wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*is_readable)(PGconn *) )
2336
+ wait_socket_readable( PGconn *conn, struct timeval *ptimeout, void *(*is_readable)(PGconn *) )
2341
2337
  {
2342
- PGconn *conn = this->pgconn;
2338
+ int sd = PQsocket( conn );
2343
2339
  void *retval;
2344
2340
  struct timeval aborttime={0,0}, currtime, waittime;
2345
2341
  DWORD timeout_milisec = INFINITE;
2346
2342
  DWORD wait_ret;
2347
2343
  WSAEVENT hEvent;
2348
2344
 
2345
+ if ( sd < 0 )
2346
+ rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
2347
+
2349
2348
  hEvent = WSACreateEvent();
2350
2349
 
2351
2350
  /* Check for connection errors (PQisBusy is true on connection errors) */
@@ -2360,7 +2359,7 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2360
2359
  }
2361
2360
 
2362
2361
  while ( !(retval=is_readable(conn)) ) {
2363
- if ( WSAEventSelect(this->socket, hEvent, FD_READ|FD_CLOSE) == SOCKET_ERROR ) {
2362
+ if ( WSAEventSelect(sd, hEvent, FD_READ|FD_CLOSE) == SOCKET_ERROR ) {
2364
2363
  WSACloseEvent( hEvent );
2365
2364
  rb_raise( rb_eConnectionBad, "WSAEventSelect socket error: %d", WSAGetLastError() );
2366
2365
  }
@@ -2412,13 +2411,16 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2412
2411
  /* non Win32 */
2413
2412
 
2414
2413
  static void *
2415
- wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*is_readable)(PGconn *))
2414
+ wait_socket_readable( PGconn *conn, struct timeval *ptimeout, void *(*is_readable)(PGconn *))
2416
2415
  {
2417
- PGconn *conn = this->pgconn;
2416
+ int sd = PQsocket( conn );
2418
2417
  int ret;
2419
2418
  void *retval;
2420
2419
  struct timeval aborttime={0,0}, currtime, waittime;
2421
2420
 
2421
+ if ( sd < 0 )
2422
+ rb_raise(rb_eConnectionBad, "PQsocket() can't get socket descriptor");
2423
+
2422
2424
  /* Check for connection errors (PQisBusy is true on connection errors) */
2423
2425
  if ( PQconsumeInput(conn) == 0 )
2424
2426
  rb_raise( rb_eConnectionBad, "PQconsumeInput() %s", PQerrorMessage(conn) );
@@ -2437,7 +2439,7 @@ wait_socket_readable( t_pg_connection *this, struct timeval *ptimeout, void *(*i
2437
2439
  /* Is the given timeout valid? */
2438
2440
  if( !ptimeout || (waittime.tv_sec >= 0 && waittime.tv_usec >= 0) ){
2439
2441
  /* Wait for the socket to become readable before checking again */
2440
- ret = rb_wait_for_single_fd( this->socket, RB_WAITFD_IN, ptimeout ? &waittime : NULL );
2442
+ ret = rb_wait_for_single_fd( sd, RB_WAITFD_IN, ptimeout ? &waittime : NULL );
2441
2443
  } else {
2442
2444
  ret = 0;
2443
2445
  }
@@ -2484,7 +2486,7 @@ notify_readable(PGconn *conn)
2484
2486
  static VALUE
2485
2487
  pgconn_wait_for_notify(int argc, VALUE *argv, VALUE self)
2486
2488
  {
2487
- t_pg_connection *this = pg_get_connection_safe( self );
2489
+ PGconn *conn = pg_get_pgconn( self );
2488
2490
  PGnotify *pnotification;
2489
2491
  struct timeval timeout;
2490
2492
  struct timeval *ptimeout = NULL;
@@ -2500,7 +2502,7 @@ pgconn_wait_for_notify(int argc, VALUE *argv, VALUE self)
2500
2502
  ptimeout = &timeout;
2501
2503
  }
2502
2504
 
2503
- pnotification = (PGnotify*) wait_socket_readable( this, ptimeout, notify_readable);
2505
+ pnotification = (PGnotify*) wait_socket_readable( conn, ptimeout, notify_readable);
2504
2506
 
2505
2507
  /* Return nil if the select timed out */
2506
2508
  if ( !pnotification ) return Qnil;
@@ -3078,7 +3080,7 @@ get_result_readable(PGconn *conn)
3078
3080
  */
3079
3081
  static VALUE
3080
3082
  pgconn_block( int argc, VALUE *argv, VALUE self ) {
3081
- t_pg_connection *this = pg_get_connection_safe( self );
3083
+ PGconn *conn = pg_get_pgconn( self );
3082
3084
 
3083
3085
  struct timeval timeout;
3084
3086
  struct timeval *ptimeout = NULL;
@@ -3093,7 +3095,7 @@ pgconn_block( int argc, VALUE *argv, VALUE self ) {
3093
3095
  ptimeout = &timeout;
3094
3096
  }
3095
3097
 
3096
- ret = wait_socket_readable( this, ptimeout, get_result_readable);
3098
+ ret = wait_socket_readable( conn, ptimeout, get_result_readable);
3097
3099
 
3098
3100
  if( !ret )
3099
3101
  return Qfalse;
@@ -3223,7 +3225,7 @@ pgconn_async_exec_params(int argc, VALUE *argv, VALUE self)
3223
3225
  pgconn_discard_results( self );
3224
3226
  /* If called with no or nil parameters, use PQsendQuery for compatibility */
3225
3227
  if ( argc == 1 || (argc >= 2 && argc <= 4 && NIL_P(argv[1]) )) {
3226
- rb_warning("forwarding async_exec_params to async_exec is deprecated");
3228
+ pg_deprecated(3, ("forwarding async_exec_params to async_exec is deprecated"));
3227
3229
  pgconn_send_query( argc, argv, self );
3228
3230
  } else {
3229
3231
  pgconn_send_query_params( argc, argv, self );