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/README.md ADDED
@@ -0,0 +1,286 @@
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
+ [![Join the chat at https://gitter.im/ged/ruby-pg](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)
9
+
10
+
11
+ ## Description
12
+
13
+ Pg is the Ruby interface to the [PostgreSQL RDBMS](http://www.postgresql.org/).
14
+ It works with [PostgreSQL 9.3 and later](http://www.postgresql.org/support/versioning/).
15
+
16
+ A small example usage:
17
+ ```ruby
18
+ #!/usr/bin/env ruby
19
+
20
+ require 'pg'
21
+
22
+ # Output a table of current connections to the DB
23
+ conn = PG.connect( dbname: 'sales' )
24
+ conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
25
+ puts " PID | User | Query"
26
+ result.each do |row|
27
+ puts " %7d | %-16s | %s " %
28
+ row.values_at('pid', 'usename', 'query')
29
+ end
30
+ end
31
+ ```
32
+
33
+ ## Build Status
34
+
35
+ [![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)
36
+ [![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)
37
+ [![Build Status Appveyor](https://ci.appveyor.com/api/projects/status/gjx5axouf3b1wicp?svg=true)](https://ci.appveyor.com/project/ged/ruby-pg-9j8l3)
38
+
39
+
40
+ ## Requirements
41
+
42
+ * Ruby 2.5 or newer
43
+ * PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
44
+
45
+ It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
46
+ not regularly tested.
47
+
48
+
49
+ ## Versioning
50
+
51
+ We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
52
+
53
+ As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint](http://guides.rubygems.org/patterns/#pessimistic-version-constraint) with two digits of precision.
54
+
55
+ For example:
56
+
57
+ ```ruby
58
+ spec.add_dependency 'pg', '~> 1.0'
59
+ ```
60
+
61
+ ## How To Install
62
+
63
+ Install via RubyGems:
64
+
65
+ gem install pg
66
+
67
+ You may need to specify the path to the 'pg_config' program installed with
68
+ Postgres:
69
+
70
+ gem install pg -- --with-pg-config=<path to pg_config>
71
+
72
+ If you're installing via Bundler, you can provide compile hints like so:
73
+
74
+ bundle config build.pg --with-pg-config=<path to pg_config>
75
+
76
+ See README-OS_X.rdoc for more information about installing under MacOS X, and
77
+ README-Windows.rdoc for Windows build/installation instructions.
78
+
79
+ There's also [a Google+ group](http://goo.gl/TFy1U) and a
80
+ [mailing list](http://groups.google.com/group/ruby-pg) if you get stuck, or just
81
+ want to chat about something.
82
+
83
+ If you want to install as a signed gem, the public certs of the gem signers
84
+ can be found in [the `certs` directory](https://github.com/ged/ruby-pg/tree/master/certs)
85
+ of the repository.
86
+
87
+
88
+ ## Type Casts
89
+
90
+ Pg can optionally type cast result values and query parameters in Ruby or
91
+ native C code. This can speed up data transfers to and from the database,
92
+ because String allocations are reduced and conversions in (slower) Ruby code
93
+ can be omitted.
94
+
95
+ Very basic type casting can be enabled by:
96
+ ```ruby
97
+ conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
98
+ # ... this works for result value mapping:
99
+ conn.exec("select 1, now(), '{2,3}'::int[]").values
100
+ # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]
101
+
102
+ conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
103
+ # ... and this for param value mapping:
104
+ conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
105
+ # => [["1", "1.2300000000000000E+00", "{2,3}"]]
106
+ ```
107
+
108
+ But Pg's type casting is highly customizable. That's why it's divided into
109
+ 2 layers:
110
+
111
+ ### Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)
112
+
113
+ This is the lower layer, containing encoding classes that convert Ruby
114
+ objects for transmission to the DBMS and decoding classes to convert
115
+ received data back to Ruby objects. The classes are namespaced according
116
+ to their format and direction in PG::TextEncoder, PG::TextDecoder,
117
+ PG::BinaryEncoder and PG::BinaryDecoder.
118
+
119
+ It is possible to assign a type OID, format code (text or binary) and
120
+ optionally a name to an encoder or decoder object. It's also possible
121
+ to build composite types by assigning an element encoder/decoder.
122
+ PG::Coder objects can be used to set up a PG::TypeMap or alternatively
123
+ to convert single values to/from their string representation.
124
+
125
+ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):
126
+
127
+ * Integer: [TE](rdoc-ref:PG::TextEncoder::Integer), [TD](rdoc-ref:PG::TextDecoder::Integer), [BD](rdoc-ref:PG::BinaryDecoder::Integer) 💡 No links? Switch to [here](https://deveiate.org/code/pg/README_md.html#label-Type+Casts) 💡
128
+ * BE: [Int2](rdoc-ref:PG::BinaryEncoder::Int2), [Int4](rdoc-ref:PG::BinaryEncoder::Int4), [Int8](rdoc-ref:PG::BinaryEncoder::Int8)
129
+ * Float: [TE](rdoc-ref:PG::TextEncoder::Float), [TD](rdoc-ref:PG::TextDecoder::Float), [BD](rdoc-ref:PG::BinaryDecoder::Float)
130
+ * BE: [Float4](rdoc-ref:PG::BinaryEncoder::Float4), [Float8](rdoc-ref:PG::BinaryEncoder::Float8)
131
+ * Numeric: [TE](rdoc-ref:PG::TextEncoder::Numeric), [TD](rdoc-ref:PG::TextDecoder::Numeric)
132
+ * Boolean: [TE](rdoc-ref:PG::TextEncoder::Boolean), [TD](rdoc-ref:PG::TextDecoder::Boolean), [BE](rdoc-ref:PG::BinaryEncoder::Boolean), [BD](rdoc-ref:PG::BinaryDecoder::Boolean)
133
+ * String: [TE](rdoc-ref:PG::TextEncoder::String), [TD](rdoc-ref:PG::TextDecoder::String), [BE](rdoc-ref:PG::BinaryEncoder::String), [BD](rdoc-ref:PG::BinaryDecoder::String)
134
+ * Bytea: [TE](rdoc-ref:PG::TextEncoder::Bytea), [TD](rdoc-ref:PG::TextDecoder::Bytea), [BE](rdoc-ref:PG::BinaryEncoder::Bytea), [BD](rdoc-ref:PG::BinaryDecoder::Bytea)
135
+ * Base64: [TE](rdoc-ref:PG::TextEncoder::ToBase64), [TD](rdoc-ref:PG::TextDecoder::FromBase64), [BE](rdoc-ref:PG::BinaryEncoder::FromBase64), [BD](rdoc-ref:PG::BinaryDecoder::ToBase64)
136
+ * Timestamp:
137
+ * TE: [local](rdoc-ref:PG::TextEncoder::TimestampWithoutTimeZone), [UTC](rdoc-ref:PG::TextEncoder::TimestampUtc), [with-TZ](rdoc-ref:PG::TextEncoder::TimestampWithTimeZone)
138
+ * TD: [local](rdoc-ref:PG::TextDecoder::TimestampLocal), [UTC](rdoc-ref:PG::TextDecoder::TimestampUtc), [UTC-to-local](rdoc-ref:PG::TextDecoder::TimestampUtcToLocal)
139
+ * BE: [local](rdoc-ref:PG::BinaryEncoder::TimestampLocal), [UTC](rdoc-ref:PG::BinaryEncoder::TimestampUtc)
140
+ * BD: [local](rdoc-ref:PG::BinaryDecoder::TimestampLocal), [UTC](rdoc-ref:PG::BinaryDecoder::TimestampUtc), [UTC-to-local](rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal)
141
+ * Date: [TE](rdoc-ref:PG::TextEncoder::Date), [TD](rdoc-ref:PG::TextDecoder::Date), [BE](rdoc-ref:PG::BinaryEncoder::Date), [BD](rdoc-ref:PG::BinaryDecoder::Date)
142
+ * JSON and JSONB: [TE](rdoc-ref:PG::TextEncoder::JSON), [TD](rdoc-ref:PG::TextDecoder::JSON)
143
+ * Inet: [TE](rdoc-ref:PG::TextEncoder::Inet), [TD](rdoc-ref:PG::TextDecoder::Inet)
144
+ * Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array)
145
+ * Composite Type (also called "Row" or "Record"): [TE](rdoc-ref:PG::TextEncoder::Record), [TD](rdoc-ref:PG::TextDecoder::Record)
146
+
147
+ The following text and binary formats can also be encoded although they are not used as column type:
148
+
149
+ * COPY input and output data: [TE](rdoc-ref:PG::TextEncoder::CopyRow), [TD](rdoc-ref:PG::TextDecoder::CopyRow), [BE](rdoc-ref:PG::BinaryEncoder::CopyRow), [BD](rdoc-ref:PG::BinaryDecoder::CopyRow)
150
+ * Literal for insertion into SQL string: [TE](rdoc-ref:PG::TextEncoder::QuotedLiteral)
151
+ * SQL-Identifier: [TE](rdoc-ref:PG::TextEncoder::Identifier), [TD](rdoc-ref:PG::TextDecoder::Identifier)
152
+
153
+ ### PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)
154
+
155
+ A TypeMap defines which value will be converted by which encoder/decoder.
156
+ There are different type map strategies, implemented by several derivations
157
+ of this class. They can be chosen and configured according to the particular
158
+ needs for type casting. The default type map is PG::TypeMapAllStrings.
159
+
160
+ A type map can be assigned per connection or per query respectively per
161
+ result set. Type maps can also be used for COPY in and out data streaming.
162
+ See PG::Connection#copy_data .
163
+
164
+ The following base type maps are available:
165
+
166
+ * PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
167
+ * PG::TypeMapByClass - selects encoder based on the class of the value to be sent
168
+ * PG::TypeMapByColumn - selects encoder and decoder by column order
169
+ * PG::TypeMapByOid - selects decoder by PostgreSQL type OID
170
+ * PG::TypeMapInRuby - define a custom type map in ruby
171
+
172
+ The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :
173
+
174
+ * PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
175
+ * PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
176
+ * PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
177
+
178
+
179
+ ## Thread support
180
+
181
+ PG is thread safe in such a way that different threads can use different PG::Connection objects concurrently.
182
+ However it is not safe to access any Pg objects simultaneously from more than one thread.
183
+ So make sure to open a new database server connection for every new thread or use a wrapper library like ActiveRecord that manages connections in a thread safe way.
184
+
185
+ If messages like the following are printed to stderr, you're probably using one connection from several threads:
186
+
187
+ message type 0x31 arrived from server while idle
188
+ message type 0x32 arrived from server while idle
189
+ message type 0x54 arrived from server while idle
190
+ message type 0x43 arrived from server while idle
191
+ message type 0x5a arrived from server while idle
192
+
193
+
194
+ ## Fiber IO scheduler support
195
+
196
+ Pg is fully compatible with `Fiber.scheduler` introduced in Ruby-3.0 since pg-1.3.0.
197
+ On Windows support for `Fiber.scheduler` is available on Ruby-3.1 or newer.
198
+ All possibly blocking IO operations are routed through the `Fiber.scheduler` if one is registered for the running thread.
199
+ That is why pg internally uses the asynchronous libpq interface even for synchronous/blocking method calls.
200
+ It also uses Ruby's DNS resolution instead of libpq's builtin functions.
201
+
202
+ Internally Pg always uses the nonblocking connection mode of libpq.
203
+ It then behaves like running in blocking mode but ensures, that all blocking IO is handled in Ruby through a possibly registered `Fiber.scheduler`.
204
+ When `PG::Connection.setnonblocking(true)` is called then the nonblocking state stays enabled, but the additional handling of blocking states is disabled, so that the calling program has to handle blocking states on its own.
205
+
206
+ An exception to this rule are the methods for large objects like `PG::Connection#lo_create` and authentication methods using external libraries (like GSSAPI authentication).
207
+ They are not compatible with `Fiber.scheduler`, so that blocking states are not passed to the registered IO scheduler.
208
+ That means the operation will work properly, but IO waiting states can not be used to switch to another Fiber doing IO.
209
+
210
+
211
+ ## Ractor support
212
+
213
+ Pg is fully compatible with Ractor introduced in Ruby-3.0 since pg-1.5.0.
214
+ All type en/decoders and type maps are shareable between ractors if they are made frozen by `Ractor.make_shareable`.
215
+ Also frozen PG::Result and PG::Tuple objects can be shared.
216
+ All frozen objects (except PG::Connection) can still be used to do communication with the PostgreSQL server or to read retrieved data.
217
+
218
+ PG::Connection is not shareable and must be created within each Ractor to establish a dedicated connection.
219
+
220
+
221
+ ## Contributing
222
+
223
+ To report bugs, suggest features, or check out the source with Git,
224
+ [check out the project page](https://github.com/ged/ruby-pg).
225
+
226
+ After checking out the source, install all dependencies:
227
+
228
+ $ bundle install
229
+
230
+ Cleanup extension files, packaging files, test databases.
231
+ Run this to change between PostgreSQL versions:
232
+
233
+ $ rake clean
234
+
235
+ Compile extension:
236
+
237
+ $ rake compile
238
+
239
+ Run tests/specs on the PostgreSQL version that `pg_config --bindir` points to:
240
+
241
+ $ rake test
242
+
243
+ Or run a specific test per file and line number on a specific PostgreSQL version:
244
+
245
+ $ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455
246
+
247
+ Generate the API documentation:
248
+
249
+ $ rake docs
250
+
251
+ Make sure, that all bugs and new features are verified by tests.
252
+
253
+ The current maintainers are Michael Granger <ged@FaerieMUD.org> and
254
+ Lars Kanis <lars@greiz-reinsdorf.de>.
255
+
256
+
257
+ ## Copying
258
+
259
+ Copyright (c) 1997-2022 by the authors.
260
+
261
+ * Jeff Davis <ruby-pg@j-davis.com>
262
+ * Guy Decoux (ts) <decoux@moulon.inra.fr>
263
+ * Michael Granger <ged@FaerieMUD.org>
264
+ * Lars Kanis <lars@greiz-reinsdorf.de>
265
+ * Dave Lee
266
+ * Eiji Matsumoto <usagi@ruby.club.or.jp>
267
+ * Yukihiro Matsumoto <matz@ruby-lang.org>
268
+ * Noboru Saitou <noborus@netlab.jp>
269
+
270
+ You may redistribute this software under the same terms as Ruby itself; see
271
+ https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source
272
+ for details.
273
+
274
+ Portions of the code are from the PostgreSQL project, and are distributed
275
+ under the terms of the PostgreSQL license, included in the file POSTGRES.
276
+
277
+ Portions copyright LAIKA, Inc.
278
+
279
+
280
+ ## Acknowledgments
281
+
282
+ See Contributors.rdoc for the many additional fine people that have contributed
283
+ to this library over the years.
284
+
285
+ We are thankful to the people at the ruby-list and ruby-dev mailing lists.
286
+ And to the people who developed PostgreSQL.
data/Rakefile CHANGED
@@ -1,22 +1,13 @@
1
- #!/usr/bin/env rake
1
+ # -*- rake -*-
2
2
 
3
3
  require 'rbconfig'
4
4
  require 'pathname'
5
5
  require 'tmpdir'
6
-
7
- begin
8
- require 'rake/extensiontask'
9
- rescue LoadError
10
- abort "This Rakefile requires rake-compiler (gem install rake-compiler)"
11
- end
12
-
13
- begin
14
- require 'hoe'
15
- rescue LoadError
16
- abort "This Rakefile requires hoe (gem install hoe)"
17
- end
18
-
6
+ require 'rake/extensiontask'
19
7
  require 'rake/clean'
8
+ require 'rspec/core/rake_task'
9
+ require 'bundler'
10
+ require 'bundler/gem_helper'
20
11
 
21
12
  # Build directory constants
22
13
  BASEDIR = Pathname( __FILE__ ).dirname
@@ -25,102 +16,38 @@ LIBDIR = BASEDIR + 'lib'
25
16
  EXTDIR = BASEDIR + 'ext'
26
17
  PKGDIR = BASEDIR + 'pkg'
27
18
  TMPDIR = BASEDIR + 'tmp'
19
+ TESTDIR = BASEDIR + "tmp_test_*"
28
20
 
29
21
  DLEXT = RbConfig::CONFIG['DLEXT']
30
22
  EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
23
 
32
24
  GEMSPEC = 'pg.gemspec'
33
25
 
34
- TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
35
-
36
- CLOBBER.include( TEST_DIRECTORY.to_s )
26
+ CLEAN.include( TESTDIR.to_s )
37
27
  CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
38
-
39
- # Set up Hoe plugins
40
- Hoe.plugin :mercurial
41
- Hoe.plugin :signing
42
- Hoe.plugin :deveiate
43
- Hoe.plugin :bundler
44
-
45
- Hoe.plugins.delete :rubyforge
46
- Hoe.plugins.delete :compiler
28
+ CLEAN.include "lib/*/libpq.dll"
29
+ CLEAN.include "lib/pg_ext.*"
30
+ CLEAN.include "lib/pg/postgresql_lib_path.rb"
47
31
 
48
32
  load 'Rakefile.cross'
49
33
 
50
-
51
- # Hoe specification
52
- $hoespec = Hoe.spec 'pg' do
53
- self.readme_file = 'README.rdoc'
54
- self.history_file = 'History.rdoc'
55
- self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
56
- self.extra_rdoc_files.include( 'POSTGRES', 'LICENSE' )
57
- self.extra_rdoc_files.include( 'ext/*.c' )
58
- self.license :BSD
59
-
60
- self.developer 'Michael Granger', 'ged@FaerieMUD.org'
61
- self.developer 'Lars Kanis', 'lars@greiz-reinsdorf.de'
62
-
63
- self.dependency 'rake-compiler', '~> 0.9', :developer
64
- self.dependency 'hoe', '~> 3.12', :developer
65
- self.dependency 'hoe-deveiate', '~> 0.6', :developer
66
- self.dependency 'hoe-bundler', '~> 1.0', :developer
67
- self.dependency 'rspec', '~> 3.0', :developer
68
-
69
- self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
70
- self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
71
-
72
- self.require_ruby_version( '>= 1.9.3' )
73
-
74
- self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
75
- self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
76
- self.spec_extras[:rdoc_options] = [
77
- '-f', 'fivefish',
78
- '-t', 'pg: The Ruby Interface to PostgreSQL',
79
- '-m', 'README.rdoc',
80
- ]
81
-
82
- self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
83
- end
84
-
85
- ENV['VERSION'] ||= $hoespec.spec.version.to_s
86
-
87
- # Tests should pass before checking in
88
- task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
89
-
90
- # Support for 'rvm specs'
91
- task :specs => :spec
92
-
93
- # Compile before testing
94
- task :spec => :compile
95
-
96
- # gem-testers support
97
- task :test do
98
- # rake-compiler always wants to copy the compiled extension into lib/, but
99
- # we don't want testers to have to re-compile, especially since that
100
- # often fails because they can't (and shouldn't have to) write to tmp/ in
101
- # the installed gem dir. So we clear the task rake-compiler set up
102
- # to break the dependency between :spec and :compile when running under
103
- # rubygems-test, and then run :spec.
104
- Rake::Task[ EXT.to_s ].clear
105
- Rake::Task[ :spec ].execute
106
- end
34
+ Bundler::GemHelper.install_tasks
35
+ $gem_spec = Bundler.load_gemspec(GEMSPEC)
107
36
 
108
37
  desc "Turn on warnings and debugging in the build."
109
38
  task :maint do
110
39
  ENV['MAINTAINER_MODE'] = 'yes'
111
40
  end
112
41
 
113
- ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.2:2.0.0'
114
-
115
42
  # Rake-compiler task
116
43
  Rake::ExtensionTask.new do |ext|
117
44
  ext.name = 'pg_ext'
118
- ext.gem_spec = $hoespec.spec
45
+ ext.gem_spec = $gem_spec
119
46
  ext.ext_dir = 'ext'
120
47
  ext.lib_dir = 'lib'
121
48
  ext.source_pattern = "*.{c,h}"
122
49
  ext.cross_compile = true
123
- ext.cross_platform = CrossLibraries.map &:for_platform
50
+ ext.cross_platform = CrossLibraries.map(&:for_platform)
124
51
 
125
52
  ext.cross_config_options += CrossLibraries.map do |lib|
126
53
  {
@@ -136,52 +63,39 @@ Rake::ExtensionTask.new do |ext|
136
63
 
137
64
  # Add libpq.dll to windows binary gemspec
138
65
  ext.cross_compiling do |spec|
139
- # mingw32-platform strings differ (RUBY_PLATFORM=i386-mingw32 vs. x86-mingw32 for rubygems)
140
- spec.files << "lib/#{spec.platform.to_s.gsub(/^x86-/, "i386-")}/libpq.dll"
66
+ spec.files << "lib/#{spec.platform}/libpq.dll"
141
67
  end
142
68
  end
143
69
 
70
+ RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
71
+ task :test => :spec
144
72
 
145
- # Make the ChangeLog update if the repo has changed since it was last built
146
- file '.hg/branch' do
147
- warn "WARNING: You need the Mercurial repo to update the ChangeLog"
148
- end
149
- file 'ChangeLog' do |task|
150
- if File.exist?('.hg/branch')
151
- $stderr.puts "Updating the changelog..."
152
- begin
153
- content = make_changelog()
154
- rescue NameError
155
- abort "Packaging tasks require the hoe-mercurial plugin (gem install hoe-mercurial)"
156
- end
157
- File.open( task.name, 'w', 0644 ) do |fh|
158
- fh.print( content )
159
- end
160
- else
161
- touch 'ChangeLog'
162
- end
163
- end
73
+ # Use the fivefish formatter for docs generated from development checkout
74
+ require 'rdoc/task'
164
75
 
165
- # Rebuild the ChangeLog immediately before release
166
- task :prerelease => 'ChangeLog'
76
+ RDoc::Task.new( 'docs' ) do |rdoc|
77
+ rdoc.options = $gem_spec.rdoc_options
78
+ rdoc.rdoc_files = $gem_spec.extra_rdoc_files
79
+ rdoc.generator = :fivefish
80
+ rdoc.rdoc_dir = 'doc'
81
+ end
167
82
 
83
+ desc "Build the source gem #{$gem_spec.full_name}.gem into the pkg directory"
84
+ task :gem => :build
168
85
 
169
- desc "Stop any Postmaster instances that remain after testing."
170
- task :cleanup_testing_dbs do
171
- require 'spec/lib/helpers'
172
- PgTestingHelpers.stop_existing_postmasters()
173
- Rake::Task[:clean].invoke
86
+ task :clobber do
87
+ puts "Stop any Postmaster instances that remain after testing."
88
+ require_relative 'spec/helpers'
89
+ PG::TestingHelpers.stop_existing_postmasters()
174
90
  end
175
91
 
176
92
  desc "Update list of server error codes"
177
93
  task :update_error_codes do
178
- URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=HEAD"
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"
179
95
 
180
96
  ERRORCODES_TXT = "ext/errorcodes.txt"
181
97
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
182
- end
183
98
 
184
- file 'ext/errorcodes.def' => ['ext/errorcodes.rb', 'ext/errorcodes.txt'] do
185
99
  ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
186
100
  end
187
101
 
@@ -190,17 +104,12 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
190
104
  touch 'ext/pg_errors.c'
191
105
  end
192
106
 
193
- task :gemspec => GEMSPEC
194
- file GEMSPEC => __FILE__
195
- task GEMSPEC do |task|
196
- spec = $hoespec.spec
197
- spec.files.delete( '.gemtest' )
198
- spec.version = "#{spec.version}.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
199
- File.open( task.name, 'w' ) do |fh|
200
- fh.write( spec.to_ruby )
201
- end
202
- end
203
-
204
- CLOBBER.include( GEMSPEC.to_s )
205
- task :default => :gemspec
107
+ desc "Translate readme"
108
+ task :translate do
109
+ cd "translation" do
110
+ # po4a's lexer might change, so record its version for reference
111
+ sh "LANG=C po4a --version > .po4a-version"
206
112
 
113
+ sh "po4a po4a.cfg"
114
+ end
115
+ end