pg 0.18.0.pre20141017160319 → 0.18.0.pre20141117110243
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.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ChangeLog +213 -15
- data/History.rdoc +15 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +1 -1
- data/Rakefile +0 -17
- data/ext/extconf.rb +2 -0
- data/ext/pg.c +67 -1
- data/ext/pg.h +50 -13
- data/ext/pg_binary_decoder.c +4 -4
- data/ext/pg_binary_encoder.c +1 -1
- data/ext/pg_coder.c +6 -0
- data/ext/pg_connection.c +50 -55
- data/ext/pg_copy_coder.c +13 -29
- data/ext/pg_errors.c +6 -0
- data/ext/pg_result.c +273 -77
- data/ext/pg_text_decoder.c +1 -1
- data/ext/pg_text_encoder.c +44 -1
- data/ext/pg_type_map.c +85 -14
- data/ext/pg_type_map_all_strings.c +16 -13
- data/ext/pg_type_map_by_class.c +239 -0
- data/ext/pg_type_map_by_column.c +81 -23
- data/ext/pg_type_map_by_mri_type.c +42 -24
- data/ext/pg_type_map_by_oid.c +52 -20
- data/ext/util.c +1 -1
- data/lib/pg.rb +3 -3
- data/lib/pg/basic_type_mapping.rb +13 -13
- data/lib/pg/coder.rb +9 -0
- data/sample/disk_usage_report.rb +1 -1
- data/sample/pg_statistics.rb +1 -1
- data/sample/replication_monitor.rb +1 -1
- data/spec/helpers.rb +5 -3
- data/spec/pg/basic_type_mapping_spec.rb +1 -1
- data/spec/pg/connection_spec.rb +16 -5
- data/spec/pg/result_spec.rb +77 -3
- data/spec/pg/type_map_by_class_spec.rb +138 -0
- data/spec/pg/type_map_by_column_spec.rb +87 -0
- data/spec/pg/type_map_by_mri_type_spec.rb +14 -0
- data/spec/pg/type_map_by_oid_spec.rb +21 -0
- data/spec/pg/type_spec.rb +27 -7
- data/spec/pg_spec.rb +14 -0
- metadata +24 -21
- metadata.gz.sig +0 -0
@@ -46,6 +46,28 @@ describe PG::TypeMapByColumn do
|
|
46
46
|
expect( cm.oids ).to eq( [23, 25, 700, 123456, nil] )
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should gracefully handle not initialized state" do
|
50
|
+
# PG::TypeMapByColumn is not initialized in allocate function, like other
|
51
|
+
# type maps, but in #initialize. So it might be not called by derived classes.
|
52
|
+
|
53
|
+
not_init = Class.new(PG::TypeMapByColumn) do
|
54
|
+
def initialize
|
55
|
+
# no super call
|
56
|
+
end
|
57
|
+
end.new
|
58
|
+
|
59
|
+
expect{ @conn.exec_params( "SELECT $1", [ 0 ], 0, not_init ) }.to raise_error(NotImplementedError)
|
60
|
+
|
61
|
+
res = @conn.exec( "SELECT 1" )
|
62
|
+
expect{ res.type_map = not_init }.to raise_error(NotImplementedError)
|
63
|
+
|
64
|
+
@conn.copy_data("COPY (SELECT 1) TO STDOUT") do
|
65
|
+
decoder = PG::TextDecoder::CopyRow.new(type_map: not_init)
|
66
|
+
expect{ @conn.get_copy_data(false, decoder) }.to raise_error(NotImplementedError)
|
67
|
+
@conn.get_copy_data
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
49
71
|
|
50
72
|
#
|
51
73
|
# Encoding Examples
|
@@ -95,6 +117,25 @@ describe PG::TypeMapByColumn do
|
|
95
117
|
}.to raise_error(ArgumentError, /mapped columns/)
|
96
118
|
end
|
97
119
|
|
120
|
+
it "should verify the default type map for query params as well" do
|
121
|
+
tm1 = PG::TypeMapByColumn.new([])
|
122
|
+
expect{
|
123
|
+
@conn.exec_params( "SELECT $1", [ 123 ], 0, PG::TypeMapByColumn.new([nil]).with_default_type_map(tm1) )
|
124
|
+
}.to raise_error(ArgumentError, /mapped columns/)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "forwards query param conversions to the #default_type_map" do
|
128
|
+
tm1 = PG::TypeMapByClass.new
|
129
|
+
tm1[Integer] = PG::TextEncoder::Integer.new name: 'INT2', oid: 21
|
130
|
+
|
131
|
+
tm2 = PG::TypeMapByColumn.new( [textenc_int, nil, nil] ).with_default_type_map( tm1 )
|
132
|
+
res = @conn.exec_params( "SELECT $1, $2, $3::TEXT", [1, 2, :abc], 0, tm2 )
|
133
|
+
|
134
|
+
expect( res.ftype(0) ).to eq( 23 ) # tm2
|
135
|
+
expect( res.ftype(1) ).to eq( 21 ) # tm1
|
136
|
+
expect( res.getvalue(0,2) ).to eq( "abc" ) # TypeMapAllStrings
|
137
|
+
end
|
138
|
+
|
98
139
|
#
|
99
140
|
# Decoding Examples
|
100
141
|
#
|
@@ -122,6 +163,52 @@ describe PG::TypeMapByColumn do
|
|
122
163
|
expect{ res.type_map = PG::TypeMapByColumn.new([]) }.to raise_error(ArgumentError, /mapped columns/)
|
123
164
|
end
|
124
165
|
|
166
|
+
it "should verify the default type map for result values as well" do
|
167
|
+
res = @conn.exec( "SELECT 1" )
|
168
|
+
tm1 = PG::TypeMapByColumn.new([])
|
169
|
+
expect{
|
170
|
+
res.type_map = PG::TypeMapByColumn.new([nil]).with_default_type_map(tm1)
|
171
|
+
}.to raise_error(ArgumentError, /mapped columns/)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "forwards result value conversions to a TypeMapByOid as #default_type_map" do
|
175
|
+
# One run with implicit built TypeMapByColumn and another with online lookup
|
176
|
+
[0, 10].each do |max_rows|
|
177
|
+
tm1 = PG::TypeMapByOid.new
|
178
|
+
tm1.add_coder PG::TextDecoder::Integer.new name: 'INT2', oid: 21
|
179
|
+
tm1.max_rows_for_online_lookup = max_rows
|
180
|
+
|
181
|
+
tm2 = PG::TypeMapByColumn.new( [textdec_int, nil, nil] ).with_default_type_map( tm1 )
|
182
|
+
res = @conn.exec( "SELECT '1'::INT4, '2'::INT2, '3'::INT8" ).map_types!( tm2 )
|
183
|
+
|
184
|
+
expect( res.getvalue(0,0) ).to eq( 1 ) # tm2
|
185
|
+
expect( res.getvalue(0,1) ).to eq( 2 ) # tm1
|
186
|
+
expect( res.getvalue(0,2) ).to eq( "3" ) # TypeMapAllStrings
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "forwards get_copy_data conversions to another TypeMapByColumn as #default_type_map" do
|
191
|
+
tm1 = PG::TypeMapByColumn.new( [textdec_int, nil, nil] )
|
192
|
+
tm2 = PG::TypeMapByColumn.new( [nil, textdec_int, nil] ).with_default_type_map( tm1 )
|
193
|
+
decoder = PG::TextDecoder::CopyRow.new(type_map: tm2)
|
194
|
+
@conn.copy_data("COPY (SELECT 1, 2, 3) TO STDOUT", decoder) do
|
195
|
+
expect( @conn.get_copy_data ).to eq( [1, 2, '3'] )
|
196
|
+
@conn.get_copy_data
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
it "will deny copy queries with different column count" do
|
201
|
+
[[2, 2], [2, 3], [3, 2]].each do |cols1, cols2|
|
202
|
+
tm1 = PG::TypeMapByColumn.new( [textdec_int, nil, nil][0, cols1] )
|
203
|
+
tm2 = PG::TypeMapByColumn.new( [nil, textdec_int, nil][0, cols2] ).with_default_type_map( tm1 )
|
204
|
+
decoder = PG::TextDecoder::CopyRow.new(type_map: tm2)
|
205
|
+
@conn.copy_data("COPY (SELECT 1, 2, 3) TO STDOUT", decoder) do
|
206
|
+
expect{ @conn.get_copy_data }.to raise_error(ArgumentError, /number of copy fields/)
|
207
|
+
@conn.get_copy_data
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
125
212
|
#
|
126
213
|
# Decoding Examples text format
|
127
214
|
#
|
@@ -87,6 +87,20 @@ describe PG::TypeMapByMriType do
|
|
87
87
|
expect{ tm[123] = textenc_float }.to raise_error(TypeError)
|
88
88
|
end
|
89
89
|
|
90
|
+
it "forwards query param conversions to the #default_type_map" do
|
91
|
+
tm1 = PG::TypeMapByColumn.new( [textenc_int, nil, nil] )
|
92
|
+
|
93
|
+
tm2 = PG::TypeMapByMriType.new
|
94
|
+
tm2['T_FIXNUM'] = PG::TextEncoder::Integer.new name: 'INT2', oid: 21
|
95
|
+
tm2.default_type_map = tm1
|
96
|
+
|
97
|
+
res = @conn.exec_params( "SELECT $1, $2, $3::TEXT", ['1', 2, 3], 0, tm2 )
|
98
|
+
|
99
|
+
expect( res.ftype(0) ).to eq( 23 ) # tm1
|
100
|
+
expect( res.ftype(1) ).to eq( 21 ) # tm2
|
101
|
+
expect( res.getvalue(0,2) ).to eq( "3" ) # TypeMapAllStrings
|
102
|
+
end
|
103
|
+
|
90
104
|
#
|
91
105
|
# Decoding Examples
|
92
106
|
#
|
@@ -85,6 +85,27 @@ describe PG::TypeMapByOid do
|
|
85
85
|
expect( tm2.coders ).to eq( [textdec_int, nil, textdec_float, pass_through_type] )
|
86
86
|
end
|
87
87
|
|
88
|
+
it "forwards result value conversions to another TypeMapByOid as #default_type_map" do
|
89
|
+
# One run with implicit built TypeMapByColumn and another with online lookup
|
90
|
+
# for each type map.
|
91
|
+
[[0, 0], [0, 10], [10, 0], [10, 10]].each do |max_rows1, max_rows2|
|
92
|
+
tm1 = PG::TypeMapByOid.new
|
93
|
+
tm1.add_coder PG::TextDecoder::Integer.new name: 'INT2', oid: 21
|
94
|
+
tm1.max_rows_for_online_lookup = max_rows1
|
95
|
+
|
96
|
+
tm2 = PG::TypeMapByOid.new
|
97
|
+
tm2.add_coder PG::TextDecoder::Integer.new name: 'INT4', oid: 23
|
98
|
+
tm2.max_rows_for_online_lookup = max_rows2
|
99
|
+
tm2.default_type_map = tm1
|
100
|
+
|
101
|
+
res = @conn.exec( "SELECT '1'::INT4, '2'::INT2, '3'::INT8" ).map_types!( tm2 )
|
102
|
+
|
103
|
+
expect( res.getvalue(0,0) ).to eq( 1 ) # tm2
|
104
|
+
expect( res.getvalue(0,1) ).to eq( 2 ) # tm1
|
105
|
+
expect( res.getvalue(0,2) ).to eq( "3" ) # TypeMapAllStrings
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
88
109
|
#
|
89
110
|
# Decoding Examples text format
|
90
111
|
#
|
data/spec/pg/type_spec.rb
CHANGED
@@ -15,6 +15,7 @@ describe "PG::Type derivations" do
|
|
15
15
|
let!(:textdec_string) { PG::TextDecoder::String.new }
|
16
16
|
let!(:textenc_timestamp) { PG::TextEncoder::TimestampWithoutTimeZone.new }
|
17
17
|
let!(:textdec_timestamp) { PG::TextDecoder::TimestampWithoutTimeZone.new }
|
18
|
+
let!(:textenc_bytea) { PG::TextEncoder::Bytea.new }
|
18
19
|
let!(:textdec_bytea) { PG::TextDecoder::Bytea.new }
|
19
20
|
let!(:binaryenc_int2) { PG::BinaryEncoder::Int2.new }
|
20
21
|
let!(:binaryenc_int4) { PG::BinaryEncoder::Int4.new }
|
@@ -92,8 +93,8 @@ describe "PG::Type derivations" do
|
|
92
93
|
end
|
93
94
|
|
94
95
|
it "should pass through nil values" do
|
95
|
-
expect( textdec_string.
|
96
|
-
expect( textdec_int.
|
96
|
+
expect( textdec_string.decode( nil )).to be_nil
|
97
|
+
expect( textdec_int.decode( nil )).to be_nil
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
@@ -155,6 +156,10 @@ describe "PG::Type derivations" do
|
|
155
156
|
expect( textenc_float.encode(-Float::NAN) ).to eq( Float::NAN.to_s )
|
156
157
|
end
|
157
158
|
|
159
|
+
it "encodes binary string to bytea" do
|
160
|
+
expect( textenc_bytea.encode("\x00\x01\x02\x03\xef".b) ).to eq( "\\x00010203ef" )
|
161
|
+
end
|
162
|
+
|
158
163
|
it "should encode with ruby encoder" do
|
159
164
|
expect( intenc_incrementer.encode(3) ).to eq( "4 " )
|
160
165
|
end
|
@@ -192,6 +197,21 @@ describe "PG::Type derivations" do
|
|
192
197
|
expect( t.format ).to eq( 0 )
|
193
198
|
expect( t.oid ).to eq( 0 )
|
194
199
|
expect( t.name ).to be_nil
|
200
|
+
|
201
|
+
t = PG::BinaryEncoder::Int4.new
|
202
|
+
expect( t.format ).to eq( 1 )
|
203
|
+
expect( t.oid ).to eq( 0 )
|
204
|
+
expect( t.name ).to be_nil
|
205
|
+
|
206
|
+
t = PG::TextDecoder::String.new
|
207
|
+
expect( t.format ).to eq( 0 )
|
208
|
+
expect( t.oid ).to eq( 0 )
|
209
|
+
expect( t.name ).to be_nil
|
210
|
+
|
211
|
+
t = PG::BinaryDecoder::String.new
|
212
|
+
expect( t.format ).to eq( 1 )
|
213
|
+
expect( t.oid ).to eq( 0 )
|
214
|
+
expect( t.name ).to be_nil
|
195
215
|
end
|
196
216
|
end
|
197
217
|
|
@@ -565,12 +585,12 @@ describe "PG::Type derivations" do
|
|
565
585
|
end
|
566
586
|
end
|
567
587
|
|
568
|
-
context "with
|
588
|
+
context "with TypeMapByClass" do
|
569
589
|
let!(:tm) do
|
570
|
-
tm = PG::
|
571
|
-
tm[
|
572
|
-
tm[
|
573
|
-
tm[
|
590
|
+
tm = PG::TypeMapByClass.new
|
591
|
+
tm[Integer] = textenc_int
|
592
|
+
tm[Float] = intenc_incrementer
|
593
|
+
tm[Array] = PG::TextEncoder::Array.new elements_type: textenc_string
|
574
594
|
tm
|
575
595
|
end
|
576
596
|
let!(:encoder) do
|
data/spec/pg_spec.rb
CHANGED
@@ -12,6 +12,20 @@ describe PG do
|
|
12
12
|
expect( PG.library_version ).to be >= 90100
|
13
13
|
end
|
14
14
|
|
15
|
+
it "can select which of both security libraries to initialize" do
|
16
|
+
# This setting does nothing here, because there is already a connection
|
17
|
+
# to the server, at this point in time.
|
18
|
+
PG.init_openssl(false, true)
|
19
|
+
PG.init_openssl(1, 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can select whether security libraries to initialize" do
|
23
|
+
# This setting does nothing here, because there is already a connection
|
24
|
+
# to the server, at this point in time.
|
25
|
+
PG.init_ssl(false)
|
26
|
+
PG.init_ssl(1)
|
27
|
+
end
|
28
|
+
|
15
29
|
|
16
30
|
it "knows whether or not the library is threadsafe" do
|
17
31
|
expect( PG ).to be_threadsafe()
|
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.0.
|
4
|
+
version: 0.18.0.pre20141117110243
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -11,27 +11,26 @@ 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
|
-
ggcrPfcYeTwWlfZPu2LrBg==
|
14
|
+
MIIDLjCCAhagAwIBAgIBAjANBgkqhkiG9w0BAQUFADA9MQ4wDAYDVQQDDAVrYW5p
|
15
|
+
czEXMBUGCgmSJomT8ixkARkWB2NvbWNhcmQxEjAQBgoJkiaJk/IsZAEZFgJkZTAe
|
16
|
+
Fw0xNDAyMjYwOTMzMDBaFw0xNTAyMjYwOTMzMDBaMD0xDjAMBgNVBAMMBWthbmlz
|
17
|
+
MRcwFQYKCZImiZPyLGQBGRYHY29tY2FyZDESMBAGCgmSJomT8ixkARkWAmRlMIIB
|
18
|
+
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApop+rNmg35bzRugZ21VMGqI6
|
19
|
+
HGzPLO4VHYncWn/xmgPU/ZMcZdfj6MzIaZJ/czXyt4eHpBk1r8QOV3gBXnRXEjVW
|
20
|
+
9xi+EdVOkTV2/AVFKThcbTAQGiF/bT1n2M+B1GTybRzMg6hyhOJeGPqIhLfJEpxn
|
21
|
+
lJi4+ENAVT4MpqHEAGB8yFoPC0GqiOHQsdHxQV3P3c2OZqG+yJey74QtwA2tLcLn
|
22
|
+
Q53c63+VLGsOjODl1yPn/2ejyq8qWu6ahfTxiIlSar2UbwtaQGBDFdb2CXgEufXT
|
23
|
+
L7oaPxlmj+Q2oLOfOnInd2Oxop59HoJCQPsg8f921J43NCQGA8VHK6paxIRDLQID
|
24
|
+
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUvgTdT7fe
|
25
|
+
x17ugO3IOsjEJwW7KP4wDQYJKoZIhvcNAQEFBQADggEBAFmIAhRT0awqLQN9e4Uv
|
26
|
+
ZEk+jUWv4zkb+TWiKFJXlwjPyjGbZY9gVfOwAwMibYOK/t/+57ZzW3d0L12OUwvo
|
27
|
+
on84NVvYtIr1/iskJFWFkMoIquAFCdi9p68stSPMQK2XcrJJuRot29fJtropsZBa
|
28
|
+
2cpaNd/sRYdK4oep2usdKifA1lI0hIkPb3r5nLfwG2lAqBH7WZsUICHcTgR0VEbG
|
29
|
+
z9Ug5qQp9Uz73xC9YdGvGiuOX53LYobHAR4MWi2xxDlHI+ER8mRz0eY2FUuNu/Wj
|
30
|
+
GrqF74zpLl7/KFdHC8VmzwZS18hvDjxeLVuVI2gIGnBInqnlqv05g/l4/1pISh5j
|
31
|
+
dS4=
|
33
32
|
-----END CERTIFICATE-----
|
34
|
-
date: 2014-
|
33
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
35
34
|
dependencies:
|
36
35
|
- !ruby/object:Gem::Dependency
|
37
36
|
name: hoe-mercurial
|
@@ -195,11 +194,13 @@ extra_rdoc_files:
|
|
195
194
|
- ext/pg_text_encoder.c
|
196
195
|
- ext/pg_type_map.c
|
197
196
|
- ext/pg_type_map_all_strings.c
|
197
|
+
- ext/pg_type_map_by_class.c
|
198
198
|
- ext/pg_type_map_by_column.c
|
199
199
|
- ext/pg_type_map_by_mri_type.c
|
200
200
|
- ext/pg_type_map_by_oid.c
|
201
201
|
- ext/util.c
|
202
202
|
files:
|
203
|
+
- ".gemtest"
|
203
204
|
- BSDL
|
204
205
|
- ChangeLog
|
205
206
|
- Contributors.rdoc
|
@@ -232,6 +233,7 @@ files:
|
|
232
233
|
- ext/pg_text_encoder.c
|
233
234
|
- ext/pg_type_map.c
|
234
235
|
- ext/pg_type_map_all_strings.c
|
236
|
+
- ext/pg_type_map_by_class.c
|
235
237
|
- ext/pg_type_map_by_column.c
|
236
238
|
- ext/pg_type_map_by_mri_type.c
|
237
239
|
- ext/pg_type_map_by_oid.c
|
@@ -274,6 +276,7 @@ files:
|
|
274
276
|
- spec/pg/basic_type_mapping_spec.rb
|
275
277
|
- spec/pg/connection_spec.rb
|
276
278
|
- spec/pg/result_spec.rb
|
279
|
+
- spec/pg/type_map_by_class_spec.rb
|
277
280
|
- spec/pg/type_map_by_column_spec.rb
|
278
281
|
- spec/pg/type_map_by_mri_type_spec.rb
|
279
282
|
- spec/pg/type_map_by_oid_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|