pg_data_encoder 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,9 +70,15 @@ module PgDataEncoder
70
70
 
71
71
  case field
72
72
  when Integer
73
- buf = [field].pack("N")
74
- io.write([buf.bytesize].pack("N"))
75
- io.write(buf)
73
+ if @options[:column_types] && @options[:column_types][index] == :bigint
74
+ io.write([8].pack("N"))
75
+ c = [field].pack('Q>')
76
+ io.write(c)
77
+ else
78
+ buf = [field].pack("N")
79
+ io.write([buf.bytesize].pack("N"))
80
+ io.write(buf)
81
+ end
76
82
  when Float
77
83
  buf = [field].pack("G")
78
84
  io.write([buf.bytesize].pack("N"))
@@ -92,6 +98,10 @@ module PgDataEncoder
92
98
  io.write([16].pack("N"))
93
99
  c = [field.gsub(/-/, "")].pack('H*')
94
100
  io.write(c)
101
+ elsif @options[:column_types] && @options[:column_types][index] == :bigint
102
+ io.write([8].pack("N"))
103
+ c = [field.to_i].pack('Q>')
104
+ io.write(c)
95
105
  else
96
106
  buf = field.encode("UTF-8")
97
107
  io.write([buf.bytesize].pack("N"))
@@ -1,3 +1,3 @@
1
1
  module PgDataEncoder
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
Binary file
Binary file
@@ -240,6 +240,19 @@ describe "generating data" do
240
240
  str.should == existing_data
241
241
  end
242
242
 
243
+ it 'should encode null uuid correctly from tempfile' do
244
+ encoder = PgDataEncoder::EncodeForCopy.new(:use_tempfile => true, column_types: {1 => :uuid})
245
+ encoder.add ['before2', nil, nil, 123423423]
246
+ encoder.close
247
+ io = encoder.get_io
248
+ existing_data = filedata("empty_uuid.dat")
249
+ str = io.read
250
+ io.class.name.should == "Tempfile"
251
+ str.force_encoding("ASCII-8BIT")
252
+ #File.open("spec/fixtures/output.dat", "w:ASCII-8BIT") {|out| out.write(str) }
253
+ str.should == existing_data
254
+ end
255
+
243
256
 
244
257
  it 'should encode uuid correctly from tempfile' do
245
258
  encoder = PgDataEncoder::EncodeForCopy.new(:use_tempfile => true, column_types: {0 => :uuid})
@@ -267,4 +280,31 @@ describe "generating data" do
267
280
  str.force_encoding("ASCII-8BIT")
268
281
  str.should == existing_data
269
282
  end
283
+
284
+ it 'should encode bigint as int correctly from tempfile' do
285
+ encoder = PgDataEncoder::EncodeForCopy.new(:use_tempfile => true, column_types: {0 => :bigint})
286
+ encoder.add [23372036854775808, 'test']
287
+ encoder.close
288
+ io = encoder.get_io
289
+ existing_data = filedata("bigint.dat")
290
+ str = io.read
291
+ io.class.name.should == "Tempfile"
292
+ str.force_encoding("ASCII-8BIT")
293
+ #File.open("spec/fixtures/output.dat", "w:ASCII-8BIT") {|out| out.write(str) }
294
+ str.should == existing_data
295
+ end
296
+
297
+ it 'should encode bigint correctly from tempfile' do
298
+ encoder = PgDataEncoder::EncodeForCopy.new(:use_tempfile => true, column_types: {0 => :bigint})
299
+ encoder.add ["23372036854775808", 'test']
300
+ encoder.close
301
+ io = encoder.get_io
302
+ existing_data = filedata("bigint.dat")
303
+ str = io.read
304
+ io.class.name.should == "Tempfile"
305
+ str.force_encoding("ASCII-8BIT")
306
+ #File.open("spec/fixtures/output.dat", "w:ASCII-8BIT") {|out| out.write(str) }
307
+ str.should == existing_data
308
+ end
309
+
270
310
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_data_encoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-07 00:00:00.000000000 Z
12
+ date: 2014-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -72,9 +72,11 @@ files:
72
72
  - spec/fixtures/array_with_two2.dat
73
73
  - spec/fixtures/big_str_array.dat
74
74
  - spec/fixtures/big_str_array2.dat
75
+ - spec/fixtures/bigint.dat
75
76
  - spec/fixtures/date.dat
76
77
  - spec/fixtures/date2.dat
77
78
  - spec/fixtures/date2000.dat
79
+ - spec/fixtures/empty_uuid.dat
78
80
  - spec/fixtures/falseclass.dat
79
81
  - spec/fixtures/float.dat
80
82
  - spec/fixtures/hstore_utf8.dat
@@ -128,9 +130,11 @@ test_files:
128
130
  - spec/fixtures/array_with_two2.dat
129
131
  - spec/fixtures/big_str_array.dat
130
132
  - spec/fixtures/big_str_array2.dat
133
+ - spec/fixtures/bigint.dat
131
134
  - spec/fixtures/date.dat
132
135
  - spec/fixtures/date2.dat
133
136
  - spec/fixtures/date2000.dat
137
+ - spec/fixtures/empty_uuid.dat
134
138
  - spec/fixtures/falseclass.dat
135
139
  - spec/fixtures/float.dat
136
140
  - spec/fixtures/hstore_utf8.dat