pg 0.15.1 → 0.16.0
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 +1 -3
- data/ChangeLog +361 -59
- data/History.rdoc +31 -4
- data/Manifest.txt +4 -0
- data/Rakefile +30 -10
- data/ext/errorcodes.def +931 -0
- data/ext/errorcodes.rb +45 -0
- data/ext/errorcodes.txt +463 -0
- data/ext/extconf.rb +11 -5
- data/ext/gvl_wrappers.c +6 -0
- data/ext/gvl_wrappers.h +47 -21
- data/ext/pg.c +30 -10
- data/ext/pg.h +30 -0
- data/ext/pg_connection.c +105 -45
- data/ext/pg_errors.c +89 -0
- data/ext/pg_result.c +49 -68
- data/lib/pg.rb +2 -2
- data/spec/lib/helpers.rb +11 -2
- data/spec/pg/connection_spec.rb +113 -8
- data/spec/pg/result_spec.rb +69 -2
- data/spec/pg_spec.rb +13 -0
- metadata +11 -5
- metadata.gz.sig +0 -0
data/spec/pg/result_spec.rb
CHANGED
@@ -73,15 +73,30 @@ describe PG::Result do
|
|
73
73
|
should == 'relation "nonexistant_table" does not exist'
|
74
74
|
result.error_field( PG::PG_DIAG_MESSAGE_DETAIL ).should be_nil()
|
75
75
|
result.error_field( PG::PG_DIAG_MESSAGE_HINT ).should be_nil()
|
76
|
-
|
77
|
-
result.error_field( PG::PG_DIAG_STATEMENT_POSITION ).should == statement_pos
|
76
|
+
result.error_field( PG::PG_DIAG_STATEMENT_POSITION ).should == '15'
|
78
77
|
result.error_field( PG::PG_DIAG_INTERNAL_POSITION ).should be_nil()
|
79
78
|
result.error_field( PG::PG_DIAG_INTERNAL_QUERY ).should be_nil()
|
80
79
|
result.error_field( PG::PG_DIAG_CONTEXT ).should be_nil()
|
81
80
|
result.error_field( PG::PG_DIAG_SOURCE_FILE ).should =~ /parse_relation\.c$|namespace\.c$/
|
82
81
|
result.error_field( PG::PG_DIAG_SOURCE_LINE ).should =~ /^\d+$/
|
83
82
|
result.error_field( PG::PG_DIAG_SOURCE_FUNCTION ).should =~ /^parserOpenTable$|^RangeVarGetRelid$/
|
83
|
+
end
|
84
84
|
|
85
|
+
it "encapsulates database object names for integrity constraint violations", :postgresql_93 do
|
86
|
+
@conn.exec( "CREATE TABLE integrity (id SERIAL PRIMARY KEY)" )
|
87
|
+
exception = nil
|
88
|
+
begin
|
89
|
+
@conn.exec( "INSERT INTO integrity VALUES (NULL)" )
|
90
|
+
rescue PGError => err
|
91
|
+
exception = err
|
92
|
+
end
|
93
|
+
result = exception.result
|
94
|
+
|
95
|
+
result.error_field( PG::PG_DIAG_SCHEMA_NAME ).should == 'public'
|
96
|
+
result.error_field( PG::PG_DIAG_TABLE_NAME ).should == 'integrity'
|
97
|
+
result.error_field( PG::PG_DIAG_COLUMN_NAME ).should == 'id'
|
98
|
+
result.error_field( PG::PG_DIAG_DATATYPE_NAME ).should be_nil
|
99
|
+
result.error_field( PG::PG_DIAG_CONSTRAINT_NAME ).should be_nil
|
85
100
|
end
|
86
101
|
|
87
102
|
it "should detect division by zero as SQLSTATE 22012" do
|
@@ -275,4 +290,56 @@ describe PG::Result do
|
|
275
290
|
expect{ res.field_values( '' ) }.to raise_error(IndexError)
|
276
291
|
expect{ res.field_values( :x ) }.to raise_error(TypeError)
|
277
292
|
end
|
293
|
+
|
294
|
+
it "should raise a proper exception for a nonexistant table" do
|
295
|
+
expect {
|
296
|
+
@conn.exec( "SELECT * FROM nonexistant_table" )
|
297
|
+
}.to raise_error( PG::UndefinedTable, /relation "nonexistant_table" does not exist/ )
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should raise a more generic exception for an unknown SQLSTATE" do
|
301
|
+
old_error = PG::ERROR_CLASSES.delete('42P01')
|
302
|
+
begin
|
303
|
+
expect {
|
304
|
+
@conn.exec( "SELECT * FROM nonexistant_table" )
|
305
|
+
}.to raise_error{|error|
|
306
|
+
error.should be_an_instance_of(PG::SyntaxErrorOrAccessRuleViolation)
|
307
|
+
error.to_s.should match(/relation "nonexistant_table" does not exist/)
|
308
|
+
}
|
309
|
+
ensure
|
310
|
+
PG::ERROR_CLASSES['42P01'] = old_error
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should raise a ServerError for an unknown SQLSTATE class" do
|
315
|
+
old_error1 = PG::ERROR_CLASSES.delete('42P01')
|
316
|
+
old_error2 = PG::ERROR_CLASSES.delete('42')
|
317
|
+
begin
|
318
|
+
expect {
|
319
|
+
@conn.exec( "SELECT * FROM nonexistant_table" )
|
320
|
+
}.to raise_error{|error|
|
321
|
+
error.should be_an_instance_of(PG::ServerError)
|
322
|
+
error.to_s.should match(/relation "nonexistant_table" does not exist/)
|
323
|
+
}
|
324
|
+
ensure
|
325
|
+
PG::ERROR_CLASSES['42P01'] = old_error1
|
326
|
+
PG::ERROR_CLASSES['42'] = old_error2
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should raise a proper exception for a nonexistant schema" do
|
331
|
+
expect {
|
332
|
+
@conn.exec( "DROP SCHEMA nonexistant_schema" )
|
333
|
+
}.to raise_error( PG::InvalidSchemaName, /schema "nonexistant_schema" does not exist/ )
|
334
|
+
end
|
335
|
+
|
336
|
+
it "the raised result should be nil in case of a connection error" do
|
337
|
+
c = PGconn.connect_start( '127.0.0.1', 54320, "", "", "me", "xxxx", "somedb" )
|
338
|
+
expect {
|
339
|
+
c.exec "select 1"
|
340
|
+
}.to raise_error{|error|
|
341
|
+
error.should be_an_instance_of(PG::UnableToSend)
|
342
|
+
error.result.should == nil
|
343
|
+
}
|
344
|
+
end
|
278
345
|
end
|
data/spec/pg_spec.rb
CHANGED
@@ -27,5 +27,18 @@ describe PG do
|
|
27
27
|
PG.should be_threadsafe()
|
28
28
|
end
|
29
29
|
|
30
|
+
it "does have hierarchical error classes" do
|
31
|
+
PG::UndefinedTable.ancestors[0,4].should == [
|
32
|
+
PG::UndefinedTable,
|
33
|
+
PG::SyntaxErrorOrAccessRuleViolation,
|
34
|
+
PG::ServerError,
|
35
|
+
PG::Error]
|
36
|
+
|
37
|
+
PG::InvalidSchemaName.ancestors[0,3].should == [
|
38
|
+
PG::InvalidSchemaName,
|
39
|
+
PG::ServerError,
|
40
|
+
PG::Error]
|
41
|
+
end
|
42
|
+
|
30
43
|
end
|
31
44
|
|
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.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
|
31
31
|
/YSusaiDXHKU2O3Akc3htA==
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2013-
|
33
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: hoe-mercurial
|
@@ -66,14 +66,14 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '4.0'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '4.0'
|
77
77
|
- !ruby/object:Gem::Dependency
|
78
78
|
name: rake-compiler
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,11 +149,13 @@ extra_rdoc_files:
|
|
149
149
|
- README-Windows.rdoc
|
150
150
|
- README.ja.rdoc
|
151
151
|
- README.rdoc
|
152
|
+
- ext/errorcodes.txt
|
152
153
|
- POSTGRES
|
153
154
|
- LICENSE
|
154
155
|
- ext/gvl_wrappers.c
|
155
156
|
- ext/pg.c
|
156
157
|
- ext/pg_connection.c
|
158
|
+
- ext/pg_errors.c
|
157
159
|
- ext/pg_result.c
|
158
160
|
files:
|
159
161
|
- .gemtest
|
@@ -170,12 +172,16 @@ files:
|
|
170
172
|
- README.rdoc
|
171
173
|
- Rakefile
|
172
174
|
- Rakefile.cross
|
175
|
+
- ext/errorcodes.def
|
176
|
+
- ext/errorcodes.rb
|
177
|
+
- ext/errorcodes.txt
|
173
178
|
- ext/extconf.rb
|
174
179
|
- ext/gvl_wrappers.c
|
175
180
|
- ext/gvl_wrappers.h
|
176
181
|
- ext/pg.c
|
177
182
|
- ext/pg.h
|
178
183
|
- ext/pg_connection.c
|
184
|
+
- ext/pg_errors.c
|
179
185
|
- ext/pg_result.c
|
180
186
|
- ext/vc/pg.sln
|
181
187
|
- ext/vc/pg_18/pg.vcproj
|
@@ -237,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
243
|
version: '0'
|
238
244
|
requirements: []
|
239
245
|
rubyforge_project: pg
|
240
|
-
rubygems_version: 2.0.
|
246
|
+
rubygems_version: 2.0.5
|
241
247
|
signing_key:
|
242
248
|
specification_version: 4
|
243
249
|
summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
|
metadata.gz.sig
CHANGED
Binary file
|