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.
@@ -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
  #
@@ -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.encode( nil )).to be_nil
96
- expect( textdec_int.encode( nil )).to be_nil
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 TypeMapByMriType" do
588
+ context "with TypeMapByClass" do
569
589
  let!(:tm) do
570
- tm = PG::TypeMapByMriType.new
571
- tm['T_FIXNUM'] = textenc_int
572
- tm['T_FLOAT'] = intenc_incrementer
573
- tm['T_ARRAY'] = PG::TextEncoder::Array.new elements_type: textenc_string
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
@@ -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.pre20141017160319
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
- MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQwwCgYDVQQDDANnZWQx
15
- GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
16
- HhcNMTQwMzE5MDQzNTI2WhcNMTUwMzE5MDQzNTI2WjA+MQwwCgYDVQQDDANnZWQx
17
- GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
18
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDb92mkyYwuGBg1oRxt2tkH
19
- +Uo3LAsaL/APBfSLzy8o3+B3AUHKCjMUaVeBoZdWtMHB75X3VQlvXfZMyBxj59Vo
20
- cDthr3zdao4HnyrzAIQf7BO5Y8KBwVD+yyXCD/N65TTwqsQnO3ie7U5/9ut1rnNr
21
- OkOzAscMwkfQxBkXDzjvAWa6UF4c5c9kR/T79iA21kDx9+bUMentU59aCJtUcbxa
22
- 7kcKJhPEYsk4OdxR9q2dphNMFDQsIdRO8rywX5FRHvcb+qnXC17RvxLHtOjysPtp
23
- EWsYoZMxyCDJpUqbwoeiM+tAHoz2ABMv3Ahie3Qeb6+MZNAtMmaWfBx3dg2u+/WN
24
- A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EAGB8yFoPC0GqiOHQsdHxQV3P3c2OZqG+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-10-17 00:00:00.000000000 Z
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