pg 0.18.4-x64-mingw32 → 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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/BSDL +2 -2
- data/ChangeLog +0 -5911
- data/History.rdoc +240 -0
- data/Manifest.txt +8 -20
- data/README-Windows.rdoc +4 -4
- data/README.ja.rdoc +1 -2
- data/README.rdoc +64 -15
- data/Rakefile +20 -21
- data/Rakefile.cross +67 -69
- data/ext/errorcodes.def +101 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +33 -2
- data/ext/extconf.rb +26 -36
- data/ext/gvl_wrappers.c +4 -0
- data/ext/gvl_wrappers.h +27 -39
- data/ext/pg.c +156 -145
- data/ext/pg.h +74 -98
- data/ext/pg_binary_decoder.c +82 -15
- data/ext/pg_binary_encoder.c +20 -19
- data/ext/pg_coder.c +103 -21
- data/ext/pg_connection.c +917 -523
- data/ext/pg_copy_coder.c +50 -12
- data/ext/pg_record_coder.c +491 -0
- data/ext/pg_result.c +590 -208
- data/ext/pg_text_decoder.c +606 -40
- data/ext/pg_text_encoder.c +245 -94
- data/ext/pg_tuple.c +549 -0
- data/ext/pg_type_map.c +14 -7
- data/ext/pg_type_map_all_strings.c +4 -4
- data/ext/pg_type_map_by_class.c +9 -4
- data/ext/pg_type_map_by_column.c +7 -6
- data/ext/pg_type_map_by_mri_type.c +1 -1
- data/ext/pg_type_map_by_oid.c +3 -2
- data/ext/pg_type_map_in_ruby.c +1 -1
- data/ext/{util.c → pg_util.c} +10 -10
- data/ext/{util.h → pg_util.h} +2 -2
- data/lib/pg.rb +23 -13
- data/lib/pg/basic_type_mapping.rb +155 -32
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +23 -2
- data/lib/pg/connection.rb +73 -13
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +2 -1
- data/lib/pg/result.rb +24 -7
- data/lib/pg/text_decoder.rb +24 -22
- data/lib/pg/text_encoder.rb +40 -8
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +3 -2
- data/spec/helpers.rb +61 -36
- data/spec/pg/basic_type_mapping_spec.rb +415 -36
- data/spec/pg/connection_spec.rb +732 -327
- data/spec/pg/connection_sync_spec.rb +41 -0
- data/spec/pg/result_spec.rb +253 -21
- data/spec/pg/tuple_spec.rb +333 -0
- data/spec/pg/type_map_by_class_spec.rb +4 -4
- data/spec/pg/type_map_by_column_spec.rb +6 -2
- data/spec/pg/type_map_by_mri_type_spec.rb +2 -2
- data/spec/pg/type_map_by_oid_spec.rb +3 -3
- data/spec/pg/type_map_in_ruby_spec.rb +1 -1
- data/spec/pg/type_map_spec.rb +1 -1
- data/spec/pg/type_spec.rb +446 -20
- data/spec/pg_spec.rb +2 -2
- metadata +66 -78
- metadata.gz.sig +0 -0
- data/lib/2.0/pg_ext.so +0 -0
- data/lib/2.1/pg_ext.so +0 -0
- data/lib/2.2/pg_ext.so +0 -0
- data/lib/x64-mingw32/libpq.dll +0 -0
- data/sample/array_insert.rb +0 -20
- data/sample/async_api.rb +0 -106
- data/sample/async_copyto.rb +0 -39
- data/sample/async_mixed.rb +0 -56
- data/sample/check_conn.rb +0 -21
- data/sample/copyfrom.rb +0 -81
- data/sample/copyto.rb +0 -19
- data/sample/cursor.rb +0 -21
- data/sample/disk_usage_report.rb +0 -186
- data/sample/issue-119.rb +0 -94
- data/sample/losample.rb +0 -69
- data/sample/minimal-testcase.rb +0 -17
- data/sample/notify_wait.rb +0 -72
- data/sample/pg_statistics.rb +0 -294
- data/sample/replication_monitor.rb +0 -231
- data/sample/test_binary_values.rb +0 -33
- data/sample/wal_shipper.rb +0 -434
- data/sample/warehouse_partitions.rb +0 -320
data/spec/pg_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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"
|
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,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
platform:
|
4
|
+
version: 1.2.3
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
8
8
|
- Lars Kanis
|
@@ -11,27 +11,30 @@ bindir: bin
|
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
+
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
MIID+DCCAmCgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
|
15
|
+
REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xOTEyMjQyMDE5NTFaFw0yMDEyMjMyMDE5
|
16
|
+
NTFaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
|
17
|
+
hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
|
18
|
+
L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
|
19
|
+
M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
|
20
|
+
5PU2AEbf04GGSrmqADGWXeaslaoRdb1fu/0M5qfPTRn5V39sWD9umuDAF9qqil/x
|
21
|
+
Sl6phTvgBrG8GExHbNZpLARd3xrBYLEFsX7RvBn2UPfgsrtvpdXjsHGfpT3IPN+B
|
22
|
+
vQ66lts4alKC69TE5cuKasWBm+16A4aEe3XdZBRNmtOu/g81gvwA7fkJHKllJuaI
|
23
|
+
dXzdHqq+zbGZVSQ7pRYHYomD0IiDe1DbIouFnPWmagaBnGHwXkDT2bKKP+s2v21m
|
24
|
+
ozilJg4aar2okb/RA6VS87o+d7g6LpDDMMQjH4G9OPnJENLdhu8KnPw/ivSVvQw7
|
25
|
+
N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYD
|
26
|
+
VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DANBgkqhkiG
|
27
|
+
9w0BAQsFAAOCAYEAifxlz7x0EfT3fjhM520ZEIrWa+tLMuLKNefkY18u8tZnx4EX
|
28
|
+
Xxwh3tna3fvNfrOrdY5leIj1dbv4FTRg+gIBnIxAySqvpGvI/Axg5EdYbwninCLL
|
29
|
+
LAKCmRo+5QwaPMYN2zdHIjGrp8jg1neCo5zy6tVvyTv0DMI6FLrydVJYduMMDFSy
|
30
|
+
gQKR1rVOcCJtnBnLCF9+kKEUKohAHOmGsE7OBZFnjMIpH5yUDUVJKByv0gIipFt0
|
31
|
+
1T6zff6oVU0w8WBiNKR381+6sF3wIZVnVY0XeJg6hNL+YecE8ILxLhHTmtT/BO0S
|
32
|
+
3xPze9uXDR+iD6HYl8KU5QEg/dXFPhfQb512vVkTJDZvMcwu6PxDUjHFChLjAji/
|
33
|
+
AZXjg1C5E9znTkeUR8ieU9F1MOKoiH57a5lYSTI8Ga8PpsNXTxNeXc16Ob26CqrJ
|
34
|
+
83uuAYSy65yXDGXXPVBeKPVnYrqp91pqpS5Nh7wfuiCrE8lgU8PATh7K4BV1UhAT
|
35
|
+
0MHbAT42wTYkfUj3
|
33
36
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
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.
|
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.
|
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:
|
82
|
+
name: rake-compiler
|
80
83
|
requirement: !ruby/object:Gem::Requirement
|
81
84
|
requirements:
|
82
85
|
- - "~>"
|
83
86
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
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: '
|
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
|
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
|
108
|
+
version: '1.0'
|
106
109
|
- !ruby/object:Gem::Dependency
|
107
|
-
name:
|
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
|
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
|
122
|
+
version: '1.0'
|
120
123
|
- !ruby/object:Gem::Dependency
|
121
|
-
name:
|
124
|
+
name: rspec
|
122
125
|
requirement: !ruby/object:Gem::Requirement
|
123
126
|
requirements:
|
124
127
|
- - "~>"
|
125
128
|
- !ruby/object:Gem::Version
|
126
|
-
version: '3.
|
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.
|
136
|
+
version: '3.5'
|
134
137
|
- !ruby/object:Gem::Dependency
|
135
|
-
name:
|
138
|
+
name: rdoc
|
136
139
|
requirement: !ruby/object:Gem::Requirement
|
137
140
|
requirements:
|
138
141
|
- - "~>"
|
139
142
|
- !ruby/object:Gem::Version
|
140
|
-
version: '1
|
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
|
150
|
+
version: '5.1'
|
148
151
|
- !ruby/object:Gem::Dependency
|
149
|
-
name:
|
152
|
+
name: hoe
|
150
153
|
requirement: !ruby/object:Gem::Requirement
|
151
154
|
requirements:
|
152
155
|
- - "~>"
|
153
156
|
- !ruby/object:Gem::Version
|
154
|
-
version: '3.
|
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.
|
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
|
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
|
-
|
180
|
+
result.each do |row|
|
178
181
|
puts " %7d | %-16s | %s " %
|
179
182
|
row.values_at('procpid', 'usename', 'current_query')
|
180
183
|
end
|
@@ -183,7 +186,8 @@ email:
|
|
183
186
|
- ged@FaerieMUD.org
|
184
187
|
- lars@greiz-reinsdorf.de
|
185
188
|
executables: []
|
186
|
-
extensions:
|
189
|
+
extensions:
|
190
|
+
- ext/extconf.rb
|
187
191
|
extra_rdoc_files:
|
188
192
|
- Contributors.rdoc
|
189
193
|
- History.rdoc
|
@@ -203,9 +207,11 @@ extra_rdoc_files:
|
|
203
207
|
- ext/pg_connection.c
|
204
208
|
- ext/pg_copy_coder.c
|
205
209
|
- ext/pg_errors.c
|
210
|
+
- ext/pg_record_coder.c
|
206
211
|
- ext/pg_result.c
|
207
212
|
- ext/pg_text_decoder.c
|
208
213
|
- ext/pg_text_encoder.c
|
214
|
+
- ext/pg_tuple.c
|
209
215
|
- ext/pg_type_map.c
|
210
216
|
- ext/pg_type_map_all_strings.c
|
211
217
|
- ext/pg_type_map_by_class.c
|
@@ -213,7 +219,7 @@ extra_rdoc_files:
|
|
213
219
|
- ext/pg_type_map_by_mri_type.c
|
214
220
|
- ext/pg_type_map_by_oid.c
|
215
221
|
- ext/pg_type_map_in_ruby.c
|
216
|
-
- ext/
|
222
|
+
- ext/pg_util.c
|
217
223
|
files:
|
218
224
|
- ".gemtest"
|
219
225
|
- BSDL
|
@@ -243,9 +249,11 @@ files:
|
|
243
249
|
- ext/pg_connection.c
|
244
250
|
- ext/pg_copy_coder.c
|
245
251
|
- ext/pg_errors.c
|
252
|
+
- ext/pg_record_coder.c
|
246
253
|
- ext/pg_result.c
|
247
254
|
- ext/pg_text_decoder.c
|
248
255
|
- ext/pg_text_encoder.c
|
256
|
+
- ext/pg_tuple.c
|
249
257
|
- ext/pg_type_map.c
|
250
258
|
- ext/pg_type_map_all_strings.c
|
251
259
|
- ext/pg_type_map_by_class.c
|
@@ -253,16 +261,14 @@ files:
|
|
253
261
|
- ext/pg_type_map_by_mri_type.c
|
254
262
|
- ext/pg_type_map_by_oid.c
|
255
263
|
- ext/pg_type_map_in_ruby.c
|
256
|
-
- ext/
|
257
|
-
- ext/
|
264
|
+
- ext/pg_util.c
|
265
|
+
- ext/pg_util.h
|
258
266
|
- ext/vc/pg.sln
|
259
267
|
- ext/vc/pg_18/pg.vcproj
|
260
268
|
- ext/vc/pg_19/pg_19.vcproj
|
261
|
-
- lib/2.0/pg_ext.so
|
262
|
-
- lib/2.1/pg_ext.so
|
263
|
-
- lib/2.2/pg_ext.so
|
264
269
|
- lib/pg.rb
|
265
270
|
- lib/pg/basic_type_mapping.rb
|
271
|
+
- lib/pg/binary_decoder.rb
|
266
272
|
- lib/pg/coder.rb
|
267
273
|
- lib/pg/connection.rb
|
268
274
|
- lib/pg/constants.rb
|
@@ -270,32 +276,16 @@ files:
|
|
270
276
|
- lib/pg/result.rb
|
271
277
|
- lib/pg/text_decoder.rb
|
272
278
|
- lib/pg/text_encoder.rb
|
279
|
+
- lib/pg/tuple.rb
|
273
280
|
- lib/pg/type_map_by_column.rb
|
274
|
-
- lib/x64-mingw32/libpq.dll
|
275
|
-
- sample/array_insert.rb
|
276
|
-
- sample/async_api.rb
|
277
|
-
- sample/async_copyto.rb
|
278
|
-
- sample/async_mixed.rb
|
279
|
-
- sample/check_conn.rb
|
280
|
-
- sample/copyfrom.rb
|
281
|
-
- sample/copyto.rb
|
282
|
-
- sample/cursor.rb
|
283
|
-
- sample/disk_usage_report.rb
|
284
|
-
- sample/issue-119.rb
|
285
|
-
- sample/losample.rb
|
286
|
-
- sample/minimal-testcase.rb
|
287
|
-
- sample/notify_wait.rb
|
288
|
-
- sample/pg_statistics.rb
|
289
|
-
- sample/replication_monitor.rb
|
290
|
-
- sample/test_binary_values.rb
|
291
|
-
- sample/wal_shipper.rb
|
292
|
-
- sample/warehouse_partitions.rb
|
293
281
|
- spec/data/expected_trace.out
|
294
282
|
- spec/data/random_binary_data
|
295
283
|
- spec/helpers.rb
|
296
284
|
- spec/pg/basic_type_mapping_spec.rb
|
297
285
|
- spec/pg/connection_spec.rb
|
286
|
+
- spec/pg/connection_sync_spec.rb
|
298
287
|
- spec/pg/result_spec.rb
|
288
|
+
- spec/pg/tuple_spec.rb
|
299
289
|
- spec/pg/type_map_by_class_spec.rb
|
300
290
|
- spec/pg/type_map_by_column_spec.rb
|
301
291
|
- spec/pg/type_map_by_mri_type_spec.rb
|
@@ -304,12 +294,11 @@ files:
|
|
304
294
|
- spec/pg/type_map_spec.rb
|
305
295
|
- spec/pg/type_spec.rb
|
306
296
|
- spec/pg_spec.rb
|
307
|
-
homepage: https://
|
297
|
+
homepage: https://github.com/ged/ruby-pg
|
308
298
|
licenses:
|
309
|
-
- BSD
|
310
|
-
|
311
|
-
-
|
312
|
-
metadata: {}
|
299
|
+
- BSD-2-Clause
|
300
|
+
metadata:
|
301
|
+
homepage_uri: https://github.com/ged/ruby-pg
|
313
302
|
post_install_message:
|
314
303
|
rdoc_options:
|
315
304
|
- "--main"
|
@@ -320,15 +309,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
320
309
|
requirements:
|
321
310
|
- - ">="
|
322
311
|
- !ruby/object:Gem::Version
|
323
|
-
version:
|
312
|
+
version: '2.2'
|
324
313
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
325
314
|
requirements:
|
326
315
|
- - ">="
|
327
316
|
- !ruby/object:Gem::Version
|
328
317
|
version: '0'
|
329
318
|
requirements: []
|
330
|
-
|
331
|
-
rubygems_version: 2.4.8
|
319
|
+
rubygems_version: 3.0.6
|
332
320
|
signing_key:
|
333
321
|
specification_version: 4
|
334
322
|
summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/2.0/pg_ext.so
DELETED
Binary file
|
data/lib/2.1/pg_ext.so
DELETED
Binary file
|
data/lib/2.2/pg_ext.so
DELETED
Binary file
|
data/lib/x64-mingw32/libpq.dll
DELETED
Binary file
|
data/sample/array_insert.rb
DELETED
@@ -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
|
-
|
data/sample/async_api.rb
DELETED
@@ -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
|
-
|