pg 0.17.1 → 0.18.4
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
- checksums.yaml.gz.sig +0 -0
- data/ChangeLog +2407 -2
- data/History.rdoc +68 -0
- data/Manifest.txt +29 -1
- data/README-Windows.rdoc +15 -26
- data/README.rdoc +52 -2
- data/Rakefile +56 -18
- data/Rakefile.cross +77 -49
- data/ext/extconf.rb +33 -26
- data/ext/pg.c +142 -21
- data/ext/pg.h +242 -6
- data/ext/pg_binary_decoder.c +162 -0
- data/ext/pg_binary_encoder.c +162 -0
- data/ext/pg_coder.c +479 -0
- data/ext/pg_connection.c +858 -553
- data/ext/pg_copy_coder.c +561 -0
- data/ext/pg_errors.c +6 -0
- data/ext/pg_result.c +479 -128
- data/ext/pg_text_decoder.c +421 -0
- data/ext/pg_text_encoder.c +663 -0
- data/ext/pg_type_map.c +159 -0
- data/ext/pg_type_map_all_strings.c +116 -0
- data/ext/pg_type_map_by_class.c +239 -0
- data/ext/pg_type_map_by_column.c +312 -0
- data/ext/pg_type_map_by_mri_type.c +284 -0
- data/ext/pg_type_map_by_oid.c +355 -0
- data/ext/pg_type_map_in_ruby.c +299 -0
- data/ext/util.c +149 -0
- data/ext/util.h +65 -0
- data/lib/pg/basic_type_mapping.rb +399 -0
- data/lib/pg/coder.rb +83 -0
- data/lib/pg/connection.rb +81 -29
- data/lib/pg/result.rb +13 -3
- data/lib/pg/text_decoder.rb +44 -0
- data/lib/pg/text_encoder.rb +27 -0
- data/lib/pg/type_map_by_column.rb +15 -0
- data/lib/pg.rb +12 -2
- data/spec/{lib/helpers.rb → helpers.rb} +101 -39
- data/spec/pg/basic_type_mapping_spec.rb +251 -0
- data/spec/pg/connection_spec.rb +516 -218
- data/spec/pg/result_spec.rb +216 -112
- data/spec/pg/type_map_by_class_spec.rb +138 -0
- data/spec/pg/type_map_by_column_spec.rb +222 -0
- data/spec/pg/type_map_by_mri_type_spec.rb +136 -0
- data/spec/pg/type_map_by_oid_spec.rb +149 -0
- data/spec/pg/type_map_in_ruby_spec.rb +164 -0
- data/spec/pg/type_map_spec.rb +22 -0
- data/spec/pg/type_spec.rb +697 -0
- data/spec/pg_spec.rb +24 -18
- data.tar.gz.sig +0 -0
- metadata +111 -45
- metadata.gz.sig +0 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require_relative '../helpers'
|
5
|
+
|
6
|
+
require 'pg'
|
7
|
+
|
8
|
+
|
9
|
+
describe PG::TypeMapInRuby do
|
10
|
+
|
11
|
+
context "result values" do
|
12
|
+
it "should be usable non-derived" do
|
13
|
+
tm = PG::TypeMapInRuby.new
|
14
|
+
res = @conn.exec("select 5").map_types!(tm)
|
15
|
+
expect( res.getvalue(0,0) ).to eq( "5" )
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should call derived result mapping methods" do
|
19
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
20
|
+
attr_reader :fit_to_result_args
|
21
|
+
|
22
|
+
def fit_to_result(*args)
|
23
|
+
@fit_to_result_args = args
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def typecast_result_value(*args)
|
28
|
+
[args, super]
|
29
|
+
end
|
30
|
+
end.new
|
31
|
+
|
32
|
+
res = @conn.exec("select 5,6").map_types!(tm)
|
33
|
+
expect( res.getvalue(0,1) ).to eq( [[res, 0, 1], "6"] )
|
34
|
+
expect( tm.fit_to_result_args ).to eq( [res] )
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should accept only a type map object from fit_to_result" do
|
38
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
39
|
+
def fit_to_result(*args)
|
40
|
+
:invalid
|
41
|
+
end
|
42
|
+
end.new
|
43
|
+
|
44
|
+
res = @conn.exec("select 5,6")
|
45
|
+
expect{ res.map_types!(tm) }.to raise_error(TypeError, /kind of PG::TypeMap/)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "query bind params" do
|
50
|
+
it "should be usable non-derived" do
|
51
|
+
tm = PG::TypeMapInRuby.new
|
52
|
+
res = @conn.exec_params("select $1::int, $2::text", [5, 6], 0, tm)
|
53
|
+
expect( res.values ).to eq( [["5", "6"]] )
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should call derived param mapping methods" do
|
57
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
58
|
+
attr_reader :fit_to_query_args
|
59
|
+
attr_reader :typecast_query_param_args
|
60
|
+
|
61
|
+
def fit_to_query(params)
|
62
|
+
@fit_to_query_args = params
|
63
|
+
@typecast_query_param_args = []
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def typecast_query_param(*args)
|
68
|
+
@typecast_query_param_args << [args, super]
|
69
|
+
PG::TextEncoder::Integer.new name: 'INT4', oid: 23
|
70
|
+
end
|
71
|
+
end.new
|
72
|
+
|
73
|
+
res = @conn.exec_params("select $1, $2", [5, 6], 0, tm)
|
74
|
+
expect( res.ftype(0) ).to eq( 23 )
|
75
|
+
expect( tm.fit_to_query_args ).to eq( [5, 6] )
|
76
|
+
expect( tm.typecast_query_param_args ).to eq( [[[5, 0], nil], [[6, 1], nil]] )
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "put_copy_data" do
|
81
|
+
it "should be usable non-derived" do
|
82
|
+
tm = PG::TypeMapInRuby.new
|
83
|
+
ce = PG::TextEncoder::CopyRow.new type_map: tm
|
84
|
+
res = ce.encode([5, 6])
|
85
|
+
expect( res ).to eq( "5\t6\n" )
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should call derived data mapping methods" do
|
89
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
90
|
+
attr_reader :fit_to_query_args
|
91
|
+
attr_reader :typecast_query_param_args
|
92
|
+
|
93
|
+
def fit_to_query(params)
|
94
|
+
@fit_to_query_args = params
|
95
|
+
@typecast_query_param_args = []
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def typecast_query_param(*args)
|
100
|
+
@typecast_query_param_args << [args, super]
|
101
|
+
PG::TextEncoder::Integer.new name: 'INT4', oid: 23
|
102
|
+
end
|
103
|
+
end.new
|
104
|
+
|
105
|
+
ce = PG::TextEncoder::CopyRow.new type_map: tm
|
106
|
+
res = ce.encode([5, 6])
|
107
|
+
expect( res ).to eq( "5\t6\n" )
|
108
|
+
expect( tm.fit_to_query_args ).to eq( [5, 6] )
|
109
|
+
expect( tm.typecast_query_param_args ).to eq( [[[5, 0], nil], [[6, 1], nil]] )
|
110
|
+
end
|
111
|
+
|
112
|
+
it "shouldn't accept invalid return from typecast_query_param" do
|
113
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
114
|
+
def typecast_query_param(*args)
|
115
|
+
:invalid
|
116
|
+
end
|
117
|
+
end.new
|
118
|
+
|
119
|
+
ce = PG::TextEncoder::CopyRow.new type_map: tm
|
120
|
+
expect{ ce.encode([5, 6]) }.to raise_error(TypeError, /nil or kind of PG::Coder/)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "get_copy_data" do
|
125
|
+
it "should be usable non-derived" do
|
126
|
+
tm = PG::TypeMapInRuby.new
|
127
|
+
ce = PG::TextDecoder::CopyRow.new type_map: tm
|
128
|
+
res = ce.decode("5\t6\n")
|
129
|
+
expect( res ).to eq( ["5", "6"] )
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should call derived data mapping methods" do
|
133
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
134
|
+
attr_reader :fit_to_copy_get_args
|
135
|
+
|
136
|
+
def fit_to_copy_get(*args)
|
137
|
+
@fit_to_copy_get_args = args
|
138
|
+
0
|
139
|
+
end
|
140
|
+
|
141
|
+
def typecast_copy_get(field_str, fieldno, format, enc)
|
142
|
+
[field_str, fieldno, format, enc, super]
|
143
|
+
end
|
144
|
+
end.new
|
145
|
+
|
146
|
+
ce = PG::TextDecoder::CopyRow.new type_map: tm
|
147
|
+
res = ce.decode("5\t6\n")
|
148
|
+
expect( tm.fit_to_copy_get_args ).to eq( [] )
|
149
|
+
expect( res ).to eq( [["5", 0, 0, Encoding::UTF_8, "5"], ["6", 1, 0, Encoding::UTF_8, "6"]] )
|
150
|
+
end
|
151
|
+
|
152
|
+
it "shouldn't accept invalid return from fit_to_copy_get" do
|
153
|
+
tm = Class.new(PG::TypeMapInRuby) do
|
154
|
+
def fit_to_copy_get
|
155
|
+
:invalid
|
156
|
+
end
|
157
|
+
end.new
|
158
|
+
|
159
|
+
ce = PG::TextDecoder::CopyRow.new type_map: tm
|
160
|
+
expect{ ce.decode("5\t6\n") }.to raise_error(TypeError, /kind of Integer/)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require_relative '../helpers'
|
5
|
+
|
6
|
+
require 'pg'
|
7
|
+
|
8
|
+
|
9
|
+
describe PG::TypeMap do
|
10
|
+
let!(:tm){ PG::TypeMap.new }
|
11
|
+
|
12
|
+
it "should raise an error when used for param type casts" do
|
13
|
+
expect{
|
14
|
+
@conn.exec_params( "SELECT $1", [5], 0, tm )
|
15
|
+
}.to raise_error(NotImplementedError, /not suitable to map query params/)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise an error when used for result type casts" do
|
19
|
+
res = @conn.exec( "SELECT 1" )
|
20
|
+
expect{ res.map_types!(tm) }.to raise_error(NotImplementedError, /not suitable to map result values/)
|
21
|
+
end
|
22
|
+
end
|