pg 0.18.2 → 1.5.3

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 (139) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.appveyor.yml +42 -0
  4. data/.gems +6 -0
  5. data/.github/workflows/binary-gems.yml +117 -0
  6. data/.github/workflows/source-gem.yml +137 -0
  7. data/.gitignore +22 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/BSDL +2 -2
  15. data/Gemfile +14 -0
  16. data/History.md +876 -0
  17. data/Manifest.txt +8 -21
  18. data/README-Windows.rdoc +17 -28
  19. data/README.ja.md +276 -0
  20. data/README.md +286 -0
  21. data/Rakefile +40 -131
  22. data/Rakefile.cross +88 -70
  23. data/certs/ged.pem +24 -0
  24. data/certs/larskanis-2022.pem +26 -0
  25. data/certs/larskanis-2023.pem +24 -0
  26. data/ext/errorcodes.def +113 -0
  27. data/ext/errorcodes.rb +1 -1
  28. data/ext/errorcodes.txt +36 -2
  29. data/ext/extconf.rb +120 -54
  30. data/ext/gvl_wrappers.c +8 -0
  31. data/ext/gvl_wrappers.h +44 -33
  32. data/ext/pg.c +226 -200
  33. data/ext/pg.h +99 -99
  34. data/ext/pg_binary_decoder.c +164 -16
  35. data/ext/pg_binary_encoder.c +249 -22
  36. data/ext/pg_coder.c +189 -44
  37. data/ext/pg_connection.c +1866 -1173
  38. data/ext/pg_copy_coder.c +398 -42
  39. data/ext/pg_errors.c +1 -1
  40. data/ext/pg_record_coder.c +522 -0
  41. data/ext/pg_result.c +727 -232
  42. data/ext/pg_text_decoder.c +629 -43
  43. data/ext/pg_text_encoder.c +269 -102
  44. data/ext/pg_tuple.c +572 -0
  45. data/ext/pg_type_map.c +64 -23
  46. data/ext/pg_type_map_all_strings.c +21 -7
  47. data/ext/pg_type_map_by_class.c +59 -27
  48. data/ext/pg_type_map_by_column.c +86 -43
  49. data/ext/pg_type_map_by_mri_type.c +49 -20
  50. data/ext/pg_type_map_by_oid.c +62 -29
  51. data/ext/pg_type_map_in_ruby.c +56 -22
  52. data/ext/{util.c → pg_util.c} +12 -12
  53. data/ext/{util.h → pg_util.h} +2 -2
  54. data/lib/pg/basic_type_map_based_on_result.rb +67 -0
  55. data/lib/pg/basic_type_map_for_queries.rb +198 -0
  56. data/lib/pg/basic_type_map_for_results.rb +104 -0
  57. data/lib/pg/basic_type_registry.rb +299 -0
  58. data/lib/pg/binary_decoder/date.rb +9 -0
  59. data/lib/pg/binary_decoder/timestamp.rb +26 -0
  60. data/lib/pg/binary_encoder/timestamp.rb +20 -0
  61. data/lib/pg/coder.rb +36 -13
  62. data/lib/pg/connection.rb +797 -77
  63. data/lib/pg/exceptions.rb +16 -2
  64. data/lib/pg/result.rb +24 -7
  65. data/lib/pg/text_decoder/date.rb +18 -0
  66. data/lib/pg/text_decoder/inet.rb +9 -0
  67. data/lib/pg/text_decoder/json.rb +14 -0
  68. data/lib/pg/text_decoder/numeric.rb +9 -0
  69. data/lib/pg/text_decoder/timestamp.rb +30 -0
  70. data/lib/pg/text_encoder/date.rb +12 -0
  71. data/lib/pg/text_encoder/inet.rb +28 -0
  72. data/lib/pg/text_encoder/json.rb +14 -0
  73. data/lib/pg/text_encoder/numeric.rb +9 -0
  74. data/lib/pg/text_encoder/timestamp.rb +24 -0
  75. data/lib/pg/tuple.rb +30 -0
  76. data/lib/pg/type_map_by_column.rb +3 -2
  77. data/lib/pg/version.rb +4 -0
  78. data/lib/pg.rb +106 -41
  79. data/misc/openssl-pg-segfault.rb +31 -0
  80. data/misc/postgres/History.txt +9 -0
  81. data/misc/postgres/Manifest.txt +5 -0
  82. data/misc/postgres/README.txt +21 -0
  83. data/misc/postgres/Rakefile +21 -0
  84. data/misc/postgres/lib/postgres.rb +16 -0
  85. data/misc/ruby-pg/History.txt +9 -0
  86. data/misc/ruby-pg/Manifest.txt +5 -0
  87. data/misc/ruby-pg/README.txt +21 -0
  88. data/misc/ruby-pg/Rakefile +21 -0
  89. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  90. data/pg.gemspec +34 -0
  91. data/rakelib/task_extension.rb +46 -0
  92. data/sample/array_insert.rb +1 -1
  93. data/sample/async_api.rb +4 -8
  94. data/sample/async_copyto.rb +1 -1
  95. data/sample/async_mixed.rb +1 -1
  96. data/sample/check_conn.rb +1 -1
  97. data/sample/copydata.rb +71 -0
  98. data/sample/copyfrom.rb +1 -1
  99. data/sample/copyto.rb +1 -1
  100. data/sample/cursor.rb +1 -1
  101. data/sample/disk_usage_report.rb +6 -15
  102. data/sample/issue-119.rb +2 -2
  103. data/sample/losample.rb +1 -1
  104. data/sample/minimal-testcase.rb +2 -2
  105. data/sample/notify_wait.rb +1 -1
  106. data/sample/pg_statistics.rb +6 -15
  107. data/sample/replication_monitor.rb +9 -18
  108. data/sample/test_binary_values.rb +1 -1
  109. data/sample/wal_shipper.rb +2 -2
  110. data/sample/warehouse_partitions.rb +8 -17
  111. data/translation/.po4a-version +7 -0
  112. data/translation/po/all.pot +910 -0
  113. data/translation/po/ja.po +1047 -0
  114. data/translation/po4a.cfg +12 -0
  115. data.tar.gz.sig +0 -0
  116. metadata +137 -204
  117. metadata.gz.sig +0 -0
  118. data/ChangeLog +0 -5545
  119. data/History.rdoc +0 -313
  120. data/README.ja.rdoc +0 -14
  121. data/README.rdoc +0 -161
  122. data/lib/pg/basic_type_mapping.rb +0 -399
  123. data/lib/pg/constants.rb +0 -11
  124. data/lib/pg/text_decoder.rb +0 -42
  125. data/lib/pg/text_encoder.rb +0 -27
  126. data/spec/data/expected_trace.out +0 -26
  127. data/spec/data/random_binary_data +0 -0
  128. data/spec/helpers.rb +0 -355
  129. data/spec/pg/basic_type_mapping_spec.rb +0 -251
  130. data/spec/pg/connection_spec.rb +0 -1535
  131. data/spec/pg/result_spec.rb +0 -449
  132. data/spec/pg/type_map_by_class_spec.rb +0 -138
  133. data/spec/pg/type_map_by_column_spec.rb +0 -222
  134. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  135. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  136. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  137. data/spec/pg/type_map_spec.rb +0 -22
  138. data/spec/pg/type_spec.rb +0 -688
  139. data/spec/pg_spec.rb +0 -50
data/Manifest.txt CHANGED
@@ -1,6 +1,5 @@
1
1
  .gemtest
2
2
  BSDL
3
- ChangeLog
4
3
  Contributors.rdoc
5
4
  History.rdoc
6
5
  LICENSE
@@ -26,9 +25,11 @@ ext/pg_coder.c
26
25
  ext/pg_connection.c
27
26
  ext/pg_copy_coder.c
28
27
  ext/pg_errors.c
28
+ ext/pg_record_coder.c
29
29
  ext/pg_result.c
30
30
  ext/pg_text_decoder.c
31
31
  ext/pg_text_encoder.c
32
+ ext/pg_tuple.c
32
33
  ext/pg_type_map.c
33
34
  ext/pg_type_map_all_strings.c
34
35
  ext/pg_type_map_by_class.c
@@ -36,13 +37,14 @@ ext/pg_type_map_by_column.c
36
37
  ext/pg_type_map_by_mri_type.c
37
38
  ext/pg_type_map_by_oid.c
38
39
  ext/pg_type_map_in_ruby.c
39
- ext/util.c
40
- ext/util.h
40
+ ext/pg_util.c
41
+ ext/pg_util.h
41
42
  ext/vc/pg.sln
42
43
  ext/vc/pg_18/pg.vcproj
43
44
  ext/vc/pg_19/pg_19.vcproj
44
45
  lib/pg.rb
45
46
  lib/pg/basic_type_mapping.rb
47
+ lib/pg/binary_decoder.rb
46
48
  lib/pg/coder.rb
47
49
  lib/pg/connection.rb
48
50
  lib/pg/constants.rb
@@ -50,31 +52,16 @@ lib/pg/exceptions.rb
50
52
  lib/pg/result.rb
51
53
  lib/pg/text_decoder.rb
52
54
  lib/pg/text_encoder.rb
55
+ lib/pg/tuple.rb
53
56
  lib/pg/type_map_by_column.rb
54
- sample/array_insert.rb
55
- sample/async_api.rb
56
- sample/async_copyto.rb
57
- sample/async_mixed.rb
58
- sample/check_conn.rb
59
- sample/copyfrom.rb
60
- sample/copyto.rb
61
- sample/cursor.rb
62
- sample/disk_usage_report.rb
63
- sample/issue-119.rb
64
- sample/losample.rb
65
- sample/minimal-testcase.rb
66
- sample/notify_wait.rb
67
- sample/pg_statistics.rb
68
- sample/replication_monitor.rb
69
- sample/test_binary_values.rb
70
- sample/wal_shipper.rb
71
- sample/warehouse_partitions.rb
72
57
  spec/data/expected_trace.out
73
58
  spec/data/random_binary_data
74
59
  spec/helpers.rb
75
60
  spec/pg/basic_type_mapping_spec.rb
76
61
  spec/pg/connection_spec.rb
62
+ spec/pg/connection_sync_spec.rb
77
63
  spec/pg/result_spec.rb
64
+ spec/pg/tuple_spec.rb
78
65
  spec/pg/type_map_by_class_spec.rb
79
66
  spec/pg/type_map_by_column_spec.rb
80
67
  spec/pg/type_map_by_mri_type_spec.rb
data/README-Windows.rdoc CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  In order to build this extension on MS Windows you will need a couple things.
4
4
 
5
- First, a compiler. For the one click installer this means you should either
6
- use VC++ 6.0 or the compiler that comes with cygwin or mingw if you're
7
- building on that platform.
5
+ First, a compiler. For the one click installer this means you should use
6
+ the DevKit or the compiler that comes with cygwin if you're building on that
7
+ platform.
8
8
 
9
9
  If you've built Ruby yourself, you should use the same compiler to build
10
10
  this library that you used to build Ruby.
@@ -29,39 +29,28 @@ Adjust your path accordingly. BE SURE TO USE THE SHORT PATH NAMES! If you
29
29
  try to use a path with spaces in it, the nmake.exe program will choke.
30
30
 
31
31
 
32
- == Cross compiling for mswin32
32
+ == Building binary 'pg' gems for MS Windows
33
33
 
34
- Using rake-compiler a cross compiled pg gem can be build on a Linux or MacOS X
35
- host for the win32 platform. The generated gem is statically linked against
36
- libpq and libssl. OpenSSL and PostgreSQL are downloaded and compiled from the
37
- sources. There are no runtime dependencies to any but the standard Windows
38
- DLLs.
34
+ Binary gems for windows can be built on Linux, OS-X and even on Windows
35
+ with the help of docker. This is how regular windows gems are built for
36
+ rubygems.org .
39
37
 
40
- Install mingw32 using the instructions in rake-compiler's README.
41
- For Debian/Ubuntu it is <tt>apt-get install gcc-mingw32</tt> .
42
- Use ruby-1.8.7 for the following commands.
38
+ To do this, install boot2docker {on Windows}[https://github.com/boot2docker/windows-installer/releases]
39
+ or {on OS X}[https://github.com/boot2docker/osx-installer/releases] and make
40
+ sure it is started. A native Docker installation is best on Linux.
43
41
 
44
- Download and cross compile ruby 1.8 and 1.9 for win32 with:
42
+ Then run:
45
43
 
46
- rake-compiler cross-ruby VERSION=1.8.7-p352
47
- rake-compiler cross-ruby VERSION=1.9.2-p290
44
+ rake gem:windows
48
45
 
49
- Download and cross compile pg for win32:
50
-
51
- rake cross native gem
52
-
53
- or with custom versions:
54
-
55
- rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.2 \
56
- OPENSSL_VERSION=1.0.0e POSTGRESQL_VERSION=9.1.1
57
-
58
- If everything works, there should be pg-VERSION-x86-mingw32.gem in the pkg
59
- directory.
46
+ This will download a docker image suited for building windows gems, and it
47
+ will download and build OpenSSL and PostgreSQL. Finally the gem is built
48
+ containing binaries for all supported ruby versions.
60
49
 
61
50
 
62
51
  == Reporting Problems
63
52
 
64
- If you have any problems you can submit them via
65
- [the project's issue-tracker][bitbucket]. And submit questions, problems, or
53
+ If you have any problems you can submit them via {the project's
54
+ issue-tracker}[https://github.com/ged/ruby-pg/issues]. And submit questions, problems, or
66
55
  solutions, so that it can be improved.
67
56
 
data/README.ja.md ADDED
@@ -0,0 +1,276 @@
1
+ # pg
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
7
+
8
+ [![https://gitter.im/ged/ruby-pg
9
+ でチャットに参加](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)
10
+
11
+
12
+ ## 説明
13
+
14
+ Pgは[PostgreSQL
15
+ RDBMS](http://www.postgresql.org/)へのRubyのインターフェースです。[PostgreSQL
16
+ 9.3以降](http://www.postgresql.org/support/versioning/)で動作します。
17
+
18
+ 簡単な使用例は次の通りです。
19
+ ```ruby
20
+ #!/usr/bin/env ruby
21
+
22
+ require 'pg'
23
+
24
+ # データベースへの現在の接続を表に出力します
25
+ conn = PG.connect( dbname: 'sales' )
26
+ conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
27
+ puts " PID | User | Query"
28
+ result.each do |row|
29
+ puts " %7d | %-16s | %s " %
30
+ row.values_at('pid', 'usename', 'query')
31
+ end
32
+ end
33
+ ```
34
+
35
+ ## ビルド状況
36
+
37
+ [![Github
38
+ 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
+ [![バイナリgem](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
+ [![Appveyorのビルド状況](https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true)](https://ci.appveyor.com/project/ged/ruby-pg-9j8l3)
41
+
42
+
43
+ ## 要件
44
+
45
+ * Ruby 2.5かそれより新しいバージョン
46
+ * PostgreSQL 9.3.xかそれ以降のバージョン(ヘッダー付属のもの、例えば-devの名前のパッケージ)。
47
+
48
+ それより前のバージョンのRubyやPostgreSQLでも通常は同様に動作しますが、定期的なテストはされていません。
49
+
50
+
51
+ ## バージョン管理
52
+
53
+ [セマンティックバージョニング](http://semver.org/)の原則にしたがってgemをタグ付けしてリリースしています。
54
+
55
+ この方針の結果として、2つの数字を指定する[悲観的バージョン制約](http://guides.rubygems.org/patterns/#pessimistic-version-constraint)を使ってこのgemへの依存関係を指定することができます(またそうすべきです)。
56
+
57
+ 例えば次の通りです。
58
+
59
+ ```ruby
60
+ spec.add_dependency 'pg', '~> 1.0'
61
+ ```
62
+
63
+ ## インストール方法
64
+
65
+ RubyGemsを経由してインストールするには以下とします。
66
+
67
+ gem install pg
68
+
69
+ Postgresと一緒にインストールされた'pg_config'プログラムへのパスを指定する必要があるかもしれません。
70
+
71
+ gem install pg -- --with-pg-config=<path to pg_config>
72
+
73
+ Bundlerを介してインストールした場合は次のようにコンパイルのためのヒントを与えられます。
74
+
75
+ bundle config build.pg --with-pg-config=<path to pg_config>
76
+
77
+ MacOS Xへインストールする詳しい情報については README-OS_X.rdoc を、Windows用のビルドやインストールの説明については
78
+ README-Windows.rdoc を参照してください。
79
+
80
+ 詰まったときやただ何か喋りたいときのために[Google+グループ](http://goo.gl/TFy1U)と[メーリングリスト](http://groups.google.com/group/ruby-pg)もあります。
81
+
82
+ 署名されたgemとしてインストールしたい場合は、リポジトリの[`certs`ディレクトリ](https://github.com/ged/ruby-pg/tree/master/certs)にgemの署名をする公開証明書があります。
83
+
84
+
85
+ ## 型変換
86
+
87
+ PgにはおまけとしてRubyとネイティブCコードにある結果の値やクエリ引数の型変換ができます。
88
+ こうすることでデータベースとのデータの往来を加速させられますが、それは文字列のアロケーションが減り、(より遅い)Rubyのコードでの変換部分が除かれるからです。
89
+
90
+ とても基本的な型変換は次のようにできます。
91
+ ```ruby
92
+ conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
93
+ # ……これは結果の値の対応付けに作用します。
94
+ conn.exec("select 1, now(), '{2,3}'::int[]").values
95
+ # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
96
+
97
+ conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
98
+ # ……そしてこれは引数値の対応付けのためのものです。
99
+ conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
100
+ # => [["1", "1.2300000000000000E+00", "{2,3}"]]
101
+ ```
102
+
103
+ しかしPgの型変換はかなり調整が効きます。2層に分かれているのがその理由です。
104
+
105
+ ### エンコーダーとデコーダー (ext/pg_*coder.c, lib/pg/*coder.rb)
106
+
107
+ こちらはより低層で、DBMSへ転送するためにRubyのオブジェクトを変換するエンコーディングクラスと取得してきたデータをRubyのオブジェクトに変換し戻すデコーディングクラスが含まれています。クラスはそれぞれの形式によって名前空間PG::TextEncoder、PG::TextDecoder、PG::BinaryEncoder、そしてPG::BinaryDecoderに分かれています。
108
+
109
+ エンコーダーないしデコーダーオブジェクトにOIDデータ型や形式コード(テキストないしバイナリ)や任意で名前を割り当てることができます。要素のエンコーダーないしデコーダーを割り当てることによって複合型を構築することもできます。PG::CoderオブジェクトはPG::TypeMapをセットアップしたりその代わりに単一の値と文字列表現とを相互に変換したりするのに使えます。
110
+
111
+ ruby-pgでは以下のPostgreSQLカラム型に対応しています(TE = Text Encoder、TD = Text Decoder、BE =
112
+ Binary Encoder、BD = Binary Decoder)。
113
+
114
+ * Integer:
115
+ [TE](rdoc-ref:PG::TextEncoder::Integer)、[TD](rdoc-ref:PG::TextDecoder::Integer)、[BD](rdoc-ref:PG::BinaryDecoder::Integer)
116
+ 💡
117
+ リンクがないでしょうか。[こちら](https://deveiate.org/code/pg/README_ja_md.html#label-E5-9E-8B-E5-A4-89-E6-8F-9B)を代わりに見てください
118
+ 💡
119
+ * BE:
120
+ [Int2](rdoc-ref:PG::BinaryEncoder::Int2)、[Int4](rdoc-ref:PG::BinaryEncoder::Int4)、[Int8](rdoc-ref:PG::BinaryEncoder::Int8)
121
+ * Float:
122
+ [TE](rdoc-ref:PG::TextEncoder::Float)、[TD](rdoc-ref:PG::TextDecoder::Float)、[BD](rdoc-ref:PG::BinaryDecoder::Float)
123
+ * BE: [Float4](rdoc-ref:PG::BinaryEncoder::Float4),
124
+ [Float8](rdoc-ref:PG::BinaryEncoder::Float8)
125
+ * Numeric:
126
+ [TE](rdoc-ref:PG::TextEncoder::Numeric)、[TD](rdoc-ref:PG::TextDecoder::Numeric)
127
+ * Boolean:
128
+ [TE](rdoc-ref:PG::TextEncoder::Boolean)、[TD](rdoc-ref:PG::TextDecoder::Boolean)、[BE](rdoc-ref:PG::BinaryEncoder::Boolean)、[BD](rdoc-ref:PG::BinaryDecoder::Boolean)
129
+ * String:
130
+ [TE](rdoc-ref:PG::TextEncoder::String)、[TD](rdoc-ref:PG::TextDecoder::String)、[BE](rdoc-ref:PG::BinaryEncoder::String)、[BD](rdoc-ref:PG::BinaryDecoder::String)
131
+ * Bytea:
132
+ [TE](rdoc-ref:PG::TextEncoder::Bytea)、[TD](rdoc-ref:PG::TextDecoder::Bytea)、[BE](rdoc-ref:PG::BinaryEncoder::Bytea)、[BD](rdoc-ref:PG::BinaryDecoder::Bytea)
133
+ * Base64:
134
+ [TE](rdoc-ref:PG::TextEncoder::ToBase64)、[TD](rdoc-ref:PG::TextDecoder::FromBase64)、[BE](rdoc-ref:PG::BinaryEncoder::FromBase64)、[BD](rdoc-ref:PG::BinaryDecoder::ToBase64)
135
+ * Timestamp:
136
+ * TE:
137
+ [現地時間](rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone)、[UTC](rdoc-ref:PG::TextEncoder::TimestampUtc)、[タイムゾーン付き](rdoc-ref:PG::TextEncoder::TimestampWithTimeZone)
138
+ * TD:
139
+ [現地時間](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)
142
+ * BD:
143
+ [現地時間](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
+ * JSONとJSONB:
149
+ [TE](rdoc-ref:PG::TextEncoder::JSON)、[TD](rdoc-ref:PG::TextDecoder::JSON)
150
+ * Inet:
151
+ [TE](rdoc-ref:PG::TextEncoder::Inet)、[TD](rdoc-ref:PG::TextDecoder::Inet)
152
+ * Array:
153
+ [TE](rdoc-ref:PG::TextEncoder::Array)、[TD](rdoc-ref:PG::TextDecoder::Array)
154
+ * 複合型(「行」や「レコード」などとも言います):[TE](rdoc-ref:PG::TextEncoder::Record)、[TD](rdoc-ref:PG::TextDecoder::Record)
155
+
156
+ The following text and binary formats can also be encoded although they are
157
+ not used as column type:
158
+
159
+ * COPYの入出力データ:[TE](rdoc-ref:PG::TextEncoder::CopyRow)、[TD](rdoc-ref:PG::TextDecoder::CopyRow),
160
+ [BE](rdoc-ref:PG::BinaryEncoder::CopyRow),
161
+ [BD](rdoc-ref:PG::BinaryDecoder::CopyRow)
162
+ * SQL文字列に挿入するリテラル:[TE](rdoc-ref:PG::TextEncoder::QuotedLiteral)
163
+ * SQLの識別子:
164
+ [TE](rdoc-ref:PG::TextEncoder::Identifier)、[TD](rdoc-ref:PG::TextDecoder::Identifier)
165
+
166
+ ### PG::TypeMapとその派生 (ext/pg_type_map*.c, lib/pg/type_map*.rb)
167
+
168
+ TypeMapはエンコーダーまたはデコーダーのどちらによってどの値を変換するかを定義します。様々な型の対応付け戦略があるので、このクラスにはいくつかの派生が実装されています。型変換の特有の需要に合わせてそれらの派生から選んで調整を加えることができます。既定の型の対応付けはPG::TypeMapAllStringsです。
169
+
170
+ 型の対応付けは、結果の集合それぞれに対し、接続毎ないしクエリ毎に割り当てることができます。型の対応付けはCOPYの入出力データストリーミングでも使うことができます。PG::Connection#copy_dataを参照してください。
171
+
172
+ 以下の基底となる型の対応付けが使えます。
173
+
174
+ * PG::TypeMapAllStrings - 全ての値と文字列について相互にエンコードとデコードを行います(既定)
175
+ * PG::TypeMapByClass - 送信する値のクラスに基づいてエンコーダーを選択します
176
+ * PG::TypeMapByColumn - カラムの順番によってエンコーダーとデコーダーを選択します
177
+ * PG::TypeMapByOid - PostgreSQLのOIDデータ型によってデコーダーを選択します
178
+ * PG::TypeMapInRuby - Rubyで独自の型の対応付けを定義します
179
+
180
+ 以下の型の対応付けはPG::BasicTypeRegistry由来の型の対応付けが入った状態になっています。
181
+
182
+ * PG::BasicTypeMapForResults -
183
+ PG::TypeMapByOidによくあるPostgreSQLカラム型用にデコーダーが入った状態になっています
184
+ * PG::BasicTypeMapBasedOnResult -
185
+ PG::TypeMapByOidによくあるPostgreSQLカラム型用のエンコーダーが入った状態になっています
186
+ * PG::BasicTypeMapForQueries -
187
+ PG::TypeMapByClassによくあるRubyの値クラス用にエンコーダーが入った状態になっています
188
+
189
+
190
+ ## スレッド対応
191
+
192
+ PGには個々のスレッドが別々のPG::Connectionオブジェクトを同時に使えるという点でスレッド安全性があります。しかし1つ以上のスレッドから同時にPgのオブジェクトにアクセスすると安全ではありません。そのため必ず、毎回新しいスレッドを作るときに新しいデータベースサーバー接続を開くか、スレッド安全性のある方法で接続を管理するActiveRecordのようなラッパーライブラリを使うようにしてください。
193
+
194
+ 以下のようなメッセージが標準エラー出力に表示された場合、恐らく複数のスレッドが1つの接続を使っています。
195
+
196
+ message type 0x31 arrived from server while idle
197
+ message type 0x32 arrived from server while idle
198
+ message type 0x54 arrived from server while idle
199
+ message type 0x43 arrived from server while idle
200
+ message type 0x5a arrived from server while idle
201
+
202
+
203
+ ## Fiber IOスケジューラー対応
204
+
205
+ PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応しています。`Fiber.scheduler`のWindows対応についてはRuby-3.1以降で使えます。`Fiber.scheduler`が走らせているスレッドに登録されている場合、起こりうる全てのブロッキングIO操作はそのスケジューラーを経由します。同期的であったりブロックしたりするメソッド呼び出しについてもpgが内部的に非同期のlibpqインターフェースを使っているのはそれが理由です。またlibpqの組み込み関数に代えてRubyのDNS解決を使っています。
206
+
207
+ 内部的にPgは常にlibpqのノンブロッキング接続モードを使います。それからブロッキングモードで走っているように振舞いますが、もし`Fiber.scheduler`が登録されていれば全てのブロッキングIOはそのスケジューラーを通じてRubyで制御されます。`PG::Connection.setnonblocking(true)`が呼ばれたらノンブロッキング状態が有効になったままになりますが、それ以降のブロッキング状態の制御が無効になるので、呼び出しているプログラムはブロッキング状態を自力で制御しなければなりません。
208
+
209
+ この規則の1つの例外には、`PG::Connection#lo_create`や外部ライブラリを使う認証メソッド(GSSAPI認証など)のような、大きめのオブジェクト用のメソッドがあります。これらは`Fiber.scheduler`と互換性がないため、ブロッキング状態は登録されたIOスケジューラに渡されません。つまり操作は適切に実行されますが、IO待ち状態に別のIOを扱うFiberから使用を切り替えてくることができなくなります。
210
+
211
+
212
+ ## 貢献
213
+
214
+ バグを報告したり機能を提案したりGitでソースをチェックアウトしたりするには[プロジェクトページをご確認ください](https://github.com/ged/ruby-pg)。
215
+
216
+ ソースをチェックアウトしたあとは全ての依存関係をインストールします。
217
+
218
+ $ bundle install
219
+
220
+ 拡張ファイル、パッケージファイル、テストデータベースを一掃するには、このコマンドを走らせてください。PostgreSQLのバージョンも切り替わります。
221
+
222
+ $ rake clean
223
+
224
+ 拡張をコンパイルするには次のようにします。
225
+
226
+ $ rake compile
227
+
228
+ `pg_config --bindir`が指すPostgreSQLのバージョンでテストやスペックを走らせるには次のようにします。
229
+
230
+ $ rake test
231
+
232
+ あるいは特定のPostgreSQLのバージョンで、ファイル中の行番号を使って特定のテストを走らせるには次のようにします。
233
+
234
+ $ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455
235
+
236
+ APIドキュメントを生成するには次のようにします。
237
+
238
+ $ rake docs
239
+
240
+ 必ず全てのバグと新機能についてテストを使って検証してください。
241
+
242
+ 現在のメンテナはMichael Granger <ged@FaerieMUD.org>とLars Kanis
243
+ <lars@greiz-reinsdorf.de>です。
244
+
245
+
246
+ ## 著作権
247
+
248
+ Copyright (c) 1997-2022 by the authors.
249
+
250
+ * Jeff Davis <ruby-pg@j-davis.com>
251
+ * Guy Decoux (ts) <decoux@moulon.inra.fr>
252
+ * Michael Granger <ged@FaerieMUD.org>
253
+ * Lars Kanis <lars@greiz-reinsdorf.de>
254
+ * Dave Lee
255
+ * Eiji Matsumoto <usagi@ruby.club.or.jp>
256
+ * Yukihiro Matsumoto <matz@ruby-lang.org>
257
+ * Noboru Saitou <noborus@netlab.jp>
258
+
259
+ You may redistribute this software under the same terms as Ruby itself; see
260
+ https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the
261
+ source for details.
262
+ (参考訳:このソフトウェアはRuby自体と同じ条件の元で再配布することができます。詳細については
263
+ https://www.ruby-lang.org/en/about/license.txt やソース中のBSDLファイルを参照してください)
264
+
265
+ Portions of the code are from the PostgreSQL project, and are distributed "
266
+ "under the terms of the PostgreSQL license, included in the file POSTGRES.
267
+ (参考訳:コードの一部はPostgreSQLプロジェクトから来ており、PostgreSQLの使用許諾の条件の元で配布されます。ファイルPOSTGRESに含まれています)
268
+
269
+ Portions copyright LAIKA, Inc.
270
+
271
+
272
+ ## 謝辞
273
+
274
+ 長年にわたって貢献してくださった方々についてはContributors.rdocを参照してください。
275
+
276
+ ruby-listとruby-devメーリングリストの方々に感謝します。またPostgreSQLを開発された方々へも謝意を表します。