pg 0.18.4 → 1.2.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 (85) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/BSDL +2 -2
  5. data/ChangeLog +0 -5911
  6. data/History.rdoc +240 -0
  7. data/Manifest.txt +8 -20
  8. data/README-Windows.rdoc +4 -4
  9. data/README.ja.rdoc +1 -2
  10. data/README.rdoc +64 -15
  11. data/Rakefile +20 -21
  12. data/Rakefile.cross +67 -69
  13. data/ext/errorcodes.def +101 -0
  14. data/ext/errorcodes.rb +1 -1
  15. data/ext/errorcodes.txt +33 -2
  16. data/ext/extconf.rb +26 -36
  17. data/ext/gvl_wrappers.c +4 -0
  18. data/ext/gvl_wrappers.h +27 -39
  19. data/ext/pg.c +156 -145
  20. data/ext/pg.h +74 -98
  21. data/ext/pg_binary_decoder.c +82 -15
  22. data/ext/pg_binary_encoder.c +20 -19
  23. data/ext/pg_coder.c +103 -21
  24. data/ext/pg_connection.c +917 -523
  25. data/ext/pg_copy_coder.c +50 -12
  26. data/ext/pg_record_coder.c +491 -0
  27. data/ext/pg_result.c +590 -208
  28. data/ext/pg_text_decoder.c +606 -40
  29. data/ext/pg_text_encoder.c +245 -94
  30. data/ext/pg_tuple.c +549 -0
  31. data/ext/pg_type_map.c +14 -7
  32. data/ext/pg_type_map_all_strings.c +4 -4
  33. data/ext/pg_type_map_by_class.c +9 -4
  34. data/ext/pg_type_map_by_column.c +7 -6
  35. data/ext/pg_type_map_by_mri_type.c +1 -1
  36. data/ext/pg_type_map_by_oid.c +3 -2
  37. data/ext/pg_type_map_in_ruby.c +1 -1
  38. data/ext/{util.c → pg_util.c} +10 -10
  39. data/ext/{util.h → pg_util.h} +2 -2
  40. data/lib/pg.rb +23 -13
  41. data/lib/pg/basic_type_mapping.rb +155 -32
  42. data/lib/pg/binary_decoder.rb +23 -0
  43. data/lib/pg/coder.rb +23 -2
  44. data/lib/pg/connection.rb +73 -13
  45. data/lib/pg/constants.rb +2 -1
  46. data/lib/pg/exceptions.rb +2 -1
  47. data/lib/pg/result.rb +24 -7
  48. data/lib/pg/text_decoder.rb +24 -22
  49. data/lib/pg/text_encoder.rb +40 -8
  50. data/lib/pg/tuple.rb +30 -0
  51. data/lib/pg/type_map_by_column.rb +3 -2
  52. data/spec/helpers.rb +61 -36
  53. data/spec/pg/basic_type_mapping_spec.rb +415 -36
  54. data/spec/pg/connection_spec.rb +732 -327
  55. data/spec/pg/connection_sync_spec.rb +41 -0
  56. data/spec/pg/result_spec.rb +253 -21
  57. data/spec/pg/tuple_spec.rb +333 -0
  58. data/spec/pg/type_map_by_class_spec.rb +4 -4
  59. data/spec/pg/type_map_by_column_spec.rb +6 -2
  60. data/spec/pg/type_map_by_mri_type_spec.rb +2 -2
  61. data/spec/pg/type_map_by_oid_spec.rb +3 -3
  62. data/spec/pg/type_map_in_ruby_spec.rb +1 -1
  63. data/spec/pg/type_map_spec.rb +1 -1
  64. data/spec/pg/type_spec.rb +446 -20
  65. data/spec/pg_spec.rb +2 -2
  66. metadata +63 -72
  67. metadata.gz.sig +0 -0
  68. data/sample/array_insert.rb +0 -20
  69. data/sample/async_api.rb +0 -106
  70. data/sample/async_copyto.rb +0 -39
  71. data/sample/async_mixed.rb +0 -56
  72. data/sample/check_conn.rb +0 -21
  73. data/sample/copyfrom.rb +0 -81
  74. data/sample/copyto.rb +0 -19
  75. data/sample/cursor.rb +0 -21
  76. data/sample/disk_usage_report.rb +0 -186
  77. data/sample/issue-119.rb +0 -94
  78. data/sample/losample.rb +0 -69
  79. data/sample/minimal-testcase.rb +0 -17
  80. data/sample/notify_wait.rb +0 -72
  81. data/sample/pg_statistics.rb +0 -294
  82. data/sample/replication_monitor.rb +0 -231
  83. data/sample/test_binary_values.rb +0 -33
  84. data/sample/wal_shipper.rb +0 -434
  85. data/sample/warehouse_partitions.rb +0 -320
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec
1
+ # -*- rspec -*-
2
2
  # encoding: utf-8
3
3
 
4
4
  require_relative 'helpers'
@@ -7,7 +7,7 @@ require 'pg'
7
7
 
8
8
  describe PG do
9
9
 
10
- it "knows what version of the libpq library is loaded", :postgresql_91 do
10
+ it "knows what version of the libpq library is loaded" do
11
11
  expect( PG.library_version ).to be_an( Integer )
12
12
  expect( PG.library_version ).to be >= 90100
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.4
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -11,27 +11,30 @@ bindir: bin
11
11
  cert_chain:
12
12
  - |
13
13
  -----BEGIN CERTIFICATE-----
14
- MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQwwCgYDVQQDDANnZWQx
15
- GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
16
- HhcNMTUwNDAxMjEyNDEzWhcNMTYwMzMxMjEyNDEzWjA+MQwwCgYDVQQDDANnZWQx
17
- GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
18
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDb92mkyYwuGBg1oRxt2tkH
19
- +Uo3LAsaL/APBfSLzy8o3+B3AUHKCjMUaVeBoZdWtMHB75X3VQlvXfZMyBxj59Vo
20
- cDthr3zdao4HnyrzAIQf7BO5Y8KBwVD+yyXCD/N65TTwqsQnO3ie7U5/9ut1rnNr
21
- OkOzAscMwkfQxBkXDzjvAWa6UF4c5c9kR/T79iA21kDx9+bUMentU59aCJtUcbxa
22
- 7kcKJhPEYsk4OdxR9q2dphNMFDQsIdRO8rywX5FRHvcb+qnXC17RvxLHtOjysPt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00:00:00.000000000 Z
37
+ date: 2020-03-18 00:00:00.000000000 Z
35
38
  dependencies:
36
39
  - !ruby/object:Gem::Dependency
37
40
  name: hoe-mercurial
@@ -53,14 +56,14 @@ dependencies:
53
56
  requirements:
54
57
  - - "~>"
55
58
  - !ruby/object:Gem::Version
56
- version: '0.7'
59
+ version: '0.10'
57
60
  type: :development
58
61
  prerelease: false
59
62
  version_requirements: !ruby/object:Gem::Requirement
60
63
  requirements:
61
64
  - - "~>"
62
65
  - !ruby/object:Gem::Version
63
- version: '0.7'
66
+ version: '0.10'
64
67
  - !ruby/object:Gem::Dependency
65
68
  name: hoe-highline
66
69
  requirement: !ruby/object:Gem::Requirement
@@ -76,93 +79,93 @@ dependencies:
76
79
  - !ruby/object:Gem::Version
77
80
  version: '0.2'
78
81
  - !ruby/object:Gem::Dependency
79
- name: rdoc
82
+ name: rake-compiler
80
83
  requirement: !ruby/object:Gem::Requirement
81
84
  requirements:
82
85
  - - "~>"
83
86
  - !ruby/object:Gem::Version
84
- version: '4.0'
87
+ version: '1.0'
85
88
  type: :development
86
89
  prerelease: false
87
90
  version_requirements: !ruby/object:Gem::Requirement
88
91
  requirements:
89
92
  - - "~>"
90
93
  - !ruby/object:Gem::Version
91
- version: '4.0'
94
+ version: '1.0'
92
95
  - !ruby/object:Gem::Dependency
93
- name: rake-compiler
96
+ name: rake-compiler-dock
94
97
  requirement: !ruby/object:Gem::Requirement
95
98
  requirements:
96
99
  - - "~>"
97
100
  - !ruby/object:Gem::Version
98
- version: '0.9'
101
+ version: '1.0'
99
102
  type: :development
100
103
  prerelease: false
101
104
  version_requirements: !ruby/object:Gem::Requirement
102
105
  requirements:
103
106
  - - "~>"
104
107
  - !ruby/object:Gem::Version
105
- version: '0.9'
108
+ version: '1.0'
106
109
  - !ruby/object:Gem::Dependency
107
- name: rake-compiler-dock
110
+ name: hoe-bundler
108
111
  requirement: !ruby/object:Gem::Requirement
109
112
  requirements:
110
113
  - - "~>"
111
114
  - !ruby/object:Gem::Version
112
- version: '0.3'
115
+ version: '1.0'
113
116
  type: :development
114
117
  prerelease: false
115
118
  version_requirements: !ruby/object:Gem::Requirement
116
119
  requirements:
117
120
  - - "~>"
118
121
  - !ruby/object:Gem::Version
119
- version: '0.3'
122
+ version: '1.0'
120
123
  - !ruby/object:Gem::Dependency
121
- name: hoe
124
+ name: rspec
122
125
  requirement: !ruby/object:Gem::Requirement
123
126
  requirements:
124
127
  - - "~>"
125
128
  - !ruby/object:Gem::Version
126
- version: '3.12'
129
+ version: '3.5'
127
130
  type: :development
128
131
  prerelease: false
129
132
  version_requirements: !ruby/object:Gem::Requirement
130
133
  requirements:
131
134
  - - "~>"
132
135
  - !ruby/object:Gem::Version
133
- version: '3.12'
136
+ version: '3.5'
134
137
  - !ruby/object:Gem::Dependency
135
- name: hoe-bundler
138
+ name: rdoc
136
139
  requirement: !ruby/object:Gem::Requirement
137
140
  requirements:
138
141
  - - "~>"
139
142
  - !ruby/object:Gem::Version
140
- version: '1.0'
143
+ version: '5.1'
141
144
  type: :development
142
145
  prerelease: false
143
146
  version_requirements: !ruby/object:Gem::Requirement
144
147
  requirements:
145
148
  - - "~>"
146
149
  - !ruby/object:Gem::Version
147
- version: '1.0'
150
+ version: '5.1'
148
151
  - !ruby/object:Gem::Dependency
149
- name: rspec
152
+ name: hoe
150
153
  requirement: !ruby/object:Gem::Requirement
151
154
  requirements:
152
155
  - - "~>"
153
156
  - !ruby/object:Gem::Version
154
- version: '3.0'
157
+ version: '3.20'
155
158
  type: :development
156
159
  prerelease: false
157
160
  version_requirements: !ruby/object:Gem::Requirement
158
161
  requirements:
159
162
  - - "~>"
160
163
  - !ruby/object:Gem::Version
161
- version: '3.0'
164
+ version: '3.20'
162
165
  description: |-
163
166
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
164
167
 
165
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
168
+ It works with {PostgreSQL 9.2 and later}[http://www.postgresql.org/support/versioning/].
166
169
 
167
170
  A small example usage:
168
171
 
@@ -174,7 +177,7 @@ description: |-
174
177
  conn = PG.connect( dbname: 'sales' )
175
178
  conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
176
179
  puts " PID | User | Query"
177
- result.each do |row|
180
+ result.each do |row|
178
181
  puts " %7d | %-16s | %s " %
179
182
  row.values_at('procpid', 'usename', 'current_query')
180
183
  end
@@ -204,9 +207,11 @@ extra_rdoc_files:
204
207
  - ext/pg_connection.c
205
208
  - ext/pg_copy_coder.c
206
209
  - ext/pg_errors.c
210
+ - ext/pg_record_coder.c
207
211
  - ext/pg_result.c
208
212
  - ext/pg_text_decoder.c
209
213
  - ext/pg_text_encoder.c
214
+ - ext/pg_tuple.c
210
215
  - ext/pg_type_map.c
211
216
  - ext/pg_type_map_all_strings.c
212
217
  - ext/pg_type_map_by_class.c
@@ -214,7 +219,7 @@ extra_rdoc_files:
214
219
  - ext/pg_type_map_by_mri_type.c
215
220
  - ext/pg_type_map_by_oid.c
216
221
  - ext/pg_type_map_in_ruby.c
217
- - ext/util.c
222
+ - ext/pg_util.c
218
223
  files:
219
224
  - ".gemtest"
220
225
  - BSDL
@@ -244,9 +249,11 @@ files:
244
249
  - ext/pg_connection.c
245
250
  - ext/pg_copy_coder.c
246
251
  - ext/pg_errors.c
252
+ - ext/pg_record_coder.c
247
253
  - ext/pg_result.c
248
254
  - ext/pg_text_decoder.c
249
255
  - ext/pg_text_encoder.c
256
+ - ext/pg_tuple.c
250
257
  - ext/pg_type_map.c
251
258
  - ext/pg_type_map_all_strings.c
252
259
  - ext/pg_type_map_by_class.c
@@ -254,13 +261,14 @@ files:
254
261
  - ext/pg_type_map_by_mri_type.c
255
262
  - ext/pg_type_map_by_oid.c
256
263
  - ext/pg_type_map_in_ruby.c
257
- - ext/util.c
258
- - ext/util.h
264
+ - ext/pg_util.c
265
+ - ext/pg_util.h
259
266
  - ext/vc/pg.sln
260
267
  - ext/vc/pg_18/pg.vcproj
261
268
  - ext/vc/pg_19/pg_19.vcproj
262
269
  - lib/pg.rb
263
270
  - lib/pg/basic_type_mapping.rb
271
+ - lib/pg/binary_decoder.rb
264
272
  - lib/pg/coder.rb
265
273
  - lib/pg/connection.rb
266
274
  - lib/pg/constants.rb
@@ -268,31 +276,16 @@ files:
268
276
  - lib/pg/result.rb
269
277
  - lib/pg/text_decoder.rb
270
278
  - lib/pg/text_encoder.rb
279
+ - lib/pg/tuple.rb
271
280
  - lib/pg/type_map_by_column.rb
272
- - sample/array_insert.rb
273
- - sample/async_api.rb
274
- - sample/async_copyto.rb
275
- - sample/async_mixed.rb
276
- - sample/check_conn.rb
277
- - sample/copyfrom.rb
278
- - sample/copyto.rb
279
- - sample/cursor.rb
280
- - sample/disk_usage_report.rb
281
- - sample/issue-119.rb
282
- - sample/losample.rb
283
- - sample/minimal-testcase.rb
284
- - sample/notify_wait.rb
285
- - sample/pg_statistics.rb
286
- - sample/replication_monitor.rb
287
- - sample/test_binary_values.rb
288
- - sample/wal_shipper.rb
289
- - sample/warehouse_partitions.rb
290
281
  - spec/data/expected_trace.out
291
282
  - spec/data/random_binary_data
292
283
  - spec/helpers.rb
293
284
  - spec/pg/basic_type_mapping_spec.rb
294
285
  - spec/pg/connection_spec.rb
286
+ - spec/pg/connection_sync_spec.rb
295
287
  - spec/pg/result_spec.rb
288
+ - spec/pg/tuple_spec.rb
296
289
  - spec/pg/type_map_by_class_spec.rb
297
290
  - spec/pg/type_map_by_column_spec.rb
298
291
  - spec/pg/type_map_by_mri_type_spec.rb
@@ -301,12 +294,11 @@ files:
301
294
  - spec/pg/type_map_spec.rb
302
295
  - spec/pg/type_spec.rb
303
296
  - spec/pg_spec.rb
304
- homepage: https://bitbucket.org/ged/ruby-pg
297
+ homepage: https://github.com/ged/ruby-pg
305
298
  licenses:
306
- - BSD
307
- - Ruby
308
- - GPL
309
- metadata: {}
299
+ - BSD-2-Clause
300
+ metadata:
301
+ homepage_uri: https://github.com/ged/ruby-pg
310
302
  post_install_message:
311
303
  rdoc_options:
312
304
  - "--main"
@@ -317,15 +309,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
317
309
  requirements:
318
310
  - - ">="
319
311
  - !ruby/object:Gem::Version
320
- version: 1.9.3
312
+ version: '2.2'
321
313
  required_rubygems_version: !ruby/object:Gem::Requirement
322
314
  requirements:
323
315
  - - ">="
324
316
  - !ruby/object:Gem::Version
325
317
  version: '0'
326
318
  requirements: []
327
- rubyforge_project:
328
- rubygems_version: 2.4.5.1
319
+ rubygems_version: 3.0.6
329
320
  signing_key:
330
321
  specification_version: 4
331
322
  summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
metadata.gz.sig CHANGED
Binary file
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
-
5
- c = PG.connect( dbname: 'test' )
6
-
7
- # this one works:
8
- c.exec( "DROP TABLE IF EXISTS foo" )
9
- c.exec( "CREATE TABLE foo (strings character varying[]);" )
10
-
11
- # But using a prepared statement works:
12
- c.set_error_verbosity( PG::PQERRORS_VERBOSE )
13
- c.prepare( 'stmt', "INSERT INTO foo VALUES ($1);" )
14
-
15
- # This won't work
16
- #c.exec_prepared( 'stmt', ["ARRAY['this','that']"] )
17
-
18
- # but this will:
19
- c.exec_prepared( 'stmt', ["{'this','that'}"] )
20
-
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
-
5
- # This is a example of how to use the asynchronous API to query the
6
- # server without blocking other threads. It's intentionally low-level;
7
- # if you hooked up the PG::Connection#socket to some kind of reactor, you
8
- # could make this much nicer.
9
-
10
- TIMEOUT = 5.0 # seconds to wait for an async operation to complete
11
-
12
- # Print 'x' continuously to demonstrate that other threads aren't
13
- # blocked while waiting for the connection, for the query to be sent,
14
- # for results, etc. You might want to sleep inside the loop or
15
- # comment this out entirely for cleaner output.
16
- progress_thread = Thread.new { loop { print 'x' } }
17
-
18
- # Output progress messages
19
- def output_progress( msg )
20
- puts "\n>>> #{msg}\n"
21
- end
22
-
23
- # Start the connection
24
- output_progress "Starting connection..."
25
- conn = PG::Connection.connect_start( :dbname => 'test' ) or
26
- abort "Unable to create a new connection!"
27
- abort "Connection failed: %s" % [ conn.error_message ] if
28
- conn.status == PG::CONNECTION_BAD
29
-
30
- # Now grab a reference to the underlying socket so we know when the
31
- # connection is established
32
- socket = conn.socket_io
33
-
34
- # Track the progress of the connection, waiting for the socket to become readable/writable
35
- # before polling it
36
- poll_status = PG::PGRES_POLLING_WRITING
37
- until poll_status == PG::PGRES_POLLING_OK ||
38
- poll_status == PG::PGRES_POLLING_FAILED
39
-
40
- # If the socket needs to read, wait 'til it becomes readable to poll again
41
- case poll_status
42
- when PG::PGRES_POLLING_READING
43
- output_progress " waiting for socket to become readable"
44
- select( [socket], nil, nil, TIMEOUT ) or
45
- raise "Asynchronous connection timed out!"
46
-
47
- # ...and the same for when the socket needs to write
48
- when PG::PGRES_POLLING_WRITING
49
- output_progress " waiting for socket to become writable"
50
- select( nil, [socket], nil, TIMEOUT ) or
51
- raise "Asynchronous connection timed out!"
52
- end
53
-
54
- # Output a status message about the progress
55
- case conn.status
56
- when PG::CONNECTION_STARTED
57
- output_progress " waiting for connection to be made."
58
- when PG::CONNECTION_MADE
59
- output_progress " connection OK; waiting to send."
60
- when PG::CONNECTION_AWAITING_RESPONSE
61
- output_progress " waiting for a response from the server."
62
- when PG::CONNECTION_AUTH_OK
63
- output_progress " received authentication; waiting for backend start-up to finish."
64
- when PG::CONNECTION_SSL_STARTUP
65
- output_progress " negotiating SSL encryption."
66
- when PG::CONNECTION_SETENV
67
- output_progress " negotiating environment-driven parameter settings."
68
- when PG::CONNECTION_NEEDED
69
- output_progress " internal state: connect() needed."
70
- end
71
-
72
- # Check to see if it's finished or failed yet
73
- poll_status = conn.connect_poll
74
- end
75
-
76
- abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
77
-
78
- output_progress "Sending query"
79
- conn.send_query( "SELECT * FROM pg_stat_activity" )
80
-
81
- # Fetch results until there aren't any more
82
- loop do
83
- output_progress " waiting for a response"
84
-
85
- # Buffer any incoming data on the socket until a full result is ready.
86
- conn.consume_input
87
- while conn.is_busy
88
- select( [socket], nil, nil, TIMEOUT ) or
89
- raise "Timeout waiting for query response."
90
- conn.consume_input
91
- end
92
-
93
- # Fetch the next result. If there isn't one, the query is finished
94
- result = conn.get_result or break
95
-
96
- puts "\n\nQuery result:\n%p\n" % [ result.values ]
97
- end
98
-
99
- output_progress "Done."
100
- conn.finish
101
-
102
- if defined?( progress_thread )
103
- progress_thread.kill
104
- progress_thread.join
105
- end
106
-