pod4 0.8.1 → 0.8.2
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 +4 -4
- data/Gemfile +1 -1
- data/lib/pod4/pg_interface.rb +20 -6
- data/lib/pod4/version.rb +1 -1
- data/spec/jruby/sequel_interface_jdbc_pg_spec.rb +12 -0
- data/spec/mri/pg_interface_spec.rb +12 -0
- data/spec/mri/sequel_interface_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c33db37048b310a24eb4effcca5a228b7b62fda
|
4
|
+
data.tar.gz: 2c34a1c066c77b8d5d033f9ec61950addcd15105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e0c5abefdd694821087dd05ccb60198c3090aba282973390f9add4784f4e780783e91c4e6eb86c29e2fbca14deb2f092b6ef81e1416b3c068f515b03cf4d2f4
|
7
|
+
data.tar.gz: f96672068c235b9297d60a885f5e7c11be57f1262d8e779a5ea2d8e103e8ecfbf6f5a4efd3a6d6fd0eb04cd494922f79d69472a8906563ecfaad3f65ffe67859
|
data/Gemfile
CHANGED
data/lib/pod4/pg_interface.rb
CHANGED
@@ -257,7 +257,6 @@ module Pod4
|
|
257
257
|
end
|
258
258
|
|
259
259
|
@client.cancel
|
260
|
-
|
261
260
|
rows
|
262
261
|
|
263
262
|
rescue => e
|
@@ -418,7 +417,6 @@ module Pod4
|
|
418
417
|
end
|
419
418
|
|
420
419
|
|
421
|
-
|
422
420
|
##
|
423
421
|
# Cast a query row
|
424
422
|
#
|
@@ -428,7 +426,6 @@ module Pod4
|
|
428
426
|
# Also, for the pg_jruby gem, type mapping doesn't work at all?
|
429
427
|
#
|
430
428
|
def cast_row_fudge(row, oids)
|
431
|
-
lBool =->(s) { s.to_i = 1 || s.upcase == 'TRUE' }
|
432
429
|
lFloat =->(s) { Float(s) rescue s }
|
433
430
|
lInt =->(s) { Integer(s,10) rescue s }
|
434
431
|
lTime =->(s) { Time.parse(s) rescue s }
|
@@ -447,7 +444,7 @@ module Pod4
|
|
447
444
|
when oid == 790 then lBigDec.(v[1..-1]) # "£1.23"
|
448
445
|
when oid == 1082 then lDate.(v)
|
449
446
|
|
450
|
-
when [16, 1560].include?(oid) then
|
447
|
+
when [16, 1560].include?(oid) then cast_bool(v)
|
451
448
|
when [700, 701].include?(oid) then lFloat.(v)
|
452
449
|
when [20, 21, 23].include?(oid) then lInt.(v)
|
453
450
|
when [1114, 1184].include?(oid) then lTime.(v)
|
@@ -459,6 +456,23 @@ module Pod4
|
|
459
456
|
|
460
457
|
end
|
461
458
|
|
459
|
+
|
460
|
+
##
|
461
|
+
# Given a value from the database which supposedly represents a boolean ... return one.
|
462
|
+
# It might of course be NULL/nil; that's allowed, too.
|
463
|
+
#
|
464
|
+
def cast_bool(val)
|
465
|
+
if val.nil?
|
466
|
+
nil
|
467
|
+
elsif val.is_a? String
|
468
|
+
%w|T TRUE|.include?(val.to_s.upcase)
|
469
|
+
elsif val.respond_to?(:to_i) # String responds to to_i, remember
|
470
|
+
val.to_i == 1
|
471
|
+
else
|
472
|
+
nil
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
462
476
|
|
463
477
|
def read_or_die(id)
|
464
478
|
raise CantContinue, "'No record found with ID '#{id}'" if read(id).empty?
|
@@ -467,8 +481,8 @@ module Pod4
|
|
467
481
|
|
468
482
|
def parse_for_params(sql, vals)
|
469
483
|
new_params = sql.scan("%s").map.with_index{|e,i| "$#{i + 1}" }
|
470
|
-
new_vals = vals.map{|v| v ? quote(v, nil).to_s
|
471
|
-
|
484
|
+
new_vals = vals.map{|v| v.nil? ? nil : quote(v, nil).to_s }
|
485
|
+
|
472
486
|
[ sql_subst(sql, *new_params), new_vals ]
|
473
487
|
end
|
474
488
|
|
data/lib/pod4/version.rb
CHANGED
@@ -66,6 +66,7 @@ describe "SequelInterface (JDBC/Pg)" do
|
|
66
66
|
day: Date.parse("2016-01-01"),
|
67
67
|
timestamp: Time.parse('2015-01-01 12:11'),
|
68
68
|
qty: BigDecimal.new("1.24"),
|
69
|
+
flag: true,
|
69
70
|
price: nil }
|
70
71
|
|
71
72
|
d << { name: 'Fred',
|
@@ -73,6 +74,7 @@ describe "SequelInterface (JDBC/Pg)" do
|
|
73
74
|
day: Date.parse("2016-02-02"),
|
74
75
|
timestamp: Time.parse('2015-01-02 12:22'),
|
75
76
|
qty: BigDecimal.new("2.35"),
|
77
|
+
flag: false,
|
76
78
|
price: nil }
|
77
79
|
|
78
80
|
d << { name: 'Betty',
|
@@ -80,6 +82,7 @@ describe "SequelInterface (JDBC/Pg)" do
|
|
80
82
|
day: Date.parse("2016-03-03"),
|
81
83
|
timestamp: Time.parse('2015-01-03 12:33'),
|
82
84
|
qty: BigDecimal.new("3.46"),
|
85
|
+
flag: nil,
|
83
86
|
price: nil }
|
84
87
|
|
85
88
|
d
|
@@ -108,6 +111,7 @@ describe "SequelInterface (JDBC/Pg)" do
|
|
108
111
|
day date null,
|
109
112
|
timestamp timestamp null,
|
110
113
|
price money null,
|
114
|
+
flag boolean null,
|
111
115
|
qty numeric null );
|
112
116
|
|
113
117
|
create table product (
|
@@ -266,6 +270,14 @@ describe "SequelInterface (JDBC/Pg)" do
|
|
266
270
|
expect( price ).to eq dibble[:price]
|
267
271
|
end
|
268
272
|
|
273
|
+
it 'returns boolean fields as boolean' do
|
274
|
+
[1,2,3].each do |i|
|
275
|
+
flag = interface.read(i).>>.flag
|
276
|
+
expect( [true, false, nil].include? flag ).to be true
|
277
|
+
expect( flag ).to be data[i - 1][:flag]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
269
281
|
it 'shouldn\'t have a problem with non-integer keys' do
|
270
282
|
# this is a 100% overlap with the create test above...
|
271
283
|
fill_product_data(prod_interface)
|
@@ -58,6 +58,7 @@ describe "PgInterface" do
|
|
58
58
|
day date null,
|
59
59
|
timestamp timestamp null,
|
60
60
|
price money null,
|
61
|
+
flag boolean null,
|
61
62
|
qty numeric null );
|
62
63
|
|
63
64
|
create table product (
|
@@ -89,6 +90,7 @@ describe "PgInterface" do
|
|
89
90
|
day: Date.parse("2016-01-01"),
|
90
91
|
timestamp: Time.parse('2015-01-01 12:11'),
|
91
92
|
price: BigDecimal.new("1.24"),
|
93
|
+
flag: true,
|
92
94
|
qty: BigDecimal.new("1.25") }
|
93
95
|
|
94
96
|
@data << { name: 'Fred',
|
@@ -96,6 +98,7 @@ describe "PgInterface" do
|
|
96
98
|
day: Date.parse("2016-02-02"),
|
97
99
|
timestamp: Time.parse('2015-01-02 12:22'),
|
98
100
|
price: BigDecimal.new("2.35"),
|
101
|
+
flag: false,
|
99
102
|
qty: BigDecimal.new("2.36") }
|
100
103
|
|
101
104
|
@data << { name: 'Betty',
|
@@ -103,6 +106,7 @@ describe "PgInterface" do
|
|
103
106
|
day: Date.parse("2016-03-03"),
|
104
107
|
timestamp: Time.parse('2015-01-03 12:33'),
|
105
108
|
price: BigDecimal.new("3.46"),
|
109
|
+
flag: nil,
|
106
110
|
qty: BigDecimal.new("3.47") }
|
107
111
|
|
108
112
|
end
|
@@ -332,6 +336,14 @@ describe "PgInterface" do
|
|
332
336
|
expect( price ).to eq @data.first[:price]
|
333
337
|
end
|
334
338
|
|
339
|
+
it 'returns boolean fields as boolean' do
|
340
|
+
[1,2,3].each do |i|
|
341
|
+
flag = interface.read(i).>>.flag
|
342
|
+
expect( [true, false, nil].include? flag ).to be true
|
343
|
+
expect( flag ).to be @data[i - 1][:flag]
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
335
347
|
it 'shouldn\'t have a problem with non-integer keys' do
|
336
348
|
# this is a 100% overlap with the create test above...
|
337
349
|
fill_product_data(prod_interface)
|
@@ -53,18 +53,21 @@ describe "SequelInterface" do
|
|
53
53
|
level: 1.23,
|
54
54
|
day: Date.parse("2016-01-01"),
|
55
55
|
timestamp: Time.parse('2015-01-01 12:11'),
|
56
|
+
flag: true,
|
56
57
|
price: BigDecimal.new("1.24") }
|
57
58
|
|
58
59
|
d << { name: 'Fred',
|
59
60
|
level: 2.34,
|
60
61
|
day: Date.parse("2016-02-02"),
|
61
62
|
timestamp: Time.parse('2015-01-02 12:22'),
|
63
|
+
flag: false,
|
62
64
|
price: BigDecimal.new("2.35") }
|
63
65
|
|
64
66
|
d << { name: 'Betty',
|
65
67
|
level: 3.45,
|
66
68
|
day: Date.parse("2016-03-03"),
|
67
69
|
timestamp: Time.parse('2015-01-03 12:33'),
|
70
|
+
flag: nil,
|
68
71
|
price: BigDecimal.new("3.46") }
|
69
72
|
|
70
73
|
d
|
@@ -92,6 +95,7 @@ describe "SequelInterface" do
|
|
92
95
|
Float :level
|
93
96
|
Date :day
|
94
97
|
Time :timestamp
|
98
|
+
TrueClass :flag
|
95
99
|
BigDecimal :price, :size=>[10.2] # Sequel doesn't support money
|
96
100
|
end
|
97
101
|
|
@@ -123,6 +127,7 @@ describe "SequelInterface" do
|
|
123
127
|
Float :level
|
124
128
|
Date :day
|
125
129
|
Time :timestamp
|
130
|
+
TrueClass :flag
|
126
131
|
BigDecimal :price, :size=>[10.2]
|
127
132
|
end
|
128
133
|
|
@@ -324,6 +329,15 @@ describe "SequelInterface" do
|
|
324
329
|
expect( price ).to eq data.first[:price]
|
325
330
|
end
|
326
331
|
|
332
|
+
# Not sure how this passes since SQLite doesn't have a boolean class, but, Sequel handles it.
|
333
|
+
it 'returns boolean fields as boolean' do
|
334
|
+
[1,2,3].each do |i|
|
335
|
+
flag = interface.read(i).>>.flag
|
336
|
+
expect( [true, false, nil].include? flag ).to be true
|
337
|
+
expect( flag ).to be data[i - 1][:flag]
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
327
341
|
it 'shouldn\'t have a problem with non-integer keys' do
|
328
342
|
# this is a 100% overlap with the create test above...
|
329
343
|
fill_product_data(prod_interface)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pod4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devnull
|