pg 1.7.0 → 1.7.1

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 (40) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile +17 -1
  5. data/README.md +1 -0
  6. data/Rakefile +8 -3
  7. data/duel/coder_duel.rb +105 -0
  8. data/duel/connect_duel.rb +26 -0
  9. data/duel/copy_duel.rb +59 -0
  10. data/duel/duel_helper.rb +47 -0
  11. data/duel/escape_duel.rb +31 -0
  12. data/duel/query_duel.rb +42 -0
  13. data/duel/result_duel.rb +64 -0
  14. data/duel/type_map_duel.rb +53 -0
  15. data/ext/errorcodes.def +4 -0
  16. data/ext/errorcodes.txt +2 -1
  17. data/ext/extconf.rb +10 -4
  18. data/ext/pg.c +53 -0
  19. data/ext/pg.h +6 -0
  20. data/ext/pg_binary_decoder.c +3 -4
  21. data/ext/pg_copy_coder.c +7 -3
  22. data/ext/pg_record_coder.c +5 -1
  23. data/ext/pg_text_decoder.c +113 -69
  24. data/ext/pg_text_encoder.c +6 -3
  25. data/ext/pg_tuple.c +17 -1
  26. data/ext/pg_type_map_by_class.c +1 -1
  27. data/ext/pg_type_map_by_column.c +1 -1
  28. data/ext/pg_util.c +8 -8
  29. data/lib/pg/connection.rb +3 -2
  30. data/lib/pg/text_decoder/date.rb +2 -14
  31. data/lib/pg/version.rb +1 -1
  32. data/ports/patches/postgresql/19.0/0001-Don-t-stop-build-due-to-atexit.patch +27 -0
  33. data/ports/patches/postgresql/19.0/0001-Fix-compatibility-to-old-MacOSX11.1.sdk-of-rake-comp.patch +31 -0
  34. data/ports/patches/postgresql/19.0/0001-PATCH-Don-t-use-workaround-of-__builtin_setjmp-on-MI.patch +27 -0
  35. data.tar.gz.sig +0 -0
  36. metadata +14 -4
  37. metadata.gz.sig +0 -0
  38. data/ports/patches/postgresql/18.6/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +0 -42
  39. /data/ports/patches/krb5/{1.22.2 → 1.22.3}/0001-Allow-static-linking-krb5-library.patch +0 -0
  40. /data/ports/patches/krb5/{1.22.2 → 1.22.3}/0002-unknown-command-line-option-on-clang.patch +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01ff8f72c20e6b96364acee8cc436df0d1305861cd3edba88be07c81fc0e2e55
4
- data.tar.gz: e1dce91f9a03eaf081e11705175902c43471710612d299d626e2bb796c6990f6
3
+ metadata.gz: 2d6617a6d1e5ea28143a434aa080fb0ca06128aee1c05c59395467340412cccc
4
+ data.tar.gz: 799780c0c55cca708f56bbde934f1a0602b248f748c6d0410860350c6f6c5c15
5
5
  SHA512:
6
- metadata.gz: 1326d36f1ebcd07e755615fa2bdc78c46bcf937f1d085c080816dee7f93790ce3aedcb58ff3be4840e6f1c713c7a81e2879bfa934d4fbcdea3faa891f83fc534
7
- data.tar.gz: 80b0474f35ffd2ef4339fbb635a375b4de216ef3a0c8f3b9ad5da6b4f5e6767edae9794fe15364ca6f27667867e137cba809b1770c63436102f3389c3c42f27a
6
+ metadata.gz: 7755a1ed7d169c50550c962393345bc4dc44d95ead458ded9e81ee38a5c16cd9fea56f4872fb4a0f992b825ec99c4c2f98dfd80b0b2f888cb6737c72adbd83c7
7
+ data.tar.gz: 8d86d258efe6e60b14450719e85bc7a806c479bfc5eb62e7c51d6d27c09640f9172a5e54e76e1f84601019fe5eef52d43c5942ac061e7ed47dec050314e9a981
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## v1.7.1 [2026-12-06] Lars Kanis <lars@greiz-reinsdorf.de>
2
+
3
+ - Update native binary gems to OpenSSL-3.6.5, krb5-1.22.3 and PostgreSQL-19.0. [#778](https://github.com/ged/ruby-pg/pull/778)
4
+ - Re-introduce rpath for darwin only, which was removed in #699 / pg-1.7.0. [#778](https://github.com/ged/ruby-pg/pull/778)
5
+ - Update error classes to PostgreSQL-19.
6
+ - CopyRow, Array, Record and Literal: Deny multibyte encodings that may contain ASCII byte values in trailing bytes, because they are incompatible to byte-wise traversal and can raise security issues. [#777](https://github.com/ged/ruby-pg/pull/777)
7
+ - Bound the `connect_timeout` retry loop and match hosts resolved by libpq.
8
+ Avoid reconnections once `stop_time` has passed. [#774](https://github.com/ged/ruby-pg/pull/774)
9
+ - Decode IPv4-mapped IPv6 addresses in TextDecoder::Inet like `::ffff:1.2.3.4` . [#772](https://github.com/ged/ruby-pg/pull/772)
10
+ - Materialize PG::Tuple objects when freezing and undef PG::Tuple.new . [#770](https://github.com/ged/ruby-pg/pull/770)
11
+ - Decode text timestamps ~40x faster on macOS, ~15x on Windows and ~1.4x on Linux. [#759](https://github.com/ged/ruby-pg/pull/759)
12
+ - Implement PG::TextDecoder::Date in C which is 4 times faster. [#758](https://github.com/ged/ruby-pg/pull/758)
13
+ - Avoid undefined behavior on non-ASCII bytes in the text date and timestamp decoders. [#761](https://github.com/ged/ruby-pg/pull/761)
14
+ - Make use of new data type for lengths in ruby-4.1+. [#754](https://github.com/ged/ruby-pg/pull/754)
15
+
16
+
1
17
  ## v1.7.0 [2026-10-02] Lars Kanis <lars@greiz-reinsdorf.de>
2
18
 
3
19
  Added:
data/Gemfile CHANGED
@@ -10,10 +10,26 @@ group :development do
10
10
  gem "mini_portile2", "~> 2.1"
11
11
  end
12
12
 
13
+ # Duel, for the performance regression guards in duel/: install it with
14
+ # `bundle config set --local with duel`, and run them with `rake duel`.
15
+ # Its PostgreSQL plugin needs a released pg, which would load its own
16
+ # pg_ext in the specs and in Duel's workers, so the group is optional,
17
+ # and the released pg is the source gem, whose lib/ has no pg_ext of the
18
+ # Ruby's version (lib/3.4/pg_ext) for pg.rb to load ahead of this tree's.
19
+ group :duel, optional: true do
20
+ # Duel requires Ruby 3.4 or later
21
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4")
22
+ gem "duel", "~> 0.3.1"
23
+ gem "duel-postgresql", "~> 0.3.1"
24
+ gem "pg", force_ruby_platform: true
25
+ end
26
+ gem "stackprof", platforms: :mri
27
+ end
28
+
13
29
  group :test do
14
30
  gem "bundler", ">= 1.16", "< 5.0"
15
31
  gem "rake-compiler", "~> 1.0"
16
- gem "rake-compiler-dock", "~> 1.11.0" #, git: "https://github.com/rake-compiler/rake-compiler-dock"
32
+ gem "rake-compiler-dock", "~> 1.12.0" #, git: "https://github.com/rake-compiler/rake-compiler-dock"
17
33
  gem "rspec", "~> 3.5"
18
34
  # "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
19
35
  # Specs should succeed without it, but 4 examples are then excluded.
data/README.md CHANGED
@@ -38,6 +38,7 @@ See the PG::Connection class for query methods and the PG::Result class for info
38
38
  [![Build Status Github Actions](https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml/badge.svg?branch=master)](https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml)
39
39
  [![Binary gems](https://github.com/ged/ruby-pg/actions/workflows/binary-gems.yml/badge.svg?branch=master)](https://github.com/ged/ruby-pg/actions/workflows/binary-gems.yml)
40
40
  [![Build Status Appveyor](https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true)](https://ci.appveyor.com/project/ged/ruby-pg-9j8l3)
41
+ [![Duel](https://raw.githubusercontent.com/sferik/duel-ruby/main/assets/badge.svg)](https://github.com/ged/ruby-pg/actions/workflows/perf.yml)
41
42
 
42
43
 
43
44
  ## Requirements
data/Rakefile CHANGED
@@ -120,8 +120,6 @@ CrossLibraries.each do |xlib|
120
120
  task "gem:native:#{platform}" => ['gem:native:prepare'] do
121
121
  RakeCompilerDock.sh <<-EOT, platform: platform
122
122
  #{ "sudo apt-get update && sudo apt-get install -y bison flex &&" if platform =~ /darwin/ }
123
- #{ # remove nm on Linux to suppress PostgreSQL's check for exit which raises thread_exit as a false positive:
124
- "sudo mv `which nm` `which nm`.bak &&" if platform =~ /linux/ }
125
123
  sudo apt-get update && sudo apt-get install -y bison flex &&
126
124
  (cp build/gem/gem-*.pem ~/.gem/ || true) &&
127
125
  bundle install --local &&
@@ -157,7 +155,7 @@ end
157
155
  desc "Update list of server error codes"
158
156
  task :update_error_codes do
159
157
  # URL_ERRORCODES_TXT = "https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_18_0"
160
- URL_ERRORCODES_TXT = "https://raw.githubusercontent.com/postgres/postgres/refs/tags/REL_18_0/src/backend/utils/errcodes.txt"
158
+ URL_ERRORCODES_TXT = "https://raw.githubusercontent.com/postgres/postgres/refs/tags/REL_19_0/src/backend/utils/errcodes.txt"
161
159
 
162
160
  ERRORCODES_TXT = "ext/errorcodes.txt"
163
161
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
@@ -181,3 +179,10 @@ task :translate do
181
179
  sh "po4a po4a.cfg"
182
180
  end
183
181
  end
182
+
183
+ begin
184
+ require "duel/rake_task"
185
+ Duel::RakeTask.new
186
+ rescue LoadError
187
+ # Duel requires Ruby 3.4 or later, and the Gemfile's optional duel group
188
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # Encoders and decoders on their own, 100 fixed values a call, as a type
6
+ # map runs them on a column: the text format, which results come in by
7
+ # default, and the binary one.
8
+
9
+ duel "text decoder: Integer" do
10
+ once { @decoder = PG::TextDecoder::Integer.new }
11
+ TEXT_VALUES[:integers].each { |value| @decoder.decode(value) }
12
+ end
13
+
14
+ duel "text decoder: Float" do
15
+ once { @decoder = PG::TextDecoder::Float.new }
16
+ TEXT_VALUES[:floats].each { |value| @decoder.decode(value) }
17
+ end
18
+
19
+ duel "text decoder: TimestampWithoutTimeZone" do
20
+ once { @decoder = PG::TextDecoder::TimestampWithoutTimeZone.new }
21
+ TEXT_VALUES[:timestamps].each { |value| @decoder.decode(value) }
22
+ end
23
+
24
+ duel "text decoder: TimestampWithTimeZone" do
25
+ once { @decoder = PG::TextDecoder::TimestampWithTimeZone.new }
26
+ TEXT_VALUES[:timestamptzs].each { |value| @decoder.decode(value) }
27
+ end
28
+
29
+ duel "text decoder: Date" do
30
+ once { @decoder = PG::TextDecoder::Date.new }
31
+ TEXT_VALUES[:dates].each { |value| @decoder.decode(value) }
32
+ end
33
+
34
+ duel "text decoder: an Array of 100 integers" do
35
+ once do
36
+ @decoder = PG::TextDecoder::Array.new(elements_type: PG::TextDecoder::Integer.new)
37
+ @array = "{#{TEXT_VALUES[:integers].join(',')}}"
38
+ end
39
+ @decoder.decode(@array)
40
+ end
41
+
42
+ duel "text decoder: an Array of quoted strings, nested" do
43
+ once do
44
+ @decoder = PG::TextDecoder::Array.new(elements_type: PG::TextDecoder::String.new)
45
+ row = Array.new(10) { |i| %("name \\"#{i}\\", with, commas") }.join(",")
46
+ @array = "{#{Array.new(10) { "{#{row}}" }.join(',')}}"
47
+ end
48
+ @decoder.decode(@array)
49
+ end
50
+
51
+ duel "text decoder: Bytea of 4 KB" do
52
+ once do
53
+ @decoder = PG::TextDecoder::Bytea.new
54
+ @hex = "\\x#{(0...4096).map { |i| format('%02x', i % 256) }.join}"
55
+ end
56
+ @decoder.decode(@hex)
57
+ end
58
+
59
+ duel "text encoder: Integer" do
60
+ once do
61
+ @encoder = PG::TextEncoder::Integer.new
62
+ @integers = TEXT_VALUES[:integers].map(&:to_i)
63
+ end
64
+ @integers.each { |value| @encoder.encode(value) }
65
+ end
66
+
67
+ duel "text encoder: TimestampWithTimeZone" do
68
+ once { @encoder = PG::TextEncoder::TimestampWithTimeZone.new }
69
+ TIMES.each { |value| @encoder.encode(value) }
70
+ end
71
+
72
+ duel "text encoder: an Array of strings that need quoting" do
73
+ once do
74
+ @encoder = PG::TextEncoder::Array.new(elements_type: PG::TextEncoder::String.new)
75
+ @array = Array.new(10) { |i| Array.new(10) { |j| %(name "#{i}-#{j}", with {braces}) } }
76
+ end
77
+ @encoder.encode(@array)
78
+ end
79
+
80
+ duel "binary decoder: Integer, Float and TimestampUtc" do
81
+ once do
82
+ @integer = PG::BinaryDecoder::Integer.new
83
+ @float = PG::BinaryDecoder::Float.new
84
+ @timestamp = PG::BinaryDecoder::TimestampUtc.new
85
+ @int8s = TEXT_VALUES[:integers].map { |value| [value.to_i].pack("q>") }
86
+ @float8s = TEXT_VALUES[:floats].map { |value| [value.to_f].pack("G") }
87
+ @times = TIMES.map { |time| PG::BinaryEncoder::TimestampUtc.new.encode(time) }
88
+ end
89
+ @int8s.each { |value| @integer.decode(value) }
90
+ @float8s.each { |value| @float.decode(value) }
91
+ @times.each { |value| @timestamp.decode(value) }
92
+ end
93
+
94
+ duel "binary encoder: Int8, Float8 and TimestampUtc" do
95
+ once do
96
+ @int8 = PG::BinaryEncoder::Int8.new
97
+ @float8 = PG::BinaryEncoder::Float8.new
98
+ @timestamp = PG::BinaryEncoder::TimestampUtc.new
99
+ @integers = TEXT_VALUES[:integers].map(&:to_i)
100
+ @floats = TEXT_VALUES[:floats].map(&:to_f)
101
+ end
102
+ @integers.each { |value| @int8.encode(value) }
103
+ @floats.each { |value| @float8.encode(value) }
104
+ TIMES.each { |value| @timestamp.encode(value) }
105
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # What happens to the connection parameters before libpq connects: every
6
+ # PG.connect parses them, and a pool or an ORM builds them from a URL or a
7
+ # Hash. No connection is made.
8
+
9
+ duel "connect: parse_connect_args of a URL" do
10
+ PG::Connection.parse_connect_args(
11
+ "postgres://jane:secret@db.example.com:5433/app_production?sslmode=require&connect_timeout=5"
12
+ )
13
+ end
14
+
15
+ duel "connect: parse_connect_args of a keyword string" do
16
+ PG::Connection.parse_connect_args("host=db.example.com port=5433 dbname=app_production user=jane sslmode=require")
17
+ end
18
+
19
+ duel "connect: parse_connect_args of a Hash" do
20
+ PG::Connection.parse_connect_args(host: "db.example.com", port: 5433, dbname: "app_production", user: "jane",
21
+ password: "it's secret", sslmode: "require", application_name: "web")
22
+ end
23
+
24
+ duel "connect: conninfo_hash of a connection", setup: -> { @conn = pg_connection }, teardown: -> { @conn.close } do
25
+ @conn.conninfo_hash
26
+ end
data/duel/copy_duel.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # COPY, the fast way in and out of a table, with the CopyRow coders: an
6
+ # encoder that turns each row (an Array) into a line, and a decoder that
7
+ # turns each line back. On their own first, then through the worker's
8
+ # server.
9
+
10
+ ROWS = Array.new(100) do |i|
11
+ [i, "user #{i}", "line\twith a tab", i.even? ? nil : "O'Brien \\ #{i}", (i * 1.5).to_s]
12
+ end.freeze
13
+
14
+ duel "copy: encode 100 rows with TextEncoder::CopyRow" do
15
+ once { @encoder = PG::TextEncoder::CopyRow.new }
16
+ ROWS.each { |row| @encoder.encode(row) }
17
+ end
18
+
19
+ duel "copy: decode 100 lines with TextDecoder::CopyRow" do
20
+ once do
21
+ @decoder = PG::TextDecoder::CopyRow.new
22
+ encoder = PG::TextEncoder::CopyRow.new
23
+ @lines = ROWS.map { |row| encoder.encode(row) }
24
+ end
25
+ @lines.each { |line| @decoder.decode(line) }
26
+ end
27
+
28
+ copy_table = lambda do
29
+ @conn = pg_connection
30
+ @conn.exec("CREATE TEMP TABLE copied (id int, name text, note text, other text, score text)")
31
+ columns = PG::TypeMapByColumn.new([PG::TextEncoder::Integer.new, nil, nil, nil, nil])
32
+ @encoder = PG::TextEncoder::CopyRow.new(type_map: columns)
33
+ end
34
+
35
+ # Each iteration's rows are rolled back, so the table never grows.
36
+ rolled_back = lambda do |iteration|
37
+ @conn.exec("BEGIN")
38
+ iteration.call
39
+ @conn.exec("ROLLBACK")
40
+ end
41
+
42
+ duel "copy: COPY 100 rows in with an encoder",
43
+ setup: copy_table, teardown: -> { @conn.close }, around_iteration: rolled_back do
44
+ @conn.copy_data("COPY copied FROM STDIN", @encoder) do
45
+ ROWS.each { |row| @conn.put_copy_data(row) }
46
+ end
47
+ end
48
+
49
+ copy_out = lambda do
50
+ @conn = pg_connection
51
+ columns = PG::TypeMapByColumn.new([PG::TextDecoder::Integer.new, nil, PG::TextDecoder::Float.new])
52
+ @decoder = PG::TextDecoder::CopyRow.new(type_map: columns)
53
+ end
54
+
55
+ duel "copy: COPY 100 rows out with a decoder", setup: copy_out, teardown: -> { @conn.close } do
56
+ @conn.copy_data("COPY (SELECT g, 'user ' || g, g * 1.5 FROM generate_series(1, 100) g) TO STDOUT", @decoder) do
57
+ while @conn.get_copy_data; end
58
+ end
59
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # What several files of benchmarks share: a connection to the worker's
4
+ # own PostgreSQL server (see .duel.rb), and results and values fetched
5
+ # once, so that what's timed is the driver's work on them.
6
+
7
+ # A new connection to the worker's server. A benchmark keeps one for all
8
+ # its samples.
9
+ def pg_connection
10
+ PG.connect(Duel::PostgreSQL.url)
11
+ end
12
+
13
+ # A typical result's columns: an id, a name, a score, a flag, a
14
+ # timestamp, a date, and a small integer array, in 100 rows.
15
+ ROWS_SQL = <<~SQL
16
+ SELECT g AS id, 'user' || g AS name, g * 1.5::float8 AS score, g % 2 = 0 AS active,
17
+ timestamp '2026-01-01 12:00:00' + g * interval '1 minute 1.5 seconds' AS created_at,
18
+ date '2026-01-01' + g AS day, ARRAY[g, g + 1, g + 2] AS tags
19
+ FROM generate_series(1, 100) g
20
+ SQL
21
+
22
+ # ROWS_SQL's result, in text format (or with +format+ 1, binary), over
23
+ # +conn+. It stays in memory after +conn+ moves on, so reading it makes
24
+ # no round trip.
25
+ def rows_result(conn, format = 0)
26
+ conn.exec_params(ROWS_SQL, [], format)
27
+ end
28
+
29
+ # The +i+th of the timestamps below, as the server sends it, with
30
+ # +suffix+ (a zone, say).
31
+ def timestamp_text(i, suffix = "")
32
+ format("2026-%02d-%02d %02d:%02d:%02d.%06d%s",
33
+ (i % 12) + 1, (i % 28) + 1, i % 24, i % 60, (i * 7) % 60, i * 1234, suffix)
34
+ end
35
+
36
+ # 100 fixed values of each kind that a text decoder takes, as the server
37
+ # sends them.
38
+ TEXT_VALUES = {
39
+ integers: Array.new(100) { |i| (i * 7919).to_s },
40
+ floats: Array.new(100) { |i| (i * 3.14159).to_s },
41
+ timestamps: Array.new(100) { |i| timestamp_text(i) },
42
+ timestamptzs: Array.new(100) { |i| timestamp_text(i, "+02") },
43
+ dates: Array.new(100) { |i| format("2026-%02d-%02d", (i % 12) + 1, (i % 28) + 1) },
44
+ }.freeze
45
+
46
+ # Times to encode, fixed.
47
+ TIMES = Array.new(100) { |i| Time.utc(2026, (i % 12) + 1, (i % 28) + 1, i % 24, i % 60, (i * 7) % 60, i * 1234) }.freeze
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # Quoting and escaping for SQL, which libpq does by the connection's
6
+ # encoding, and pg wraps: no round trip. Each escapes 20 fixed strings,
7
+ # some with quotes and backslashes in them.
8
+
9
+ setup do
10
+ @conn = pg_connection
11
+ @strings = Array.new(20) { |i| i.even? ? "jane#{i}@example.com" : "O'Brien \\ \"#{i}\" it's" }
12
+ end
13
+ teardown { @conn.close }
14
+
15
+ duel "escape: escape_string" do
16
+ @strings.each { |string| @conn.escape_string(string) }
17
+ end
18
+
19
+ duel "escape: escape_literal" do
20
+ @strings.each { |string| @conn.escape_literal(string) }
21
+ end
22
+
23
+ duel "escape: quote_ident of a schema-qualified name" do
24
+ PG::Connection.quote_ident(%w[public users])
25
+ PG::Connection.quote_ident("Order Items")
26
+ end
27
+
28
+ duel "escape: escape_bytea and unescape_bytea of 4 KB" do
29
+ once { @bytes = (0...4096).map { |i| (i % 256).chr }.join.b }
30
+ PG::Connection.unescape_bytea(@conn.escape_bytea(@bytes))
31
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # Queries, over a Unix socket to the worker's own server: sending each
6
+ # one, waiting for its result and reading it. What the server does for
7
+ # them is in its own process, not this one's CPU time, so these are
8
+ # judged on what the driver does, and on the plugin's counts of the
9
+ # queries and rows the server ran.
10
+
11
+ setup { @conn = pg_connection }
12
+ teardown { @conn.close }
13
+
14
+ duel "query: exec a small SELECT" do
15
+ @conn.exec("SELECT 1")
16
+ end
17
+
18
+ duel "query: exec_params with three parameters" do
19
+ @conn.exec_params("SELECT $1::int, $2::text, $3::bool", [42, "jane@example.com", true])
20
+ end
21
+
22
+ duel "query: exec_prepared a statement" do
23
+ once { @conn.prepare("user_by_id", "SELECT $1::int AS id, 'user' || $1 AS name") }
24
+ @conn.exec_prepared("user_by_id", [42])
25
+ end
26
+
27
+ duel "query: exec 100 rows and read their values" do
28
+ @conn.exec(ROWS_SQL).values
29
+ end
30
+
31
+ duel "query: exec_params with a BasicTypeMapForQueries" do
32
+ once do
33
+ @conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(@conn)
34
+ @params = [42, "jane@example.com", 3.5, true, Time.utc(2026, 1, 2, 3, 4, 5), [1, 2, 3]]
35
+ end
36
+ @conn.exec_params("SELECT $1, $2, $3, $4, $5, $6", @params)
37
+ end
38
+
39
+ duel "query: 100 rows decoded by a BasicTypeMapForResults" do
40
+ once { @conn.type_map_for_results = PG::BasicTypeMapForResults.new(@conn) }
41
+ @conn.exec(ROWS_SQL).values
42
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # Reading a result that's in memory already, 100 rows of 7 columns (see
6
+ # ROWS_SQL): what an application does with every result, once its query
7
+ # has come back.
8
+
9
+ setup do
10
+ conn = pg_connection
11
+ @result = rows_result(conn)
12
+ @symbols = rows_result(conn).field_names_as(:symbol)
13
+ conn.close
14
+ end
15
+
16
+ duel "result: values" do
17
+ @result.values
18
+ end
19
+
20
+ duel "result: getvalue of every field" do
21
+ result = @result
22
+ 100.times do |row|
23
+ 7.times { |field| result.getvalue(row, field) }
24
+ end
25
+ end
26
+
27
+ duel "result: each, a Hash a row" do
28
+ @result.each { |_row| nil }
29
+ end
30
+
31
+ duel "result: each_row, an Array a row" do
32
+ @result.each_row { |_row| nil }
33
+ end
34
+
35
+ duel "result: column_values of two columns" do
36
+ @result.column_values(0)
37
+ @result.column_values(1)
38
+ end
39
+
40
+ duel "result: tuple, and fields by name" do
41
+ result = @result
42
+ 100.times do |row|
43
+ tuple = result.tuple(row)
44
+ tuple["id"]
45
+ tuple["name"]
46
+ tuple[6]
47
+ end
48
+ end
49
+
50
+ duel "result: each, a Hash a row with Symbol keys" do
51
+ @symbols.each { |_row| nil }
52
+ end
53
+
54
+ duel "result: field names, numbers and types" do
55
+ result = @result
56
+ result.fields
57
+ 7.times do |field|
58
+ result.fname(field)
59
+ result.ftype(field)
60
+ result.fmod(field)
61
+ end
62
+ result.fnumber("created_at")
63
+ result.fnumber("tags")
64
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "duel_helper"
4
+
5
+ # The type maps that decode a result's values into Ruby objects: the
6
+ # basic ones, which pick a decoder by the column's type OID, and one of
7
+ # explicit decoders by column. Each decodes a result that's in memory
8
+ # already (see ROWS_SQL), so no round trip is timed.
9
+
10
+ setup do
11
+ @conn = pg_connection
12
+ @text = rows_result(@conn)
13
+ @binary = rows_result(@conn, 1)
14
+ end
15
+ teardown { @conn.close }
16
+
17
+ duel "type map: BasicTypeMapForResults, text format" do
18
+ once { @map = PG::BasicTypeMapForResults.new(@conn) }
19
+ @text.map_types!(@map).values
20
+ end
21
+
22
+ duel "type map: BasicTypeMapForResults, binary format" do
23
+ once { @map = PG::BasicTypeMapForResults.new(@conn) }
24
+ @binary.map_types!(@map).values
25
+ end
26
+
27
+ duel "type map: TypeMapByColumn of text decoders" do
28
+ once do
29
+ @map = PG::TypeMapByColumn.new([
30
+ PG::TextDecoder::Integer.new, nil, PG::TextDecoder::Float.new, PG::TextDecoder::Boolean.new,
31
+ PG::TextDecoder::TimestampWithoutTimeZone.new, PG::TextDecoder::Date.new,
32
+ PG::TextDecoder::Array.new(elements_type: PG::TextDecoder::Integer.new),
33
+ ])
34
+ end
35
+ @text.map_types!(@map).values
36
+ end
37
+
38
+ duel "type map: BasicTypeMapForQueries picks encoders for parameters" do
39
+ once do
40
+ @map = PG::BasicTypeMapForQueries.new(@conn)
41
+ @params = [42, "jane@example.com", 3.5, true, nil, Time.utc(2026, 1, 2, 3, 4, 5), [1, 2, 3], %w[a b], 2**40]
42
+ end
43
+ @map.query_param_encoders(@params)
44
+ end
45
+
46
+ duel "type map: embed_params with a BasicTypeMapForQueries" do
47
+ once do
48
+ @map = PG::BasicTypeMapForQueries.new(@conn)
49
+ @params = [42, "O'Brien", 3.5, true, nil, Time.utc(2026, 1, 2, 3, 4, 5), [1, 2, 3]]
50
+ end
51
+ @conn.embed_params("SELECT * FROM users WHERE id = $1 AND name = $2 AND score > $3 AND active = $4 " \
52
+ "AND deleted_at IS $5 AND created_at < $6 AND group_id = ANY($7)", @params, type_map: @map)
53
+ end
data/ext/errorcodes.def CHANGED
@@ -287,6 +287,10 @@
287
287
  VALUE klass = define_error_class( "UntranslatableCharacter", "22" );
288
288
  register_error_class( "22P05", klass );
289
289
  }
290
+ {
291
+ VALUE klass = define_error_class( "DatumVersionMismatch", "22" );
292
+ register_error_class( "22P07", klass );
293
+ }
290
294
  {
291
295
  VALUE klass = define_error_class( "NotAnXmlDocument", "22" );
292
296
  register_error_class( "2200L", 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-2025, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2026, 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
@@ -207,6 +207,7 @@ Section: Class 22 - Data Exception
207
207
  22P03 E ERRCODE_INVALID_BINARY_REPRESENTATION invalid_binary_representation
208
208
  22P04 E ERRCODE_BAD_COPY_FILE_FORMAT bad_copy_file_format
209
209
  22P05 E ERRCODE_UNTRANSLATABLE_CHARACTER untranslatable_character
210
+ 22P07 E ERRCODE_DATUM_VERSION_MISMATCH datum_version_mismatch
210
211
  2200L E ERRCODE_NOT_AN_XML_DOCUMENT not_an_xml_document
211
212
  2200M E ERRCODE_INVALID_XML_DOCUMENT invalid_xml_document
212
213
  2200N E ERRCODE_INVALID_XML_CONTENT invalid_xml_content
data/ext/extconf.rb CHANGED
@@ -30,10 +30,10 @@ if gem_platform=with_config("cross-build")
30
30
  OPENSSL_VERSION = ENV['OPENSSL_VERSION'] || '3.6.5'
31
31
  OPENSSL_SOURCE_URI = "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"
32
32
 
33
- KRB5_VERSION = ENV['KRB5_VERSION'] || '1.22.2'
33
+ KRB5_VERSION = ENV['KRB5_VERSION'] || '1.22.3'
34
34
  KRB5_SOURCE_URI = "https://kerberos.org/dist/krb5/#{KRB5_VERSION[/^(\d+\.\d+)/]}/krb5-#{KRB5_VERSION}.tar.gz"
35
35
 
36
- POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '18.6'
36
+ POSTGRESQL_VERSION = ENV['POSTGRESQL_VERSION'] || '19.0'
37
37
  POSTGRESQL_SOURCE_URI = "https://ftp.postgresql.org/pub/source/v#{POSTGRESQL_VERSION}/postgresql-#{POSTGRESQL_VERSION}.tar.bz2"
38
38
 
39
39
  class BuildRecipe < MiniPortile
@@ -178,7 +178,7 @@ if gem_platform=with_config("cross-build")
178
178
  recipe.configure_options << "CFLAGS=#{" -fPIC" if RUBY_PLATFORM =~ /linux|darwin/}"
179
179
  recipe.configure_options << "LDFLAGS=-L#{openssl_recipe.path}/lib #{"-Wl,-soname,#{libpq_rubypg} -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support -ldl" if RUBY_PLATFORM =~ /linux/} #{"-Wl,-install_name,@loader_path/../../ports/#{gem_platform}/lib/#{libpq_rubypg} -lgssapi_krb5 -lkrb5 -lk5crypto -lkrb5support -lresolv -framework Kerberos" if RUBY_PLATFORM =~ /darwin/}"
180
180
  recipe.configure_options << "LIBS=-lkrb5 -lcom_err -lk5crypto -lkrb5support -lresolv" if RUBY_PLATFORM =~ /linux/
181
- recipe.configure_options << "LIBS=-lssl -lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/
181
+ recipe.configure_options << "LIBS=-lssl -lwsock32 -lgdi32 -lws2_32 -lcrypt32 -lbcrypt" if RUBY_PLATFORM =~ /mingw|mswin/
182
182
  recipe.configure_options << "CPPFLAGS=-I#{openssl_recipe.path}/include"
183
183
  recipe.cook_and_activate
184
184
  end
@@ -222,6 +222,13 @@ else
222
222
  dlldir = libdir
223
223
  end
224
224
 
225
+ # Try to use runtime path linker option, even if RbConfig doesn't know about it.
226
+ # The rpath option is usually set implicit by dir_config(), but so far not on MacOS-X.
227
+ # rpath is required on EDB darwin build since PostgreSQL-19.0.
228
+ if dlldir && RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && /darwin/ =~ RUBY_PLATFORM
229
+ append_ldflags "-Wl,-rpath,#{dlldir.quote}"
230
+ end
231
+
225
232
  if /mswin/ =~ RUBY_PLATFORM
226
233
  $libs = append_library($libs, 'ws2_32')
227
234
  end
@@ -309,7 +316,6 @@ have_func 'PQencryptPasswordConn', 'libpq-fe.h' or # since PostgreSQL-10
309
316
  "or upgrade your database to at least PostgreSQL-10."
310
317
  # optional headers/functions
311
318
  have_func 'PQresultMemorySize', 'libpq-fe.h' # since PostgreSQL-12
312
- have_func 'timegm'
313
319
  have_func 'rb_hash_new_capa' # since ruby-3.2
314
320
 
315
321
  have_header 'inttypes.h'