pg 1.5.3 → 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 (53) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Gemfile +6 -0
  4. data/History.md +60 -4
  5. data/README.ja.md +54 -30
  6. data/Rakefile +4 -1
  7. data/Rakefile.cross +13 -8
  8. data/certs/kanis@comcard.de.pem +20 -0
  9. data/certs/larskanis-2024.pem +24 -0
  10. data/ext/errorcodes.def +4 -5
  11. data/ext/errorcodes.txt +2 -5
  12. data/ext/extconf.rb +7 -0
  13. data/ext/pg.c +2 -2
  14. data/ext/pg.h +0 -1
  15. data/ext/pg_binary_decoder.c +2 -0
  16. data/ext/pg_binary_encoder.c +1 -1
  17. data/ext/pg_connection.c +60 -21
  18. data/ext/pg_copy_coder.c +17 -13
  19. data/ext/pg_record_coder.c +6 -6
  20. data/ext/pg_result.c +4 -4
  21. data/ext/pg_text_decoder.c +4 -1
  22. data/ext/pg_text_encoder.c +17 -11
  23. data/lib/pg/basic_type_map_for_queries.rb +8 -4
  24. data/lib/pg/basic_type_registry.rb +14 -2
  25. data/lib/pg/connection.rb +58 -38
  26. data/lib/pg/exceptions.rb +6 -0
  27. data/lib/pg/text_decoder/date.rb +3 -0
  28. data/lib/pg/text_decoder/json.rb +3 -0
  29. data/lib/pg/text_encoder/date.rb +1 -0
  30. data/lib/pg/text_encoder/inet.rb +3 -0
  31. data/lib/pg/text_encoder/json.rb +3 -0
  32. data/lib/pg/version.rb +1 -1
  33. data/lib/pg.rb +10 -0
  34. data/pg.gemspec +3 -1
  35. data.tar.gz.sig +0 -0
  36. metadata +17 -34
  37. metadata.gz.sig +0 -0
  38. data/.appveyor.yml +0 -42
  39. data/.gems +0 -6
  40. data/.gemtest +0 -0
  41. data/.github/workflows/binary-gems.yml +0 -117
  42. data/.github/workflows/source-gem.yml +0 -137
  43. data/.gitignore +0 -22
  44. data/.hgsigs +0 -34
  45. data/.hgtags +0 -41
  46. data/.irbrc +0 -23
  47. data/.pryrc +0 -23
  48. data/.tm_properties +0 -21
  49. data/.travis.yml +0 -49
  50. data/translation/.po4a-version +0 -7
  51. data/translation/po/all.pot +0 -910
  52. data/translation/po/ja.po +0 -1047
  53. data/translation/po4a.cfg +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cbac60d76e50f034bb84d601d55d816cd3d3b8c05a3067b9ccd3103fc293699
4
- data.tar.gz: e9e5d36b50bd17e8cfd3d2191a0bbc499ca09a466f9c73dc81c2799be82a3346
3
+ metadata.gz: c0abb6cbfa5134825baaaa3cab5bbb2d88a5092559331239ccb977c24579d27d
4
+ data.tar.gz: 53d6fd115d923b9654b2928791309d290a87f01275a13f3489025d673ba967ab
5
5
  SHA512:
6
- metadata.gz: b9bc096fb5410cc044f0f5fb7f688d8047fcc5c7ea8ff025bb6ada32f92288f1f6c076da157e8812aa01a47fe2b025798bafa92aab7fd1294bfcc60f03e53f09
7
- data.tar.gz: 120f870057de3c7552e4beef0c81dd90e5ce03a4557bf3b01d518197596dfa149c7612375028451c0b07f6714567ee5e2c80040ec9470226d045e6b9fc3153eb
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,3 +1,59 @@
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
+
48
+ ## v1.5.4 [2023-09-01] Lars Kanis <lars@greiz-reinsdorf.de>
49
+
50
+ - Fix compiling the pg extension with MSVC 2022. [#535](https://github.com/ged/ruby-pg/pull/535)
51
+ - Set PG::Connection's encoding even if setting client_encoding on connection startup fails. [#541](https://github.com/ged/ruby-pg/pull/541)
52
+ - Don't set the server's client_encoding if it's unnecessary. [#542](https://github.com/ged/ruby-pg/pull/542)
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.
55
+
56
+
1
57
  ## v1.5.3 [2023-04-28] Lars Kanis <lars@greiz-reinsdorf.de>
2
58
 
3
59
  - Fix possible segfault when creating a new PG::Result with type map. [#530](https://github.com/ged/ruby-pg/pull/530)
@@ -67,7 +123,7 @@ Removed:
67
123
  Repository:
68
124
 
69
125
  - `rake test` tries to find PostgreSQL server commands by pg_config [#503](https://github.com/ged/ruby-pg/pull/503)
70
- 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.
71
127
 
72
128
 
73
129
  ## v1.4.6 [2023-02-26] Lars Kanis <lars@greiz-reinsdorf.de>
@@ -136,7 +192,7 @@ Added:
136
192
  Bugfixes:
137
193
 
138
194
  - Try IPv6 and IPv4 addresses, if DNS resolves to both. [#452](https://github.com/ged/ruby-pg/pull/452)
139
- - 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)
140
196
  - Handle client error after all data consumed in #copy_data for output. [#455](https://github.com/ged/ruby-pg/pull/455)
141
197
  - Avoid spurious keyword argument warning on Ruby 2.7. [#456](https://github.com/ged/ruby-pg/pull/456)
142
198
  - Change connection setup to respect connect_timeout parameter. [#459](https://github.com/ged/ruby-pg/pull/459)
@@ -175,7 +231,7 @@ Bugfixes:
175
231
 
176
232
  - Don't leak IO in case of connection errors. [#439](https://github.com/ged/ruby-pg/pull/439)
177
233
  Previously it was kept open until the PG::Connection was garbage collected.
178
- - 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)
179
235
  - Fix occasional error Errno::EBADF (Bad file descriptor) while connecting. [#444](https://github.com/ged/ruby-pg/pull/444)
180
236
  - Fix compatibility of res.stream_each* methods with Fiber.scheduler. [#446](https://github.com/ged/ruby-pg/pull/446)
181
237
  - Remove FL_TEST and FL_SET, which are MRI-internal. [#437](https://github.com/ged/ruby-pg/pull/437)
@@ -261,7 +317,7 @@ Type cast enhancements:
261
317
  - Add PG::BasicTypeMapForQueries::BinaryData for encoding of bytea columns. [#348](https://github.com/ged/ruby-pg/pull/348)
262
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)
263
319
  - Make BasicTypeRegistry a class and use a global default instance of it.
264
- 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.
265
321
  - Allow PG::BasicTypeMapForQueries to take a Proc as callback for undefined types.
266
322
 
267
323
  Other Enhancements:
data/README.ja.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # pg
2
2
 
3
- * home :: https://github.com/ged/ruby-pg
4
- * docs :: http://deveiate.org/code/pg (English) ,
5
- https://deveiate.org/code/pg/README_ja_md.html (Japanese)
6
- * clog :: link:/History.md
3
+ * ホーム :: https://github.com/ged/ruby-pg
4
+ * ドキュメント :: http://deveiate.org/code/pg (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
5
+ * 変更履歴 :: link:/History.md
7
6
 
8
7
  [![https://gitter.im/ged/ruby-pg
9
8
  でチャットに参加](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -84,8 +83,9 @@ README-Windows.rdoc を参照してください。
84
83
 
85
84
  ## 型変換
86
85
 
87
- PgにはおまけとしてRubyとネイティブCコードにある結果の値やクエリ引数の型変換ができます。
88
- こうすることでデータベースとのデータの往来を加速させられますが、それは文字列のアロケーションが減り、(より遅い)Rubyのコードでの変換部分が除かれるからです。
86
+ Pgでは任意でRubyと素のCコードにある結果の値やクエリ引数の型変換ができます。
87
+ こうすることでデータベースとのデータの往来を加速させられます。
88
+ なぜなら文字列のアロケーションが減り、(比較的遅い)Rubyのコードでの変換部分が省かれるからです。
89
89
 
90
90
  とても基本的な型変換は次のようにできます。
91
91
  ```ruby
@@ -104,9 +104,13 @@ PgにはおまけとしてRubyとネイティブCコードにある結果の値
104
104
 
105
105
  ### エンコーダーとデコーダー (ext/pg_*coder.c, lib/pg/*coder.rb)
106
106
 
107
- こちらはより低層で、DBMSへ転送するためにRubyのオブジェクトを変換するエンコーディングクラスと取得してきたデータをRubyのオブジェクトに変換し戻すデコーディングクラスが含まれています。クラスはそれぞれの形式によって名前空間PG::TextEncoder、PG::TextDecoder、PG::BinaryEncoder、そしてPG::BinaryDecoderに分かれています。
107
+ こちらはより低層で、DBMSへ転送するためにRubyのオブジェクトを変換するエンコーディングクラスと、取得してきたデータをRubyのオブジェクトに変換し戻すデコーディングクラスが含まれています。
108
+ クラスはそれぞれの形式によって名前空間 PG::TextEncoder, PG::TextDecoder, PG::BinaryEncoder, そして
109
+ PG::BinaryDecoder に分かれています。
108
110
 
109
- エンコーダーないしデコーダーオブジェクトにOIDデータ型や形式コード(テキストないしバイナリ)や任意で名前を割り当てることができます。要素のエンコーダーないしデコーダーを割り当てることによって複合型を構築することもできます。PG::CoderオブジェクトはPG::TypeMapをセットアップしたりその代わりに単一の値と文字列表現とを相互に変換したりするのに使えます。
111
+ エンコーダーないしデコーダーオブジェクトにOIDデータ型や形式コード(テキストないしバイナリ)や任意で名前を割り当てることができます。
112
+ 要素のエンコーダーないしデコーダーを割り当てることによって複合型を構築することもできます。
113
+ PG::Coder オブジェクトは PG::TypeMap をセットアップしたり、その代わりに単一の値と文字列表現とを相互に変換したりするのに使えます。
110
114
 
111
115
  ruby-pgでは以下のPostgreSQLカラム型に対応しています(TE = Text Encoder、TD = Text Decoder、BE =
112
116
  Binary Encoder、BD = Binary Decoder)。
@@ -137,14 +141,11 @@ Binary Encoder、BD = Binary Decoder)。
137
141
  [現地時間](rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone)、[UTC](rdoc-ref:PG::TextEncoder::TimestampUtc)、[タイムゾーン付き](rdoc-ref:PG::TextEncoder::TimestampWithTimeZone)
138
142
  * TD:
139
143
  [現地時間](rdoc-ref:PG::TextDecoder::TimestampLocal)、[UTC](rdoc-ref:PG::TextDecoder::TimestampUtc)、[UTCから現地時間へ](rdoc-ref:PG::TextDecoder::TimestampUtcToLocal)
140
- * BE: [local](rdoc-ref:PG::BinaryEncoder::TimestampLocal),
141
- [UTC](rdoc-ref:PG::BinaryEncoder::TimestampUtc)
144
+ * BE:
145
+ [現地時間](rdoc-ref:PG::BinaryEncoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryEncoder::TimestampUtc)
142
146
  * BD:
143
147
  [現地時間](rdoc-ref:PG::BinaryDecoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryDecoder::TimestampUtc)、[UTCから現地時間へ](rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal)
144
- * Date: [TE](rdoc-ref:PG::TextEncoder::Date),
145
- [TD](rdoc-ref:PG::TextDecoder::Date),
146
- [BE](rdoc-ref:PG::BinaryEncoder::Date),
147
- [BD](rdoc-ref:PG::BinaryDecoder::Date)
148
+ * 日付:[TE](rdoc-ref:PG::TextEncoder::Date)、[TD](rdoc-ref:PG::TextDecoder::Date)、[BE](rdoc-ref:PG::BinaryEncoder::Date)、[BD](rdoc-ref:PG::BinaryDecoder::Date)
148
149
  * JSONとJSONB:
149
150
  [TE](rdoc-ref:PG::TextEncoder::JSON)、[TD](rdoc-ref:PG::TextDecoder::JSON)
150
151
  * Inet:
@@ -153,8 +154,7 @@ Binary Encoder、BD = Binary Decoder)。
153
154
  [TE](rdoc-ref:PG::TextEncoder::Array)、[TD](rdoc-ref:PG::TextDecoder::Array)
154
155
  * 複合型(「行」や「レコード」などとも言います):[TE](rdoc-ref:PG::TextEncoder::Record)、[TD](rdoc-ref:PG::TextDecoder::Record)
155
156
 
156
- The following text and binary formats can also be encoded although they are
157
- not used as column type:
157
+ カラム型として使われていませんが、以下のテキスト形式とバイナリ形式もエンコードできます。
158
158
 
159
159
  * COPYの入出力データ:[TE](rdoc-ref:PG::TextEncoder::CopyRow)、[TD](rdoc-ref:PG::TextDecoder::CopyRow),
160
160
  [BE](rdoc-ref:PG::BinaryEncoder::CopyRow),
@@ -163,11 +163,16 @@ not used as column type:
163
163
  * SQLの識別子:
164
164
  [TE](rdoc-ref:PG::TextEncoder::Identifier)、[TD](rdoc-ref:PG::TextDecoder::Identifier)
165
165
 
166
- ### PG::TypeMapとその派生 (ext/pg_type_map*.c, lib/pg/type_map*.rb)
166
+ ### PG::TypeMap とその派生 (ext/pg_type_map*.c, lib/pg/type_map*.rb)
167
167
 
168
- TypeMapはエンコーダーまたはデコーダーのどちらによってどの値を変換するかを定義します。様々な型の対応付け戦略があるので、このクラスにはいくつかの派生が実装されています。型変換の特有の需要に合わせてそれらの派生から選んで調整を加えることができます。既定の型の対応付けはPG::TypeMapAllStringsです。
168
+ TypeMapはエンコーダーまたはデコーダーのどちらによってどの値を変換するかを定義します。
169
+ 様々な型の対応付け戦略があるので、このクラスにはいくつかの派生が実装されています。
170
+ 型変換の特有の需要に合わせてそれらの派生から選んで調整を加えることができます。
171
+ 既定の型の対応付けは PG::TypeMapAllStrings です。
169
172
 
170
- 型の対応付けは、結果の集合それぞれに対し、接続毎ないしクエリ毎に割り当てることができます。型の対応付けはCOPYの入出力データストリーミングでも使うことができます。PG::Connection#copy_dataを参照してください。
173
+ 型の対応付けは、結果の集合それぞれに対し、接続毎ないしクエリ毎に割り当てることができます。
174
+ 型の対応付けはCOPYの入出力データストリーミングでも使うことができます。
175
+ PG::Connection#copy_data を参照してください。
171
176
 
172
177
  以下の基底となる型の対応付けが使えます。
173
178
 
@@ -177,19 +182,21 @@ TypeMapはエンコーダーまたはデコーダーのどちらによってど
177
182
  * PG::TypeMapByOid - PostgreSQLのOIDデータ型によってデコーダーを選択します
178
183
  * PG::TypeMapInRuby - Rubyで独自の型の対応付けを定義します
179
184
 
180
- 以下の型の対応付けはPG::BasicTypeRegistry由来の型の対応付けが入った状態になっています。
185
+ 以下の型の対応付けは PG::BasicTypeRegistry 由来の型の対応付けが入った状態になっています。
181
186
 
182
- * PG::BasicTypeMapForResults -
183
- PG::TypeMapByOidによくあるPostgreSQLカラム型用にデコーダーが入った状態になっています
184
- * PG::BasicTypeMapBasedOnResult -
185
- PG::TypeMapByOidによくあるPostgreSQLカラム型用のエンコーダーが入った状態になっています
186
- * PG::BasicTypeMapForQueries -
187
- PG::TypeMapByClassによくあるRubyの値クラス用にエンコーダーが入った状態になっています
187
+ * PG::BasicTypeMapForResults - PG::TypeMapByOid
188
+ によくあるPostgreSQLカラム型用にデコーダーが入った状態になっています
189
+ * PG::BasicTypeMapBasedOnResult - PG::TypeMapByOid
190
+ によくあるPostgreSQLカラム型用のエンコーダーが入った状態になっています
191
+ * PG::BasicTypeMapForQueries - PG::TypeMapByClass
192
+ によくあるRubyの値クラス用にエンコーダーが入った状態になっています
188
193
 
189
194
 
190
195
  ## スレッド対応
191
196
 
192
- PGには個々のスレッドが別々のPG::Connectionオブジェクトを同時に使えるという点でスレッド安全性があります。しかし1つ以上のスレッドから同時にPgのオブジェクトにアクセスすると安全ではありません。そのため必ず、毎回新しいスレッドを作るときに新しいデータベースサーバー接続を開くか、スレッド安全性のある方法で接続を管理するActiveRecordのようなラッパーライブラリを使うようにしてください。
197
+ PGには個々のスレッドが別々の PG::Connection オブジェクトを同時に使えるという点でスレッド安全性があります。
198
+ しかし1つ以上のスレッドから同時にPgのオブジェクトにアクセスすると安全ではありません。
199
+ そのため必ず、毎回新しいスレッドを作るときに新しいデータベースサーバー接続を開くか、スレッド安全性のある方法で接続を管理するActiveRecordのようなラッパーライブラリを使うようにしてください。
193
200
 
194
201
  以下のようなメッセージが標準エラー出力に表示された場合、恐らく複数のスレッドが1つの接続を使っています。
195
202
 
@@ -202,13 +209,30 @@ PGには個々のスレッドが別々のPG::Connectionオブジェクトを同
202
209
 
203
210
  ## Fiber IOスケジューラー対応
204
211
 
205
- PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応しています。`Fiber.scheduler`のWindows対応についてはRuby-3.1以降で使えます。`Fiber.scheduler`が走らせているスレッドに登録されている場合、起こりうる全てのブロッキングIO操作はそのスケジューラーを経由します。同期的であったりブロックしたりするメソッド呼び出しについてもpgが内部的に非同期のlibpqインターフェースを使っているのはそれが理由です。またlibpqの組み込み関数に代えてRubyのDNS解決を使っています。
212
+ pg-1.3.0以降で、PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応しています。
213
+ Windowsでは、`Fiber.scheduler`対応はRuby-3.1以降で使えます。
214
+ `Fiber.scheduler`が走らせているスレッドに登録されている場合、起こりうる全てのブロッキングIO操作はそのスケジューラーを経由します。
215
+ 同期的であったりブロックしたりするメソッド呼び出しについてもpgが内部的に非同期のlibpqインターフェースを使っているのはそれが理由です。
216
+ またlibpqの組み込み関数に代えてRubyのDNS解決を使っています。
206
217
 
207
- 内部的にPgは常にlibpqのノンブロッキング接続モードを使います。それからブロッキングモードで走っているように振舞いますが、もし`Fiber.scheduler`が登録されていれば全てのブロッキングIOはそのスケジューラーを通じてRubyで制御されます。`PG::Connection.setnonblocking(true)`が呼ばれたらノンブロッキング状態が有効になったままになりますが、それ以降のブロッキング状態の制御が無効になるので、呼び出しているプログラムはブロッキング状態を自力で制御しなければなりません。
218
+ 内部的にPgは常にlibpqのノンブロッキング接続モードを使います。
219
+ それからブロッキングモードで走っているように振舞いますが、もし`Fiber.scheduler`が登録されていれば全てのブロッキングIOはそのスケジューラーを通じてRubyで制御されます。
220
+ `PG::Connection.setnonblocking(true)`が呼ばれたらノンブロッキング状態が有効になったままになりますが、それ以降のブロッキング状態の制御が無効になるので、呼び出しているプログラムはブロッキング状態を自力で制御しなければなりません。
208
221
 
209
222
  この規則の1つの例外には、`PG::Connection#lo_create`や外部ライブラリを使う認証メソッド(GSSAPI認証など)のような、大きめのオブジェクト用のメソッドがあります。これらは`Fiber.scheduler`と互換性がないため、ブロッキング状態は登録されたIOスケジューラに渡されません。つまり操作は適切に実行されますが、IO待ち状態に別のIOを扱うFiberから使用を切り替えてくることができなくなります。
210
223
 
211
224
 
225
+ ## Ractor対応
226
+
227
+ pg-1.5.0以降で、PgはRuby-3.0で導入されたRactorと完全な互換性があります。
228
+ 型エンコーダーないしデコーダー、及び型の対応付けが`Ractor.make_shareable`により凍結されている場合、これらをractor間で共有できます。
229
+ また凍結された PG::Result と PG::Tuple オブジェクトも共有できます。
230
+ 少なくとも全ての凍結されたオブジェクト(ただし PG::Connection
231
+ を除く)はPostgreSQLサーバーとのやり取りをしたり取得されたデータを読むのに使えます。
232
+
233
+ PG::Connection は共有できません。個々の接続を確立するために、それぞれのRactor内で作られなければなりません。
234
+
235
+
212
236
  ## 貢献
213
237
 
214
238
  バグを報告したり機能を提案したりGitでソースをチェックアウトしたりするには[プロジェクトページをご確認ください](https://github.com/ged/ruby-pg)。
@@ -271,6 +295,6 @@ Portions copyright LAIKA, Inc.
271
295
 
272
296
  ## 謝辞
273
297
 
274
- 長年にわたって貢献してくださった方々についてはContributors.rdocを参照してください。
298
+ 長年にわたって貢献してくださった方々については Contributors.rdoc を参照してください。
275
299
 
276
300
  ruby-listとruby-devメーリングリストの方々に感謝します。またPostgreSQLを開発された方々へも謝意を表します。
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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kBaxWOMtWlqIprq8JZXM9AgMBAAGjOTA3MAkG
14
+ A1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQ4h1tIyvdUWtMI739xMzTR
15
+ 7EfMFzANBgkqhkiG9w0BAQsFAAOCAYEArBmHSfnUyNWf3R1Fx0mMHloWGdcKn2D2
16
+ BsqTApXU2nADiyppIqRq4b9e7hw342uzadSLkoQcEFOxThLRhAcijoWfQVBcsbV/
17
+ ZsCY1qlUTIJuSWxaSyS4efUX+N4eMNyPM9oW/sphlWFo0DgI34Y9WB6HDzH+O71y
18
+ R7PARke3f4kYnRJf5yRQLPDrH9UYt9KlBQm6l7XMtr5EMnQt0EfcmZEi9H4t/vS2
19
+ haxvpFMdAKo4H46GBYNO96r6b74t++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' )
@@ -60,6 +62,10 @@ else
60
62
  if dlldir && RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
61
63
  append_ldflags "-Wl,-rpath,#{dlldir.quote}"
62
64
  end
65
+
66
+ if /mswin/ =~ RUBY_PLATFORM
67
+ $libs = append_library($libs, 'ws2_32')
68
+ end
63
69
  end
64
70
 
65
71
  $stderr.puts "Using libpq from #{dlldir}"
@@ -154,6 +160,7 @@ have_func 'timegm'
154
160
  have_func 'rb_gc_adjust_memory_usage' # since ruby-2.4
155
161
  have_func 'rb_gc_mark_movable' # since ruby-2.7
156
162
  have_func 'rb_io_wait' # since ruby-3.0
163
+ have_func 'rb_io_descriptor' # since ruby-3.1
157
164
 
158
165
  # unistd.h confilicts with ruby/win32.h when cross compiling for win32 and ruby 1.9.1
159
166
  have_header 'unistd.h'
data/ext/pg.c CHANGED
@@ -125,7 +125,7 @@ const char * const (pg_enc_pg2ruby_mapping[][2]) = {
125
125
  * - returns NULL if the client encoding is 'SQL_ASCII'.
126
126
  * - returns ASCII-8BIT if the client encoding is unknown.
127
127
  */
128
- rb_encoding *
128
+ static rb_encoding *
129
129
  pg_get_pg_encoding_as_rb_encoding( int enc_id )
130
130
  {
131
131
  const char *name = pg_encoding_to_char( enc_id );
@@ -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
  */
data/ext/pg.h CHANGED
@@ -369,7 +369,6 @@ pgresult_get_this( VALUE self )
369
369
  }
370
370
 
371
371
 
372
- rb_encoding * pg_get_pg_encoding_as_rb_encoding _(( int ));
373
372
  rb_encoding * pg_get_pg_encname_as_rb_encoding _(( const char * ));
374
373
  const char * pg_get_rb_encoding_as_pg_encoding _(( rb_encoding * ));
375
374
  rb_encoding *pg_conn_enc_get _(( PGconn * ));
@@ -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 */