pg 0.18.4 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/BSDL +2 -2
- data/ChangeLog +689 -5
- data/History.rdoc +56 -0
- data/Manifest.txt +1 -18
- data/README.rdoc +13 -9
- data/Rakefile +15 -17
- data/Rakefile.cross +8 -7
- data/ext/errorcodes.def +25 -0
- data/ext/errorcodes.txt +13 -1
- data/ext/extconf.rb +9 -1
- data/ext/gvl_wrappers.h +4 -0
- data/ext/pg.c +4 -3
- data/ext/pg.h +6 -3
- data/ext/pg_binary_encoder.c +8 -8
- data/ext/pg_coder.c +31 -10
- data/ext/pg_connection.c +252 -98
- data/ext/pg_copy_coder.c +34 -4
- data/ext/pg_result.c +20 -14
- data/ext/pg_text_encoder.c +62 -42
- data/ext/pg_type_map.c +14 -7
- data/lib/pg/basic_type_mapping.rb +35 -8
- data/lib/pg/connection.rb +46 -10
- data/lib/pg/deprecated_constants.rb +21 -0
- data/lib/pg/result.rb +10 -5
- data/lib/pg/text_decoder.rb +7 -0
- data/lib/pg/text_encoder.rb +8 -0
- data/lib/pg.rb +21 -9
- data/spec/helpers.rb +6 -9
- data/spec/pg/basic_type_mapping_spec.rb +54 -0
- data/spec/pg/connection_spec.rb +158 -26
- data/spec/pg/result_spec.rb +11 -4
- data/spec/pg/type_map_by_class_spec.rb +2 -2
- data/spec/pg/type_map_by_mri_type_spec.rb +1 -1
- data/spec/pg/type_spec.rb +82 -2
- data.tar.gz.sig +0 -0
- metadata +50 -64
- metadata.gz.sig +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
@@ -116,7 +116,7 @@ describe PG::TypeMapByMriType do
|
|
116
116
|
|
117
117
|
it "should allow mixed type conversions" do
|
118
118
|
res = @conn.exec_params( "SELECT $1, $2, $3", [5, 1.23, :TestSymbol], 0, tm )
|
119
|
-
expect( res.values ).to eq([['5', '1.23',
|
119
|
+
expect( res.values ).to eq([['5', '1.23', "[:TestSymbol, #{@conn.internal_encoding.inspect}]"]])
|
120
120
|
expect( res.ftype(0) ).to eq(20)
|
121
121
|
end
|
122
122
|
|
data/spec/pg/type_spec.rb
CHANGED
@@ -39,6 +39,14 @@ describe "PG::Type derivations" do
|
|
39
39
|
end.new
|
40
40
|
end
|
41
41
|
|
42
|
+
let!(:intenc_incrementer_with_encoding) do
|
43
|
+
Class.new(PG::SimpleEncoder) do
|
44
|
+
def encode(value, encoding)
|
45
|
+
r = (value.to_i + 1).to_s + " #{encoding}"
|
46
|
+
r.encode!(encoding)
|
47
|
+
end
|
48
|
+
end.new
|
49
|
+
end
|
42
50
|
let!(:intenc_incrementer_with_int_result) do
|
43
51
|
Class.new(PG::SimpleEncoder) do
|
44
52
|
def encode(value)
|
@@ -127,6 +135,13 @@ describe "PG::Type derivations" do
|
|
127
135
|
expect( quoted_type.decode(%[a.b]) ).to eq( ['a','b'] )
|
128
136
|
expect( quoted_type.decode(%[a]) ).to eq( ['a'] )
|
129
137
|
end
|
138
|
+
|
139
|
+
it 'should split identifier string with correct character encoding' do
|
140
|
+
quoted_type = PG::TextDecoder::Identifier.new
|
141
|
+
v = quoted_type.decode(%[Héllo].encode("iso-8859-1")).first
|
142
|
+
expect( v.encoding ).to eq( Encoding::ISO_8859_1 )
|
143
|
+
expect( v ).to eq( %[Héllo].encode(Encoding::ISO_8859_1) )
|
144
|
+
end
|
130
145
|
end
|
131
146
|
|
132
147
|
it "should raise when decode method is called with wrong args" do
|
@@ -209,6 +224,13 @@ describe "PG::Type derivations" do
|
|
209
224
|
expect( quoted_type.encode( nil ) ).to be_nil
|
210
225
|
end
|
211
226
|
|
227
|
+
it 'should quote identifiers with correct character encoding' do
|
228
|
+
quoted_type = PG::TextEncoder::Identifier.new
|
229
|
+
v = quoted_type.encode(['Héllo'], "iso-8859-1")
|
230
|
+
expect( v ).to eq( %["Héllo"].encode(Encoding::ISO_8859_1) )
|
231
|
+
expect( v.encoding ).to eq( Encoding::ISO_8859_1 )
|
232
|
+
end
|
233
|
+
|
212
234
|
it "will raise a TypeError for invalid arguments to quote_ident" do
|
213
235
|
quoted_type = PG::TextEncoder::Identifier.new
|
214
236
|
expect{ quoted_type.encode( [nil] ) }.to raise_error(TypeError)
|
@@ -220,6 +242,12 @@ describe "PG::Type derivations" do
|
|
220
242
|
expect( intenc_incrementer.encode(3) ).to eq( "4 " )
|
221
243
|
end
|
222
244
|
|
245
|
+
it "should encode with ruby encoder and given character encoding" do
|
246
|
+
r = intenc_incrementer_with_encoding.encode(3, Encoding::CP850)
|
247
|
+
expect( r ).to eq( "4 CP850" )
|
248
|
+
expect( r.encoding ).to eq( Encoding::CP850 )
|
249
|
+
end
|
250
|
+
|
223
251
|
it "should return when ruby encoder returns non string values" do
|
224
252
|
expect( intenc_incrementer_with_int_result.encode(3) ).to eq( 4 )
|
225
253
|
end
|
@@ -447,9 +475,18 @@ describe "PG::Type derivations" do
|
|
447
475
|
end
|
448
476
|
|
449
477
|
context 'array of types with encoder in ruby space' do
|
450
|
-
it 'encodes with quotation' do
|
478
|
+
it 'encodes with quotation and default character encoding' do
|
479
|
+
array_type = PG::TextEncoder::Array.new elements_type: intenc_incrementer, needs_quotation: true
|
480
|
+
r = array_type.encode([3,4])
|
481
|
+
expect( r ).to eq( %[{"4 ","5 "}] )
|
482
|
+
expect( r.encoding ).to eq( Encoding::ASCII_8BIT )
|
483
|
+
end
|
484
|
+
|
485
|
+
it 'encodes with quotation and given character encoding' do
|
451
486
|
array_type = PG::TextEncoder::Array.new elements_type: intenc_incrementer, needs_quotation: true
|
452
|
-
|
487
|
+
r = array_type.encode([3,4], Encoding::CP850)
|
488
|
+
expect( r ).to eq( %[{"4 ","5 "}] )
|
489
|
+
expect( r.encoding ).to eq( Encoding::CP850 )
|
453
490
|
end
|
454
491
|
|
455
492
|
it 'encodes without quotation' do
|
@@ -457,6 +494,20 @@ describe "PG::Type derivations" do
|
|
457
494
|
expect( array_type.encode([3,4]) ).to eq( %[{4 ,5 }] )
|
458
495
|
end
|
459
496
|
|
497
|
+
it 'encodes with default character encoding' do
|
498
|
+
array_type = PG::TextEncoder::Array.new elements_type: intenc_incrementer_with_encoding
|
499
|
+
r = array_type.encode([3,4])
|
500
|
+
expect( r ).to eq( %[{"4 ASCII-8BIT","5 ASCII-8BIT"}] )
|
501
|
+
expect( r.encoding ).to eq( Encoding::ASCII_8BIT )
|
502
|
+
end
|
503
|
+
|
504
|
+
it 'encodes with given character encoding' do
|
505
|
+
array_type = PG::TextEncoder::Array.new elements_type: intenc_incrementer_with_encoding
|
506
|
+
r = array_type.encode([3,4], Encoding::CP850)
|
507
|
+
expect( r ).to eq( %[{"4 CP850","5 CP850"}] )
|
508
|
+
expect( r.encoding ).to eq( Encoding::CP850 )
|
509
|
+
end
|
510
|
+
|
460
511
|
it "should raise when ruby encoder returns non string values" do
|
461
512
|
array_type = PG::TextEncoder::Array.new elements_type: intenc_incrementer_with_int_result, needs_quotation: false
|
462
513
|
expect{ array_type.encode([3,4]) }.to raise_error(TypeError)
|
@@ -473,6 +524,13 @@ describe "PG::Type derivations" do
|
|
473
524
|
quoted_type = PG::TextEncoder::QuotedLiteral.new elements_type: textenc_string_array
|
474
525
|
expect( quoted_type.encode(["'A\",","\\B'"]) ).to eq( %['{"''A\\",","\\\\B''"}'] )
|
475
526
|
end
|
527
|
+
|
528
|
+
it 'should quote literals with correct character encoding' do
|
529
|
+
quoted_type = PG::TextEncoder::QuotedLiteral.new elements_type: textenc_string_array
|
530
|
+
v = quoted_type.encode(["Héllo"], "iso-8859-1")
|
531
|
+
expect( v.encoding ).to eq( Encoding::ISO_8859_1 )
|
532
|
+
expect( v ).to eq( %['{Héllo}'].encode(Encoding::ISO_8859_1) )
|
533
|
+
end
|
476
534
|
end
|
477
535
|
end
|
478
536
|
|
@@ -522,9 +580,19 @@ describe "PG::Type derivations" do
|
|
522
580
|
expect( e.encode("(\xFBm") ).to eq("KPtt")
|
523
581
|
end
|
524
582
|
|
583
|
+
it 'should encode Strings as base64 with correct character encoding' do
|
584
|
+
e = PG::TextEncoder::ToBase64.new
|
585
|
+
v = e.encode("Héllo".encode("utf-16le"), "iso-8859-1")
|
586
|
+
expect( v ).to eq("SOlsbG8=")
|
587
|
+
expect( v.encoding ).to eq(Encoding::ISO_8859_1)
|
588
|
+
end
|
589
|
+
|
525
590
|
it "should encode Strings as base64 in BinaryDecoder" do
|
526
591
|
e = PG::BinaryDecoder::ToBase64.new
|
527
592
|
expect( e.decode("x") ).to eq("eA==")
|
593
|
+
v = e.decode("Héllo".encode("utf-16le"))
|
594
|
+
expect( v ).to eq("SADpAGwAbABvAA==")
|
595
|
+
expect( v.encoding ).to eq(Encoding::ASCII_8BIT)
|
528
596
|
end
|
529
597
|
|
530
598
|
it "should encode Integers as base64" do
|
@@ -611,6 +679,12 @@ describe "PG::Type derivations" do
|
|
611
679
|
expect( encoder.encode([:xyz, 123, 2456, 34567, 456789, 5678901, [1,2,3], 12.1, "abcdefg", nil]) ).
|
612
680
|
to eq("xyz\t123\t2456\t34567\t456789\t5678901\t[1, 2, 3]\t12.1\tabcdefg\t\\N\n")
|
613
681
|
end
|
682
|
+
|
683
|
+
it 'should output a string with correct character encoding' do
|
684
|
+
v = encoder.encode(["Héllo"], "iso-8859-1")
|
685
|
+
expect( v.encoding ).to eq( Encoding::ISO_8859_1 )
|
686
|
+
expect( v ).to eq( "Héllo\n".encode(Encoding::ISO_8859_1) )
|
687
|
+
end
|
614
688
|
end
|
615
689
|
|
616
690
|
context "with TypeMapByClass" do
|
@@ -675,6 +749,12 @@ describe "PG::Type derivations" do
|
|
675
749
|
it "should decode different types of Ruby objects" do
|
676
750
|
expect( decoder.decode("123\t \0#\t#\n#\r#\\ \t234\t#\x01#\002\n".gsub("#", "\\"))).to eq( ["123", " \0\t\n\r\\ ", "234", "\x01\x02"] )
|
677
751
|
end
|
752
|
+
|
753
|
+
it 'should respect input character encoding' do
|
754
|
+
v = decoder.decode("Héllo\n".encode("iso-8859-1")).first
|
755
|
+
expect( v.encoding ).to eq(Encoding::ISO_8859_1)
|
756
|
+
expect( v ).to eq("Héllo".encode("iso-8859-1"))
|
757
|
+
end
|
678
758
|
end
|
679
759
|
end
|
680
760
|
|
data.tar.gz.sig
CHANGED
Binary file
|
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.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -11,27 +11,32 @@ bindir: bin
|
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
14
|
+
MIIEbDCCAtSgAwIBAgIBATANBgkqhkiG9w0BAQsFADA+MQwwCgYDVQQDDANnZWQx
|
15
15
|
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
16
|
-
|
16
|
+
HhcNMTYwODIwMTgxNzQyWhcNMTcwODIwMTgxNzQyWjA+MQwwCgYDVQQDDANnZWQx
|
17
17
|
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC/JWGRHO+USzR97vXjkFgt
|
19
|
+
83qeNf2KHkcvrRTSnR64i6um/ziin0I0oX23H7VYrDJC9A/uoUa5nGRJS5Zw/+wW
|
20
|
+
ENcvWVZS4iUzi4dsYJGY6yEOsXh2CcF46+QevV8iE+UmbkU75V7Dy1JCaUOyizEt
|
21
|
+
TH5UHsOtUU7k9TYARt/TgYZKuaoAMZZd5qyVqhF1vV+7/Qzmp89NGflXf2xYP26a
|
22
|
+
4MAX2qqKX/FKXqmFO+AGsbwYTEds1mksBF3fGsFgsQWxftG8GfZQ9+Cyu2+l1eOw
|
23
|
+
cZ+lPcg834G9DrqW2zhqUoLr1MTly4pqxYGb7XoDhoR7dd1kFE2a067+DzWC/ADt
|
24
|
+
+QkcqWUm5oh1fN0eqr7NsZlVJDulFgdiiYPQiIN7UNsii4Wc9aZqBoGcYfBeQNPZ
|
25
|
+
soo/6za/bWajOKUmDhpqvaiRv9EDpVLzuj53uDoukMMwxCMfgb04+ckQ0t2G7wqc
|
26
|
+
/D+K9JW9DDs3Yjgv9k4h7YMhW5gftosd+NkNC/+Y2CkCAwEAAaN1MHMwCQYDVR0T
|
27
|
+
BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFHKN/nkRusdqCJEuq3lgB3fJvyTg
|
28
|
+
MBwGA1UdEQQVMBOBEWdlZEBGYWVyaWVNVUQub3JnMBwGA1UdEgQVMBOBEWdlZEBG
|
29
|
+
YWVyaWVNVUQub3JnMA0GCSqGSIb3DQEBCwUAA4IBgQAPJzKiT0zBU7kpqe0aS2qb
|
30
|
+
FI0PJ4y5I8buU4IZGUD5NEt/N7pZNfOyBxkrZkXhS44Fp+xwBH5ebLbq/WY78Bqd
|
31
|
+
db0z6ZgW4LMYMpWFfbXsRbd9TU2f52L8oMAhxOvF7Of5qJMVWuFQ8FPagk2iHrdH
|
32
|
+
inYLQagqAF6goWTXgAJCdPd6SNeeSNqA6vlY7CV1Jh5kfNJJ6xu/CVij1GzCLu/5
|
33
|
+
DMOr26DBv+qLJRRC/2h34uX71q5QgeOyxvMg+7V3u/Q06DXyQ2VgeeqiwDFFpEH0
|
34
|
+
PFkdPO6ZqbTRcLfNH7mFgCBJjsfSjJrn0sPBlYyOXgCoByfZnZyrIMH/UY+lgQqS
|
35
|
+
6Von1VDsfQm0eJh5zYZD64ZF86phSR7mUX3mXItwH04HrZwkWpvgd871DZVR3i1n
|
36
|
+
w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
|
37
|
+
p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
|
33
38
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
39
|
+
date: 2017-06-12 00:00:00.000000000 Z
|
35
40
|
dependencies:
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: hoe-mercurial
|
@@ -53,14 +58,14 @@ dependencies:
|
|
53
58
|
requirements:
|
54
59
|
- - "~>"
|
55
60
|
- !ruby/object:Gem::Version
|
56
|
-
version: '0.
|
61
|
+
version: '0.9'
|
57
62
|
type: :development
|
58
63
|
prerelease: false
|
59
64
|
version_requirements: !ruby/object:Gem::Requirement
|
60
65
|
requirements:
|
61
66
|
- - "~>"
|
62
67
|
- !ruby/object:Gem::Version
|
63
|
-
version: '0.
|
68
|
+
version: '0.9'
|
64
69
|
- !ruby/object:Gem::Dependency
|
65
70
|
name: hoe-highline
|
66
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,93 +81,93 @@ dependencies:
|
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: '0.2'
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
84
|
+
name: rake-compiler
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
86
|
requirements:
|
82
87
|
- - "~>"
|
83
88
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
89
|
+
version: '1.0'
|
85
90
|
type: :development
|
86
91
|
prerelease: false
|
87
92
|
version_requirements: !ruby/object:Gem::Requirement
|
88
93
|
requirements:
|
89
94
|
- - "~>"
|
90
95
|
- !ruby/object:Gem::Version
|
91
|
-
version: '
|
96
|
+
version: '1.0'
|
92
97
|
- !ruby/object:Gem::Dependency
|
93
|
-
name: rake-compiler
|
98
|
+
name: rake-compiler-dock
|
94
99
|
requirement: !ruby/object:Gem::Requirement
|
95
100
|
requirements:
|
96
101
|
- - "~>"
|
97
102
|
- !ruby/object:Gem::Version
|
98
|
-
version: '0.
|
103
|
+
version: '0.6'
|
99
104
|
type: :development
|
100
105
|
prerelease: false
|
101
106
|
version_requirements: !ruby/object:Gem::Requirement
|
102
107
|
requirements:
|
103
108
|
- - "~>"
|
104
109
|
- !ruby/object:Gem::Version
|
105
|
-
version: '0.
|
110
|
+
version: '0.6'
|
106
111
|
- !ruby/object:Gem::Dependency
|
107
|
-
name:
|
112
|
+
name: hoe-bundler
|
108
113
|
requirement: !ruby/object:Gem::Requirement
|
109
114
|
requirements:
|
110
115
|
- - "~>"
|
111
116
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0
|
117
|
+
version: '1.0'
|
113
118
|
type: :development
|
114
119
|
prerelease: false
|
115
120
|
version_requirements: !ruby/object:Gem::Requirement
|
116
121
|
requirements:
|
117
122
|
- - "~>"
|
118
123
|
- !ruby/object:Gem::Version
|
119
|
-
version: '0
|
124
|
+
version: '1.0'
|
120
125
|
- !ruby/object:Gem::Dependency
|
121
|
-
name:
|
126
|
+
name: rspec
|
122
127
|
requirement: !ruby/object:Gem::Requirement
|
123
128
|
requirements:
|
124
129
|
- - "~>"
|
125
130
|
- !ruby/object:Gem::Version
|
126
|
-
version: '3.
|
131
|
+
version: '3.5'
|
127
132
|
type: :development
|
128
133
|
prerelease: false
|
129
134
|
version_requirements: !ruby/object:Gem::Requirement
|
130
135
|
requirements:
|
131
136
|
- - "~>"
|
132
137
|
- !ruby/object:Gem::Version
|
133
|
-
version: '3.
|
138
|
+
version: '3.5'
|
134
139
|
- !ruby/object:Gem::Dependency
|
135
|
-
name:
|
140
|
+
name: rdoc
|
136
141
|
requirement: !ruby/object:Gem::Requirement
|
137
142
|
requirements:
|
138
143
|
- - "~>"
|
139
144
|
- !ruby/object:Gem::Version
|
140
|
-
version: '1
|
145
|
+
version: '5.1'
|
141
146
|
type: :development
|
142
147
|
prerelease: false
|
143
148
|
version_requirements: !ruby/object:Gem::Requirement
|
144
149
|
requirements:
|
145
150
|
- - "~>"
|
146
151
|
- !ruby/object:Gem::Version
|
147
|
-
version: '1
|
152
|
+
version: '5.1'
|
148
153
|
- !ruby/object:Gem::Dependency
|
149
|
-
name:
|
154
|
+
name: hoe
|
150
155
|
requirement: !ruby/object:Gem::Requirement
|
151
156
|
requirements:
|
152
157
|
- - "~>"
|
153
158
|
- !ruby/object:Gem::Version
|
154
|
-
version: '3.
|
159
|
+
version: '3.16'
|
155
160
|
type: :development
|
156
161
|
prerelease: false
|
157
162
|
version_requirements: !ruby/object:Gem::Requirement
|
158
163
|
requirements:
|
159
164
|
- - "~>"
|
160
165
|
- !ruby/object:Gem::Version
|
161
|
-
version: '3.
|
166
|
+
version: '3.16'
|
162
167
|
description: |-
|
163
168
|
Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
|
164
169
|
|
165
|
-
It works with {PostgreSQL
|
170
|
+
It works with {PostgreSQL 9.1 and later}[http://www.postgresql.org/support/versioning/].
|
166
171
|
|
167
172
|
A small example usage:
|
168
173
|
|
@@ -174,7 +179,7 @@ description: |-
|
|
174
179
|
conn = PG.connect( dbname: 'sales' )
|
175
180
|
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
|
176
181
|
puts " PID | User | Query"
|
177
|
-
|
182
|
+
result.each do |row|
|
178
183
|
puts " %7d | %-16s | %s " %
|
179
184
|
row.values_at('procpid', 'usename', 'current_query')
|
180
185
|
end
|
@@ -264,29 +269,12 @@ files:
|
|
264
269
|
- lib/pg/coder.rb
|
265
270
|
- lib/pg/connection.rb
|
266
271
|
- lib/pg/constants.rb
|
272
|
+
- lib/pg/deprecated_constants.rb
|
267
273
|
- lib/pg/exceptions.rb
|
268
274
|
- lib/pg/result.rb
|
269
275
|
- lib/pg/text_decoder.rb
|
270
276
|
- lib/pg/text_encoder.rb
|
271
277
|
- 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
278
|
- spec/data/expected_trace.out
|
291
279
|
- spec/data/random_binary_data
|
292
280
|
- spec/helpers.rb
|
@@ -303,9 +291,7 @@ files:
|
|
303
291
|
- spec/pg_spec.rb
|
304
292
|
homepage: https://bitbucket.org/ged/ruby-pg
|
305
293
|
licenses:
|
306
|
-
- BSD
|
307
|
-
- Ruby
|
308
|
-
- GPL
|
294
|
+
- BSD-3-Clause
|
309
295
|
metadata: {}
|
310
296
|
post_install_message:
|
311
297
|
rdoc_options:
|
@@ -317,7 +303,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
317
303
|
requirements:
|
318
304
|
- - ">="
|
319
305
|
- !ruby/object:Gem::Version
|
320
|
-
version:
|
306
|
+
version: 2.0.0
|
321
307
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
322
308
|
requirements:
|
323
309
|
- - ">="
|
@@ -325,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
311
|
version: '0'
|
326
312
|
requirements: []
|
327
313
|
rubyforge_project:
|
328
|
-
rubygems_version: 2.
|
314
|
+
rubygems_version: 2.6.12
|
329
315
|
signing_key:
|
330
316
|
specification_version: 4
|
331
317
|
summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
|
metadata.gz.sig
CHANGED
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
|
-
|
data/sample/async_copyto.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pg'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
# Using COPY asynchronously
|
7
|
-
|
8
|
-
$stderr.puts "Opening database connection ..."
|
9
|
-
conn = PG.connect( :dbname => 'test' )
|
10
|
-
conn.setnonblocking( true )
|
11
|
-
|
12
|
-
socket = conn.socket_io
|
13
|
-
|
14
|
-
$stderr.puts "Running COPY command ..."
|
15
|
-
buf = ''
|
16
|
-
conn.transaction do
|
17
|
-
conn.send_query( "COPY logs TO STDOUT WITH csv" )
|
18
|
-
buf = nil
|
19
|
-
|
20
|
-
# #get_copy_data returns a row if there's a whole one to return, false
|
21
|
-
# if there isn't one but the COPY is still running, or nil when it's
|
22
|
-
# finished.
|
23
|
-
begin
|
24
|
-
$stderr.puts "COPY loop"
|
25
|
-
conn.consume_input
|
26
|
-
while conn.is_busy
|
27
|
-
$stderr.puts " ready loop"
|
28
|
-
select( [socket], nil, nil, 5.0 ) or
|
29
|
-
raise "Timeout (5s) waiting for query response."
|
30
|
-
conn.consume_input
|
31
|
-
end
|
32
|
-
|
33
|
-
buf = conn.get_copy_data
|
34
|
-
$stdout.puts( buf ) if buf
|
35
|
-
end until buf.nil?
|
36
|
-
end
|
37
|
-
|
38
|
-
conn.finish
|
39
|
-
|
data/sample/async_mixed.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pg'
|
4
|
-
|
5
|
-
$stdout.sync = true
|
6
|
-
|
7
|
-
# This is a example of how to mix and match synchronous and async APIs. In this case,
|
8
|
-
# the connection to the server is made syncrhonously, and then queries are
|
9
|
-
# asynchronous.
|
10
|
-
|
11
|
-
TIMEOUT = 5.0 # seconds to wait for an async operation to complete
|
12
|
-
CONN_OPTS = {
|
13
|
-
:host => 'localhost',
|
14
|
-
:dbname => 'test',
|
15
|
-
}
|
16
|
-
|
17
|
-
# Output progress messages
|
18
|
-
def output_progress( msg )
|
19
|
-
puts ">>> #{msg}\n"
|
20
|
-
end
|
21
|
-
|
22
|
-
# Start the (synchronous) connection
|
23
|
-
output_progress "Starting connection..."
|
24
|
-
conn = PG.connect( CONN_OPTS ) or abort "Unable to create a new connection!"
|
25
|
-
|
26
|
-
abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
|
27
|
-
|
28
|
-
# Now grab a reference to the underlying socket to select() on while the query is running
|
29
|
-
socket = conn.socket_io
|
30
|
-
|
31
|
-
# Send the (asynchronous) query
|
32
|
-
output_progress "Sending query"
|
33
|
-
conn.send_query( "SELECT * FROM pg_stat_activity" )
|
34
|
-
|
35
|
-
# Fetch results until there aren't any more
|
36
|
-
loop do
|
37
|
-
output_progress " waiting for a response"
|
38
|
-
|
39
|
-
# Buffer any incoming data on the socket until a full result is ready.
|
40
|
-
conn.consume_input
|
41
|
-
while conn.is_busy
|
42
|
-
output_progress " waiting for data to be available on %p..." % [ socket ]
|
43
|
-
select( [socket], nil, nil, TIMEOUT ) or
|
44
|
-
raise "Timeout waiting for query response."
|
45
|
-
conn.consume_input
|
46
|
-
end
|
47
|
-
|
48
|
-
# Fetch the next result. If there isn't one, the query is finished
|
49
|
-
result = conn.get_result or break
|
50
|
-
|
51
|
-
output_progress "Query result:\n%p\n" % [ result.values ]
|
52
|
-
end
|
53
|
-
|
54
|
-
output_progress "Done."
|
55
|
-
conn.finish
|
56
|
-
|
data/sample/check_conn.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# vim: set nosta noet ts=4 sw=4:
|
3
|
-
# encoding: utf-8
|
4
|
-
|
5
|
-
require 'pg'
|
6
|
-
|
7
|
-
# This is a minimal example of a function that can test an existing PG::Connection and
|
8
|
-
# reset it if necessary.
|
9
|
-
|
10
|
-
def check_connection( conn )
|
11
|
-
begin
|
12
|
-
conn.exec( "SELECT 1" )
|
13
|
-
rescue PG::Error => err
|
14
|
-
$stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
|
15
|
-
conn.reset
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
conn = PG.connect( dbname: 'test' )
|
20
|
-
check_connection( conn )
|
21
|
-
|