pg 1.5.4 → 1.5.9

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 (51) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Gemfile +6 -0
  4. data/History.md +52 -4
  5. data/Rakefile +4 -1
  6. data/Rakefile.cross +13 -8
  7. data/certs/kanis@comcard.de.pem +20 -0
  8. data/certs/larskanis-2024.pem +24 -0
  9. data/ext/errorcodes.def +4 -5
  10. data/ext/errorcodes.txt +2 -5
  11. data/ext/extconf.rb +3 -0
  12. data/ext/pg.c +1 -1
  13. data/ext/pg_binary_decoder.c +2 -0
  14. data/ext/pg_binary_encoder.c +1 -1
  15. data/ext/pg_connection.c +45 -13
  16. data/ext/pg_copy_coder.c +17 -13
  17. data/ext/pg_record_coder.c +6 -6
  18. data/ext/pg_result.c +2 -2
  19. data/ext/pg_text_decoder.c +4 -1
  20. data/ext/pg_text_encoder.c +17 -11
  21. data/lib/pg/basic_type_map_for_queries.rb +8 -4
  22. data/lib/pg/basic_type_registry.rb +14 -2
  23. data/lib/pg/connection.rb +58 -38
  24. data/lib/pg/exceptions.rb +6 -0
  25. data/lib/pg/text_decoder/date.rb +3 -0
  26. data/lib/pg/text_decoder/json.rb +3 -0
  27. data/lib/pg/text_encoder/date.rb +1 -0
  28. data/lib/pg/text_encoder/inet.rb +3 -0
  29. data/lib/pg/text_encoder/json.rb +3 -0
  30. data/lib/pg/version.rb +1 -1
  31. data/lib/pg.rb +10 -0
  32. data/pg.gemspec +3 -1
  33. data.tar.gz.sig +0 -0
  34. metadata +27 -40
  35. metadata.gz.sig +0 -0
  36. data/.appveyor.yml +0 -42
  37. data/.gems +0 -6
  38. data/.gemtest +0 -0
  39. data/.github/workflows/binary-gems.yml +0 -117
  40. data/.github/workflows/source-gem.yml +0 -141
  41. data/.gitignore +0 -22
  42. data/.hgsigs +0 -34
  43. data/.hgtags +0 -41
  44. data/.irbrc +0 -23
  45. data/.pryrc +0 -23
  46. data/.tm_properties +0 -21
  47. data/.travis.yml +0 -49
  48. data/translation/.po4a-version +0 -7
  49. data/translation/po/all.pot +0 -936
  50. data/translation/po/ja.po +0 -1036
  51. data/translation/po4a.cfg +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e50a6829d4fe134af52d85429a3db06240fb6d228b96ef5b3fade98d38f4d199
4
- data.tar.gz: 281f5700e856a64a4a7c3157bbef4398345ac16698dbcdce54ed0408c0448457
3
+ metadata.gz: c0abb6cbfa5134825baaaa3cab5bbb2d88a5092559331239ccb977c24579d27d
4
+ data.tar.gz: 53d6fd115d923b9654b2928791309d290a87f01275a13f3489025d673ba967ab
5
5
  SHA512:
6
- metadata.gz: 4ca887b068f003b077c17fca5e8297368f5236ed74ae16888a64312fed269110c455e2cd58105b5a23fbb53a1841b081ae215d3a4c3473815914642fcdde75cc
7
- data.tar.gz: 86599add8d622097727be30a1a05259c69d8c83fa73e1dad0f46125e95685a752a5df24f235158ff0d62dbfe99034aa8512e89bc39f26edf81a2540c466a6541
6
+ metadata.gz: c7b1c92f223b4250fd56d37bbfa94dadf19d9e03518e7a3426bb19800745f031ab133a3d8921ec2f63045762e46bbfe7ac5a01f0144c4eb3d5b3ad8cf2f1197d
7
+ data.tar.gz: 3fd53f91bfc2880da42fddcc5ae6a9334c419025636e0d1626b533da7fa62a6f87942629ed6c24c1183002295dcbdf56a33c96af2323e3a9fb0396bcb68e673e
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile CHANGED
@@ -11,4 +11,10 @@ group :development, :test do
11
11
  gem "rake-compiler-dock", "~> 1.0"
12
12
  gem "rdoc", "~> 6.4"
13
13
  gem "rspec", "~> 3.5"
14
+ gem "ostruct", "~> 0.5" # for Rakefile.cross
15
+ # "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
16
+ # Specs should succeed without it, but 4 examples are then excluded.
17
+ # With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
18
+ # That way we can check both situations in CI.
19
+ # gem "bigdecimal", "~> 3.0"
14
20
  end
data/History.md CHANGED
@@ -1,9 +1,57 @@
1
+ ## v1.5.9 [2024-10-24] Lars Kanis <lars@greiz-reinsdorf.de>
2
+
3
+ - Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595)
4
+ - Remove raising `conect_timeout` from 1 to 2 seconds. [#590](https://github.com/ged/ruby-pg/pull/590)
5
+ - Fix binary copy_data in Ractor context. [#594](https://github.com/ged/ruby-pg/pull/594)
6
+ - Exclude CI files and hidden files from built gem. [#591](https://github.com/ged/ruby-pg/pull/591)
7
+ This is to simplify security inspection.
8
+ - Update error classes to PostgreSQL-17.
9
+ - Update Windows fat binary gem to OpenSSL-3.4.0 and PostgreSQL-17.0.
10
+
11
+
12
+ ## v1.5.8 [2024-09-06] Lars Kanis <lars@greiz-reinsdorf.de>
13
+
14
+ - Fix host list duplication every time conn.reset is used. [#586](https://github.com/ged/ruby-pg/pull/586)
15
+ - Add default decoder for anonymous record types to BasicTypeRegistry [#579](https://github.com/ged/ruby-pg/pull/579)
16
+ - Update Windows fat binary gem to OpenSSL-3.3.2 and PostgreSQL-16.4.
17
+
18
+
19
+ ## v1.5.7 [2024-07-28] Lars Kanis <lars@greiz-reinsdorf.de>
20
+
21
+ - Remove deprecated use of fptr->fd.[#562](https://github.com/ged/ruby-pg/pull/562)
22
+ Direct access is disallowed since ruby-3.4.
23
+ - Make `pgconn_connect_poll` close the socket prior to calling `PQconnectPoll`. [#564](https://github.com/ged/ruby-pg/pull/564)
24
+ This could result in an exception while connecting when used multi threaded.
25
+ - Fix several typos and improve spelling in documentation and code. [#566](https://github.com/ged/ruby-pg/pull/566)
26
+ - Add missing PG::RollbackTransaction as an option to exit conn.transaction. [#560](https://github.com/ged/ruby-pg/pull/560)
27
+ Usage like in rails: https://api.rubyonrails.org/classes/ActiveRecord/Rollback.html
28
+ - Don't print a warning when bigdecimal is required on ruby-3.4+ [#574](https://github.com/ged/ruby-pg/pull/574)
29
+ - Update Windows fat binary gem to OpenSSL-3.3.1 and PostgreSQL-16.3.
30
+
31
+
32
+ ## v1.5.6 [2024-03-01] Lars Kanis <lars@greiz-reinsdorf.de>
33
+
34
+ - Renew address resolution (DNS) in conn.reset. [#558](https://github.com/ged/ruby-pg/pull/558)
35
+ This is important, if DNS is used for load balancing, etc.
36
+ - Make bigdecimal an optional dependency. [#556](https://github.com/ged/ruby-pg/pull/556)
37
+ It's a gem in ruby-3.4+, so that users shouldn't be forced to use it.
38
+
39
+
40
+ ## v1.5.5 [2024-02-15] Lars Kanis <lars@greiz-reinsdorf.de>
41
+
42
+ - Explicitly retype timespec fields to int64_t to fix compatibility with 32bit arches. [#547](https://github.com/ged/ruby-pg/pull/547)
43
+ - Fix possible buffer overflows in PG::BinaryDecoder::CopyRow on 32 bit systems. [#548](https://github.com/ged/ruby-pg/pull/548)
44
+ - Add binary Windows gems for Ruby 3.3.
45
+ - Update Windows fat binary gem to OpenSSL-3.2.1 and PostgreSQL-16.2.
46
+
47
+
1
48
  ## v1.5.4 [2023-09-01] Lars Kanis <lars@greiz-reinsdorf.de>
2
49
 
3
50
  - Fix compiling the pg extension with MSVC 2022. [#535](https://github.com/ged/ruby-pg/pull/535)
4
51
  - Set PG::Connection's encoding even if setting client_encoding on connection startup fails. [#541](https://github.com/ged/ruby-pg/pull/541)
5
52
  - Don't set the server's client_encoding if it's unnecessary. [#542](https://github.com/ged/ruby-pg/pull/542)
6
53
  This is important for connection proxies, who disallow configuration settings.
54
+ - Update Windows fat binary gem to OpenSSL-3.1.2 and PostgreSQL-15.4.
7
55
 
8
56
 
9
57
  ## v1.5.3 [2023-04-28] Lars Kanis <lars@greiz-reinsdorf.de>
@@ -75,7 +123,7 @@ Removed:
75
123
  Repository:
76
124
 
77
125
  - `rake test` tries to find PostgreSQL server commands by pg_config [#503](https://github.com/ged/ruby-pg/pull/503)
78
- So there's no need to set the PATH manuelly any longer.
126
+ So there's no need to set the PATH manually any longer.
79
127
 
80
128
 
81
129
  ## v1.4.6 [2023-02-26] Lars Kanis <lars@greiz-reinsdorf.de>
@@ -144,7 +192,7 @@ Added:
144
192
  Bugfixes:
145
193
 
146
194
  - Try IPv6 and IPv4 addresses, if DNS resolves to both. [#452](https://github.com/ged/ruby-pg/pull/452)
147
- - Re-add block-call semantics to PG::Connection.new accidently removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454)
195
+ - Re-add block-call semantics to PG::Connection.new accidentally removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454)
148
196
  - Handle client error after all data consumed in #copy_data for output. [#455](https://github.com/ged/ruby-pg/pull/455)
149
197
  - Avoid spurious keyword argument warning on Ruby 2.7. [#456](https://github.com/ged/ruby-pg/pull/456)
150
198
  - Change connection setup to respect connect_timeout parameter. [#459](https://github.com/ged/ruby-pg/pull/459)
@@ -183,7 +231,7 @@ Bugfixes:
183
231
 
184
232
  - Don't leak IO in case of connection errors. [#439](https://github.com/ged/ruby-pg/pull/439)
185
233
  Previously it was kept open until the PG::Connection was garbage collected.
186
- - Fix a performance regession in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442)
234
+ - Fix a performance regression in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442)
187
235
  - Fix occasional error Errno::EBADF (Bad file descriptor) while connecting. [#444](https://github.com/ged/ruby-pg/pull/444)
188
236
  - Fix compatibility of res.stream_each* methods with Fiber.scheduler. [#446](https://github.com/ged/ruby-pg/pull/446)
189
237
  - Remove FL_TEST and FL_SET, which are MRI-internal. [#437](https://github.com/ged/ruby-pg/pull/437)
@@ -269,7 +317,7 @@ Type cast enhancements:
269
317
  - Add PG::BasicTypeMapForQueries::BinaryData for encoding of bytea columns. [#348](https://github.com/ged/ruby-pg/pull/348)
270
318
  - Reduce time to build coder maps and permit to reuse them for several type maps per PG::BasicTypeRegistry::CoderMapsBundle.new(conn) . [#376](https://github.com/ged/ruby-pg/pull/376)
271
319
  - Make BasicTypeRegistry a class and use a global default instance of it.
272
- Now a local type registry can be instanciated and given to the type map, to avoid changing shared global states.
320
+ Now a local type registry can be instantiated and given to the type map, to avoid changing shared global states.
273
321
  - Allow PG::BasicTypeMapForQueries to take a Proc as callback for undefined types.
274
322
 
275
323
  Other Enhancements:
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  # -*- rake -*-
2
2
 
3
+ # Enable english error messages, as some specs depend on them
4
+ ENV["LANG"] = "C"
5
+
3
6
  require 'rbconfig'
4
7
  require 'pathname'
5
8
  require 'tmpdir'
@@ -91,7 +94,7 @@ end
91
94
 
92
95
  desc "Update list of server error codes"
93
96
  task :update_error_codes do
94
- URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_15_0"
97
+ URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_17_0"
95
98
 
96
99
  ERRORCODES_TXT = "ext/errorcodes.txt"
97
100
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
data/Rakefile.cross CHANGED
@@ -31,8 +31,8 @@ class CrossLibrary < OpenStruct
31
31
  self.host_platform = toolchain
32
32
 
33
33
  # Cross-compilation constants
34
- self.openssl_version = ENV['OPENSSL_VERSION'] || '3.1.0'
35
- self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '15.2'
34
+ self.openssl_version = ENV['OPENSSL_VERSION'] || '3.4.0'
35
+ self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '17.0'
36
36
 
37
37
  # Check if symlinks work in the current working directory.
38
38
  # This fails, if rake-compiler-dock is running on a Windows box.
@@ -52,9 +52,8 @@ class CrossLibrary < OpenStruct
52
52
 
53
53
  # Static OpenSSL build vars
54
54
  self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
55
-
56
55
  self.openssl_source_uri =
57
- URI( "http://www.openssl.org/source/openssl-#{openssl_version}.tar.gz" )
56
+ URI( "https://github.com/openssl/openssl/releases/download/openssl-#{openssl_version}/openssl-#{openssl_version}.tar.gz" )
58
57
  self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
59
58
  self.openssl_makefile = static_openssl_builddir + 'Makefile'
60
59
 
@@ -119,7 +118,7 @@ class CrossLibrary < OpenStruct
119
118
  self.cmd_prelude = [
120
119
  "env",
121
120
  "CROSS_COMPILE=#{host_platform}-",
122
- "CFLAGS=-DDSO_WIN32",
121
+ "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS",
123
122
  ]
124
123
 
125
124
 
@@ -127,7 +126,7 @@ class CrossLibrary < OpenStruct
127
126
  file openssl_makefile => static_openssl_builddir do |t|
128
127
  chdir( static_openssl_builddir ) do
129
128
  cmd = cmd_prelude.dup
130
- cmd << "./Configure" << "-static" << openssl_config
129
+ cmd << "./Configure" << "threads" << "-static" << openssl_config
131
130
 
132
131
  run( *cmd )
133
132
  end
@@ -184,6 +183,7 @@ class CrossLibrary < OpenStruct
184
183
  "--host=#{host_platform}",
185
184
  '--with-openssl',
186
185
  '--without-zlib',
186
+ '--without-icu',
187
187
  ]
188
188
 
189
189
  chdir( static_postgresql_builddir ) do
@@ -192,7 +192,7 @@ class CrossLibrary < OpenStruct
192
192
  cmd << "CFLAGS=-L#{static_openssl_builddir}"
193
193
  cmd << "LDFLAGS=-L#{static_openssl_builddir}"
194
194
  cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
195
- cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32 -lcrypt32"
195
+ cmd << "LIBS=-lssl -lwsock32 -lgdi32 -lws2_32 -lcrypt32"
196
196
  cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
197
197
 
198
198
  run( *cmd )
@@ -206,6 +206,10 @@ class CrossLibrary < OpenStruct
206
206
  chdir( static_postgresql_srcdir + "common" ) do
207
207
  sh 'make', "-j#{NUM_CPUS}"
208
208
  end
209
+ # Work around missing dependency to errorcodes.h in PostgreSQL-17.0
210
+ chdir( static_postgresql_srcdir + "backend" + "utils" ) do
211
+ sh 'make', "-j#{NUM_CPUS}"
212
+ end
209
213
  chdir( static_postgresql_srcdir + "port" ) do
210
214
  sh 'make', "-j#{NUM_CPUS}"
211
215
  end
@@ -289,8 +293,9 @@ CrossLibraries.each do |xlib|
289
293
  task "gem:windows:#{platform}" => ['gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
290
294
  RakeCompilerDock.sh <<-EOT, platform: platform
291
295
  (cp build/gem/gem-*.pem ~/.gem/ || true) &&
296
+ sudo apt-get update && sudo apt-get install -y bison flex &&
292
297
  bundle install --local &&
293
- rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`" RUBY_CC_VERSION=3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
298
+ rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=3.3.0:3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
294
299
  EOT
295
300
  end
296
301
  desc "Build the windows binary gems"
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDLjCCAhagAwIBAgIBCzANBgkqhkiG9w0BAQsFADA9MQ4wDAYDVQQDDAVrYW5p
3
+ czEXMBUGCgmSJomT8ixkARkWB2NvbWNhcmQxEjAQBgoJkiaJk/IsZAEZFgJkZTAe
4
+ Fw0yMzA0MjgwOTI0NDhaFw0yNDA0MjcwOTI0NDhaMD0xDjAMBgNVBAMMBWthbmlz
5
+ MRcwFQYKCZImiZPyLGQBGRYHY29tY2FyZDESMBAGCgmSJomT8ixkARkWAmRlMIIB
6
+ I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xvpFMdAKo4H46GBYNO96r6b74t++vgQSBTg/AFVwvRZwNSrPPcBfb4xxeEAhRR
20
+ x+LU7feIH7lZ//3buiyD03gLAEtHXai0Y+/VfuWIpwYJAl2BO/tU7FS/dtbJq9oc
21
+ dI36Yyzy+BrCM0WT4oCsagePNb97FaNhl4F6sM5JEPT0ZPxRx0i3G4TNNIYziVos
22
+ 5wFER6XhvvLDFAMh/jMg+s7Wd5SbSHgHNSUaUGVtdWkVPOer6oF0aLdZUR3CETkn
23
+ 5nWXZma/BUd3YgYA/Xumc6QQqIS4p7mr
24
+ -----END CERTIFICATE-----
data/ext/errorcodes.def CHANGED
@@ -453,6 +453,10 @@
453
453
  VALUE klass = define_error_class( "IdleInTransactionSessionTimeout", "25" );
454
454
  register_error_class( "25P03", klass );
455
455
  }
456
+ {
457
+ VALUE klass = define_error_class( "TransactionTimeout", "25" );
458
+ register_error_class( "25P04", klass );
459
+ }
456
460
  {
457
461
  VALUE klass = define_error_class( "InvalidSqlStatementName", NULL );
458
462
  register_error_class( "26000", klass );
@@ -885,11 +889,6 @@
885
889
  VALUE klass = define_error_class( "DuplicateFile", "58" );
886
890
  register_error_class( "58P02", klass );
887
891
  }
888
- {
889
- VALUE klass = define_error_class( "SnapshotTooOld", NULL );
890
- register_error_class( "72000", klass );
891
- register_error_class( "72", klass );
892
- }
893
892
  {
894
893
  VALUE klass = define_error_class( "ConfigFileError", NULL );
895
894
  register_error_class( "F0000", klass );
data/ext/errorcodes.txt CHANGED
@@ -2,7 +2,7 @@
2
2
  # errcodes.txt
3
3
  # PostgreSQL error codes
4
4
  #
5
- # Copyright (c) 2003-2022, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2024, 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
@@ -252,6 +252,7 @@ Section: Class 25 - Invalid Transaction State
252
252
  25P01 E ERRCODE_NO_ACTIVE_SQL_TRANSACTION no_active_sql_transaction
253
253
  25P02 E ERRCODE_IN_FAILED_SQL_TRANSACTION in_failed_sql_transaction
254
254
  25P03 E ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT idle_in_transaction_session_timeout
255
+ 25P04 E ERRCODE_TRANSACTION_TIMEOUT transaction_timeout
255
256
 
256
257
  Section: Class 26 - Invalid SQL Statement Name
257
258
 
@@ -439,10 +440,6 @@ Section: Class 58 - System Error (errors external to PostgreSQL itself)
439
440
  58P01 E ERRCODE_UNDEFINED_FILE undefined_file
440
441
  58P02 E ERRCODE_DUPLICATE_FILE duplicate_file
441
442
 
442
- Section: Class 72 - Snapshot Failure
443
- # (class borrowed from Oracle)
444
- 72000 E ERRCODE_SNAPSHOT_TOO_OLD snapshot_too_old
445
-
446
443
  Section: Class F0 - Configuration File Error
447
444
 
448
445
  # (PostgreSQL-specific error class)
data/ext/extconf.rb CHANGED
@@ -9,6 +9,8 @@ if ENV['MAINTAINER_MODE']
9
9
  ' -ggdb' <<
10
10
  ' -DDEBUG' <<
11
11
  ' -pedantic'
12
+ $LDFLAGS <<
13
+ ' -ggdb'
12
14
  end
13
15
 
14
16
  if pgdir = with_config( 'pg' )
@@ -158,6 +160,7 @@ have_func 'timegm'
158
160
  have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
159
161
  have_func 'rb_gc_mark_movable' # since ruby-2.7
160
162
  have_func 'rb_io_wait' # since ruby-3.0
163
+ have_func 'rb_io_descriptor' # since ruby-3.1
161
164
 
162
165
  # unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
163
166
  have_header 'unistd.h'
data/ext/pg.c CHANGED
@@ -543,7 +543,7 @@ Init_pg_ext(void)
543
543
  /* Result#result_error_field argument constant
544
544
  *
545
545
  * The SQLSTATE code for the error.
546
- * The SQLSTATE code identies the type of error that has occurred; it can be used by front-end applications to perform specific operations (such as error handling) in response to a particular database error.
546
+ * The SQLSTATE code identifies the type of error that has occurred; it can be used by front-end applications to perform specific operations (such as error handling) in response to a particular database error.
547
547
  * For a list of the possible SQLSTATE codes, see Appendix A.
548
548
  * This field is not localizable, and is always present.
549
549
  */
@@ -233,6 +233,8 @@ j2date(int jd, int *year, int *month, int *day)
233
233
  *
234
234
  * This is a decoder class for conversion of PostgreSQL binary date
235
235
  * to Ruby Date objects.
236
+ *
237
+ * As soon as this class is used, it requires the ruby standard library 'date'.
236
238
  */
237
239
  static VALUE
238
240
  pg_bin_dec_date(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
@@ -185,7 +185,7 @@ pg_bin_enc_timestamp(t_pg_coder *this, VALUE value, char *out, VALUE *intermedia
185
185
  ts = rb_time_timespec(*intermediate);
186
186
  /* PostgreSQL's timestamp is based on year 2000 and Ruby's time is based on 1970.
187
187
  * Adjust the 30 years difference. */
188
- timestamp = (ts.tv_sec - 10957L * 24L * 3600L) * 1000000 + (ts.tv_nsec / 1000);
188
+ timestamp = ((int64_t)ts.tv_sec - 10957L * 24L * 3600L) * 1000000 + ((int64_t)ts.tv_nsec / 1000);
189
189
 
190
190
  if( this->flags & PG_CODER_TIMESTAMP_DB_LOCAL ) {
191
191
  /* send as local time */
data/ext/pg_connection.c CHANGED
@@ -33,8 +33,8 @@ static VALUE pgconn_async_flush(VALUE self);
33
33
  #ifdef __GNUC__
34
34
  __attribute__((format(printf, 3, 4)))
35
35
  #endif
36
- static void
37
- pg_raise_conn_error( VALUE klass, VALUE self, const char *format, ...)
36
+ NORETURN( static void
37
+ pg_raise_conn_error( VALUE klass, VALUE self, const char *format, ...))
38
38
  {
39
39
  VALUE msg, error;
40
40
  va_list ap;
@@ -264,6 +264,7 @@ pgconn_s_allocate( VALUE klass )
264
264
  RB_OBJ_WRITE(self, &this->decoder_for_get_copy_data, Qnil);
265
265
  RB_OBJ_WRITE(self, &this->trace_stream, Qnil);
266
266
  rb_ivar_set(self, rb_intern("@calls_to_put_copy_data"), INT2FIX(0));
267
+ rb_ivar_set(self, rb_intern("@iopts_for_reset"), Qnil);
267
268
 
268
269
  return self;
269
270
  }
@@ -515,9 +516,9 @@ static VALUE
515
516
  pgconn_connect_poll(VALUE self)
516
517
  {
517
518
  PostgresPollingStatusType status;
518
- status = gvl_PQconnectPoll(pg_get_pgconn(self));
519
519
 
520
520
  pgconn_close_socket_io(self);
521
+ status = gvl_PQconnectPoll(pg_get_pgconn(self));
521
522
 
522
523
  return INT2FIX((int)status);
523
524
  }
@@ -563,6 +564,27 @@ pgconn_sync_reset( VALUE self )
563
564
  return self;
564
565
  }
565
566
 
567
+ static VALUE
568
+ pgconn_reset_start2( VALUE self, VALUE conninfo )
569
+ {
570
+ t_pg_connection *this = pg_get_connection( self );
571
+
572
+ /* Close old connection */
573
+ pgconn_close_socket_io( self );
574
+ PQfinish( this->pgconn );
575
+
576
+ /* Start new connection */
577
+ this->pgconn = gvl_PQconnectStart( StringValueCStr(conninfo) );
578
+
579
+ if( this->pgconn == NULL )
580
+ rb_raise(rb_ePGerror, "PQconnectStart() unable to allocate PGconn structure");
581
+
582
+ if ( PQstatus(this->pgconn) == CONNECTION_BAD )
583
+ pg_raise_conn_error( rb_eConnectionBad, self, "%s", PQerrorMessage(this->pgconn));
584
+
585
+ return Qnil;
586
+ }
587
+
566
588
  /*
567
589
  * call-seq:
568
590
  * conn.reset_start() -> nil
@@ -594,9 +616,9 @@ static VALUE
594
616
  pgconn_reset_poll(VALUE self)
595
617
  {
596
618
  PostgresPollingStatusType status;
597
- status = gvl_PQresetPoll(pg_get_pgconn(self));
598
619
 
599
620
  pgconn_close_socket_io(self);
621
+ status = gvl_PQresetPoll(pg_get_pgconn(self));
600
622
 
601
623
  return INT2FIX((int)status);
602
624
  }
@@ -2245,6 +2267,17 @@ pgconn_notifies(VALUE self)
2245
2267
  return hash;
2246
2268
  }
2247
2269
 
2270
+ #ifndef HAVE_RB_IO_DESCRIPTOR
2271
+ static int
2272
+ rb_io_descriptor(VALUE io)
2273
+ {
2274
+ Check_Type(io, T_FILE);
2275
+ rb_io_t *fptr = RFILE(io)->fptr;
2276
+ rb_io_check_closed(fptr);
2277
+ return fptr->fd;
2278
+ }
2279
+ #endif
2280
+
2248
2281
  #if defined(_WIN32)
2249
2282
 
2250
2283
  /* We use a specialized implementation of rb_io_wait() on Windows.
@@ -2265,7 +2298,6 @@ int rb_w32_wait_events( HANDLE *events, int num, DWORD timeout );
2265
2298
 
2266
2299
  static VALUE
2267
2300
  pg_rb_thread_io_wait(VALUE io, VALUE events, VALUE timeout) {
2268
- rb_io_t *fptr;
2269
2301
  struct timeval ptimeout;
2270
2302
 
2271
2303
  struct timeval aborttime={0,0}, currtime, waittime;
@@ -2276,7 +2308,6 @@ pg_rb_thread_io_wait(VALUE io, VALUE events, VALUE timeout) {
2276
2308
  long w32_events = 0;
2277
2309
  DWORD wait_ret;
2278
2310
 
2279
- GetOpenFile((io), fptr);
2280
2311
  if( !NIL_P(timeout) ){
2281
2312
  ptimeout.tv_sec = (time_t)(NUM2DBL(timeout));
2282
2313
  ptimeout.tv_usec = (time_t)((NUM2DBL(timeout) - (double)ptimeout.tv_sec) * 1e6);
@@ -2290,7 +2321,7 @@ pg_rb_thread_io_wait(VALUE io, VALUE events, VALUE timeout) {
2290
2321
  if(rb_events & PG_RUBY_IO_PRIORITY) w32_events |= FD_OOB;
2291
2322
 
2292
2323
  for(;;) {
2293
- if ( WSAEventSelect(_get_osfhandle(fptr->fd), hEvent, w32_events) == SOCKET_ERROR ) {
2324
+ if ( WSAEventSelect(_get_osfhandle(rb_io_descriptor(io)), hEvent, w32_events) == SOCKET_ERROR ) {
2294
2325
  WSACloseEvent( hEvent );
2295
2326
  rb_raise( rb_eConnectionBad, "WSAEventSelect socket error: %d", WSAGetLastError() );
2296
2327
  }
@@ -2333,7 +2364,7 @@ static VALUE
2333
2364
  pg_rb_io_wait(VALUE io, VALUE events, VALUE timeout) {
2334
2365
  #if defined(HAVE_RUBY_FIBER_SCHEDULER_H)
2335
2366
  /* We don't support Fiber.scheduler on Windows ruby-3.0 because there is no fast way to check whether a scheduler is active.
2336
- * Fortunatelly ruby-3.1 offers a C-API for it.
2367
+ * Fortunately ruby-3.1 offers a C-API for it.
2337
2368
  */
2338
2369
  VALUE scheduler = rb_fiber_scheduler_current();
2339
2370
 
@@ -2363,16 +2394,14 @@ typedef enum {
2363
2394
 
2364
2395
  static VALUE
2365
2396
  pg_rb_io_wait(VALUE io, VALUE events, VALUE timeout) {
2366
- rb_io_t *fptr;
2367
2397
  struct timeval waittime;
2368
2398
  int res;
2369
2399
 
2370
- GetOpenFile((io), fptr);
2371
2400
  if( !NIL_P(timeout) ){
2372
2401
  waittime.tv_sec = (time_t)(NUM2DBL(timeout));
2373
2402
  waittime.tv_usec = (time_t)((NUM2DBL(timeout) - (double)waittime.tv_sec) * 1e6);
2374
2403
  }
2375
- res = rb_wait_for_single_fd(fptr->fd, NUM2UINT(events), NIL_P(timeout) ? NULL : &waittime);
2404
+ res = rb_wait_for_single_fd(rb_io_descriptor(io), NUM2UINT(events), NIL_P(timeout) ? NULL : &waittime);
2376
2405
 
2377
2406
  return UINT2NUM(res);
2378
2407
  }
@@ -3107,7 +3136,9 @@ pgconn_async_get_last_result(VALUE self)
3107
3136
  for(;;) {
3108
3137
  int status;
3109
3138
 
3110
- /* wait for input (without blocking) before reading each result */
3139
+ /* Wait for input before reading each result.
3140
+ * That way we support the ruby-3.x IO scheduler and don't block other ruby threads.
3141
+ */
3111
3142
  wait_socket_readable(self, NULL, get_result_readable);
3112
3143
 
3113
3144
  cur = gvl_PQgetResult(conn);
@@ -3141,7 +3172,7 @@ pgconn_async_get_last_result(VALUE self)
3141
3172
  * Returns:
3142
3173
  * * +nil+ when the connection is already idle
3143
3174
  * * +true+ when some results have been discarded
3144
- * * +false+ when a failure occured and the connection was closed
3175
+ * * +false+ when a failure occurred and the connection was closed
3145
3176
  *
3146
3177
  */
3147
3178
  static VALUE
@@ -4468,6 +4499,7 @@ init_pg_connection(void)
4468
4499
  rb_define_method(rb_cPGconn, "finished?", pgconn_finished_p, 0);
4469
4500
  rb_define_method(rb_cPGconn, "sync_reset", pgconn_sync_reset, 0);
4470
4501
  rb_define_method(rb_cPGconn, "reset_start", pgconn_reset_start, 0);
4502
+ rb_define_private_method(rb_cPGconn, "reset_start2", pgconn_reset_start2, 1);
4471
4503
  rb_define_method(rb_cPGconn, "reset_poll", pgconn_reset_poll, 0);
4472
4504
  rb_define_alias(rb_cPGconn, "close", "finish");
4473
4505
 
data/ext/pg_copy_coder.c CHANGED
@@ -212,6 +212,7 @@ pg_copycoder_type_map_get(VALUE self)
212
212
  *
213
213
  * See also PG::TextDecoder::CopyRow for the decoding direction with
214
214
  * PG::Connection#get_copy_data .
215
+ * And see PG::BinaryEncoder::CopyRow for an encoder of the COPY binary format.
215
216
  */
216
217
  static int
217
218
  pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
@@ -235,7 +236,7 @@ pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedia
235
236
  char *ptr1;
236
237
  char *ptr2;
237
238
  int strlen;
238
- int backslashs;
239
+ int backslashes;
239
240
  VALUE subint;
240
241
  VALUE entry;
241
242
 
@@ -286,19 +287,19 @@ pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedia
286
287
  ptr2 = current_out + strlen;
287
288
 
288
289
  /* count required backlashs */
289
- for(backslashs = 0; ptr1 != ptr2; ptr1++) {
290
+ for(backslashes = 0; ptr1 != ptr2; ptr1++) {
290
291
  /* Escape backslash itself, newline, carriage return, and the current delimiter character. */
291
292
  if(*ptr1 == '\\' || *ptr1 == '\n' || *ptr1 == '\r' || *ptr1 == this->delimiter){
292
- backslashs++;
293
+ backslashes++;
293
294
  }
294
295
  }
295
296
 
296
297
  ptr1 = current_out + strlen;
297
- ptr2 = current_out + strlen + backslashs;
298
+ ptr2 = current_out + strlen + backslashes;
298
299
  current_out = ptr2;
299
300
 
300
301
  /* Then store the escaped string on the final position, walking
301
- * right to left, until all backslashs are placed. */
302
+ * right to left, until all backslashes are placed. */
302
303
  while( ptr1 != ptr2 ) {
303
304
  *--ptr2 = *--ptr1;
304
305
  if(*ptr1 == '\\' || *ptr1 == '\n' || *ptr1 == '\r' || *ptr1 == this->delimiter){
@@ -358,6 +359,7 @@ pg_text_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermedia
358
359
  *
359
360
  * See also PG::BinaryDecoder::CopyRow for the decoding direction with
360
361
  * PG::Connection#get_copy_data .
362
+ * And see PG::TextEncoder::CopyRow for an encoder of the COPY text format.
361
363
  */
362
364
  static int
363
365
  pg_bin_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate, int enc_idx)
@@ -391,7 +393,7 @@ pg_bin_enc_copy_row(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediat
391
393
 
392
394
  switch(TYPE(entry)){
393
395
  case T_NIL:
394
- /* 4 bytes for -1 indicationg a NULL value */
396
+ /* 4 bytes for -1 indicating a NULL value */
395
397
  PG_RB_STR_ENSURE_CAPA( *intermediate, 4, current_out, end_capa_ptr );
396
398
  write_nbo32(-1, current_out);
397
399
  current_out += 4;
@@ -496,6 +498,7 @@ GetDecimalFromHex(char hex)
496
498
  *
497
499
  * See also PG::TextEncoder::CopyRow for the encoding direction with
498
500
  * PG::Connection#put_copy_data .
501
+ * And see PG::BinaryDecoder::CopyRow for a decoder of the COPY binary format.
499
502
  */
500
503
  /*
501
504
  * Parse the current line into separate attributes (fields),
@@ -763,6 +766,7 @@ static const char BinarySignature[11] = "PGCOPY\n\377\r\n\0";
763
766
  *
764
767
  * See also PG::BinaryEncoder::CopyRow for the encoding direction with
765
768
  * PG::Connection#put_copy_data .
769
+ * And see PG::TextDecoder::CopyRow for a decoder of the COPY text format.
766
770
  */
767
771
  static VALUE
768
772
  pg_bin_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tuple, int _field, int enc_idx)
@@ -795,26 +799,26 @@ pg_bin_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tupl
795
799
  cur_ptr = input_line;
796
800
  line_end_ptr = input_line + len;
797
801
 
798
- if (cur_ptr + 11 <= line_end_ptr && memcmp(cur_ptr, BinarySignature, 11) == 0){
802
+ if (line_end_ptr - cur_ptr >= 11 && memcmp(cur_ptr, BinarySignature, 11) == 0){
799
803
  /* binary COPY header signature detected -> just drop it */
800
804
  int ext_bytes;
801
805
  cur_ptr += 11;
802
806
 
803
807
  /* read flags */
804
- if (cur_ptr + 4 > line_end_ptr) goto length_error;
808
+ if (line_end_ptr - cur_ptr < 4 ) goto length_error;
805
809
  cur_ptr += 4;
806
810
 
807
811
  /* read header extensions */
808
- if (cur_ptr + 4 > line_end_ptr) goto length_error;
812
+ if (line_end_ptr - cur_ptr < 4 ) goto length_error;
809
813
  ext_bytes = read_nbo32(cur_ptr);
810
814
  if (ext_bytes < 0) goto length_error;
811
815
  cur_ptr += 4;
812
- if (cur_ptr + ext_bytes > line_end_ptr) goto length_error;
816
+ if (line_end_ptr - cur_ptr < ext_bytes ) goto length_error;
813
817
  cur_ptr += ext_bytes;
814
818
  }
815
819
 
816
820
  /* read row header */
817
- if (cur_ptr + 2 > line_end_ptr) goto length_error;
821
+ if (line_end_ptr - cur_ptr < 2 ) goto length_error;
818
822
  nfields = read_nbo16(cur_ptr);
819
823
  cur_ptr += 2;
820
824
 
@@ -830,7 +834,7 @@ pg_bin_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tupl
830
834
  VALUE field_value;
831
835
 
832
836
  /* read field size */
833
- if (cur_ptr + 4 > line_end_ptr) goto length_error;
837
+ if (line_end_ptr - cur_ptr < 4 ) goto length_error;
834
838
  input_len = read_nbo32(cur_ptr);
835
839
  cur_ptr += 4;
836
840
 
@@ -839,7 +843,7 @@ pg_bin_dec_copy_row(t_pg_coder *conv, const char *input_line, int len, int _tupl
839
843
  /* NULL indicator */
840
844
  rb_ary_push(array, Qnil);
841
845
  } else {
842
- if (cur_ptr + input_len > line_end_ptr) goto length_error;
846
+ if (line_end_ptr - cur_ptr < input_len ) goto length_error;
843
847
 
844
848
  /* copy input data to field_str */
845
849
  PG_RB_STR_ENSURE_CAPA( field_str, input_len, output_ptr, end_capa_ptr );