pg-ct 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/BSD +23 -0
- data/ChangeLog +585 -0
- data/Contributors +30 -0
- data/GPL +340 -0
- data/LICENSE +58 -0
- data/README +68 -0
- data/README.OS_X +19 -0
- data/README.ja +183 -0
- data/README.windows +72 -0
- data/Rakefile +359 -0
- data/Rakefile.local +298 -0
- data/ext/compat.c +541 -0
- data/ext/compat.h +180 -0
- data/ext/extconf.rb +147 -0
- data/ext/pg.c +4307 -0
- data/ext/pg.h +49 -0
- data/lib/pg.rb +14 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/documentation.rb +123 -0
- data/rake/helpers.rb +502 -0
- data/rake/hg.rb +287 -0
- data/rake/manual.rb +787 -0
- data/rake/packaging.rb +129 -0
- data/rake/publishing.rb +341 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +668 -0
- data/rake/testing.rb +151 -0
- data/rake/verifytask.rb +64 -0
- data/spec/data/expected_trace.out +26 -0
- data/spec/data/random_binary_data +0 -0
- data/spec/lib/helpers.rb +236 -0
- data/spec/m17n_spec.rb +151 -0
- data/spec/pgconn_spec.rb +437 -0
- data/spec/pgresult_spec.rb +215 -0
- metadata +126 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
#!/usr/bin/env spec
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
BEGIN {
|
5
|
+
require 'pathname'
|
6
|
+
require 'rbconfig'
|
7
|
+
|
8
|
+
basedir = Pathname( __FILE__ ).dirname.parent
|
9
|
+
libdir = basedir + 'lib'
|
10
|
+
archlib = libdir + Config::CONFIG['sitearch']
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
13
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
14
|
+
$LOAD_PATH.unshift( archlib.to_s ) unless $LOAD_PATH.include?( archlib.to_s )
|
15
|
+
}
|
16
|
+
|
17
|
+
require 'rspec'
|
18
|
+
require 'spec/lib/helpers'
|
19
|
+
require 'pg'
|
20
|
+
|
21
|
+
describe PGresult do
|
22
|
+
include PgTestingHelpers
|
23
|
+
|
24
|
+
before( :all ) do
|
25
|
+
@conn = setup_testing_db( "PGresult" )
|
26
|
+
end
|
27
|
+
|
28
|
+
before( :each ) do
|
29
|
+
@conn.exec( 'BEGIN' )
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "should act as an array of hashes" do
|
34
|
+
res = @conn.exec("SELECT 1 AS a, 2 AS b")
|
35
|
+
res[0]['a'].should== '1'
|
36
|
+
res[0]['b'].should== '2'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should insert nil AS NULL and return NULL as nil" do
|
40
|
+
res = @conn.exec("SELECT $1::int AS n", [nil])
|
41
|
+
res[0]['n'].should == nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should detect division by zero as SQLSTATE 22012" do
|
45
|
+
sqlstate = nil
|
46
|
+
begin
|
47
|
+
res = @conn.exec("SELECT 1/0")
|
48
|
+
rescue PGError => e
|
49
|
+
sqlstate = e.result.result_error_field(
|
50
|
+
PGresult::PG_DIAG_SQLSTATE).to_i
|
51
|
+
end
|
52
|
+
sqlstate.should == 22012
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return the same bytes in binary format that are sent in binary format" do
|
56
|
+
binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
|
57
|
+
bytes = File.open(binary_file, 'rb').read
|
58
|
+
res = @conn.exec('VALUES ($1::bytea)',
|
59
|
+
[ { :value => bytes, :format => 1 } ], 1)
|
60
|
+
res[0]['column1'].should== bytes
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return the same bytes in binary format that are sent as inline text" do
|
64
|
+
binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
|
65
|
+
in_bytes = File.open(binary_file, 'rb').read
|
66
|
+
out_bytes = nil
|
67
|
+
@conn.exec("SET standard_conforming_strings=on")
|
68
|
+
res = @conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 1)
|
69
|
+
out_bytes = res[0]['column1']
|
70
|
+
out_bytes.should == in_bytes
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return the same bytes in text format that are sent in binary format" do
|
74
|
+
binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
|
75
|
+
bytes = File.open(binary_file, 'rb').read
|
76
|
+
res = @conn.exec('VALUES ($1::bytea)',
|
77
|
+
[ { :value => bytes, :format => 1 } ])
|
78
|
+
PGconn.unescape_bytea(res[0]['column1']).should== bytes
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return the same bytes in text format that are sent as inline text" do
|
82
|
+
binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
|
83
|
+
in_bytes = File.open(binary_file, 'rb').read
|
84
|
+
|
85
|
+
out_bytes = nil
|
86
|
+
@conn.exec("SET standard_conforming_strings=on")
|
87
|
+
res = @conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 0)
|
88
|
+
out_bytes = PGconn.unescape_bytea(res[0]['column1'])
|
89
|
+
out_bytes.should == in_bytes
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return the parameter type of the specified prepared statment parameter" do
|
93
|
+
query = 'SELECT * FROM pg_stat_activity WHERE user = $1::name AND current_query = $2::text'
|
94
|
+
@conn.prepare( 'queryfinder', query )
|
95
|
+
res = @conn.describe_prepared( 'queryfinder' )
|
96
|
+
|
97
|
+
@conn.exec( 'SELECT format_type($1, -1)', [res.paramtype(0)] ).getvalue( 0, 0 ).
|
98
|
+
should == 'name'
|
99
|
+
@conn.exec( 'SELECT format_type($1, -1)', [res.paramtype(1)] ).getvalue( 0, 0 ).
|
100
|
+
should == 'text'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should raise an exception when a negative index is given to #fformat" do
|
104
|
+
res = @conn.exec('SELECT * FROM pg_stat_activity')
|
105
|
+
expect {
|
106
|
+
res.fformat( -1 )
|
107
|
+
}.to raise_error( ArgumentError, /column number/i )
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should raise an exception when a negative index is given to #fmod" do
|
111
|
+
res = @conn.exec('SELECT * FROM pg_stat_activity')
|
112
|
+
expect {
|
113
|
+
res.fmod( -1 )
|
114
|
+
}.to raise_error( ArgumentError, /column number/i )
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise an exception when a negative index is given to #[]" do
|
118
|
+
res = @conn.exec('SELECT * FROM pg_stat_activity')
|
119
|
+
expect {
|
120
|
+
res[ -1 ]
|
121
|
+
}.to raise_error( IndexError, /-1 is out of range/i )
|
122
|
+
end
|
123
|
+
|
124
|
+
# PQfmod
|
125
|
+
it "can return the type modifier for a result column" do
|
126
|
+
@conn.exec( 'CREATE TABLE fmodtest ( foo varchar(33) )' )
|
127
|
+
res = @conn.exec( 'SELECT * FROM fmodtest' )
|
128
|
+
res.fmod( 0 ).should == 33 + 4 # Column length + varlena size (4)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should raise an exception when an invalid index is passed to PGresult#fmod" do
|
132
|
+
@conn.exec( 'CREATE TABLE fmodtest ( foo varchar(33) )' )
|
133
|
+
res = @conn.exec( 'SELECT * FROM fmodtest' )
|
134
|
+
expect { res.fmod(1) }.to raise_error( ArgumentError )
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should raise an exception when an invalid (negative) index is passed to PGresult#fmod" do
|
138
|
+
@conn.exec( 'CREATE TABLE fmodtest ( foo varchar(33) )' )
|
139
|
+
res = @conn.exec( 'SELECT * FROM fmodtest' )
|
140
|
+
expect { res.fmod(-11) }.to raise_error( ArgumentError )
|
141
|
+
end
|
142
|
+
|
143
|
+
it "shouldn't raise an exception when a valid index is passed to PGresult#fmod for a column with no typemod" do
|
144
|
+
@conn.exec( 'CREATE TABLE fmodtest ( foo text )' )
|
145
|
+
res = @conn.exec( 'SELECT * FROM fmodtest' )
|
146
|
+
res.fmod( 0 ).should == -1 # and it shouldn't raise an exception, either
|
147
|
+
end
|
148
|
+
|
149
|
+
# PQftable
|
150
|
+
it "can return the oid of the table from which a result column was fetched" do
|
151
|
+
@conn.exec( 'CREATE TABLE ftabletest ( foo text )' )
|
152
|
+
res = @conn.exec( 'SELECT * FROM ftabletest' )
|
153
|
+
|
154
|
+
res.ftable( 0 ).should == be_nonzero()
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should raise an exception when an invalid index is passed to PGresult#ftable" do
|
158
|
+
@conn.exec( 'CREATE TABLE ftabletest ( foo text )' )
|
159
|
+
res = @conn.exec( 'SELECT * FROM ftabletest' )
|
160
|
+
|
161
|
+
expect { res.ftable(18) }.to raise_error( ArgumentError )
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should raise an exception when an invalid (negative) index is passed to PGresult#ftable" do
|
165
|
+
@conn.exec( 'CREATE TABLE ftabletest ( foo text )' )
|
166
|
+
res = @conn.exec( 'SELECT * FROM ftabletest' )
|
167
|
+
|
168
|
+
expect { res.ftable(-2) }.to raise_error( ArgumentError )
|
169
|
+
end
|
170
|
+
|
171
|
+
it "shouldn't raise an exception when a valid index is passed to PGresult#ftable for a " +
|
172
|
+
"column with no corresponding table" do
|
173
|
+
@conn.exec( 'CREATE TABLE ftabletest ( foo text )' )
|
174
|
+
res = @conn.exec( 'SELECT foo, LENGTH(foo) as length FROM ftabletest' )
|
175
|
+
res.ftable( 1 ).should == PGresult::InvalidOid # and it shouldn't raise an exception, either
|
176
|
+
end
|
177
|
+
|
178
|
+
# PQftablecol
|
179
|
+
it "can return the column number (within its table) of a column in a result" do
|
180
|
+
@conn.exec( 'CREATE TABLE ftablecoltest ( foo text, bar numeric )' )
|
181
|
+
res = @conn.exec( 'SELECT * FROM ftablecoltest' )
|
182
|
+
|
183
|
+
res.ftablecol( 0 ).should == 1
|
184
|
+
res.ftablecol( 1 ).should == 2
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should raise an exception when an invalid index is passed to PGresult#ftablecol" do
|
188
|
+
@conn.exec( 'CREATE TABLE ftablecoltest ( foo text, bar numeric )' )
|
189
|
+
res = @conn.exec( 'SELECT * FROM ftablecoltest' )
|
190
|
+
|
191
|
+
expect { res.ftablecol(32) }.to raise_error( ArgumentError )
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should raise an exception when an invalid (negative) index is passed to PGresult#ftablecol" do
|
195
|
+
@conn.exec( 'CREATE TABLE ftablecoltest ( foo text, bar numeric )' )
|
196
|
+
res = @conn.exec( 'SELECT * FROM ftablecoltest' )
|
197
|
+
|
198
|
+
expect { res.ftablecol(-1) }.to raise_error( ArgumentError )
|
199
|
+
end
|
200
|
+
|
201
|
+
it "shouldn't raise an exception when a valid index is passed to PGresult#ftablecol for a " +
|
202
|
+
"column with no corresponding table" do
|
203
|
+
@conn.exec( 'CREATE TABLE ftablecoltest ( foo text )' )
|
204
|
+
res = @conn.exec( 'SELECT foo, LENGTH(foo) as length FROM ftablecoltest' )
|
205
|
+
res.ftablecol(1).should == 0 # and it shouldn't raise an exception, either
|
206
|
+
end
|
207
|
+
|
208
|
+
after( :each ) do
|
209
|
+
@conn.exec( 'ROLLBACK' )
|
210
|
+
end
|
211
|
+
|
212
|
+
after( :all ) do
|
213
|
+
teardown_testing_db( @conn )
|
214
|
+
end
|
215
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pg-ct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 10
|
8
|
+
- 0
|
9
|
+
version: 0.10.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jeff Davis
|
13
|
+
- Michael Granger
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-29 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |-
|
23
|
+
This is the extension library to access a PostgreSQL database from Ruby.
|
24
|
+
This library works with PostgreSQL 7.4 and later.
|
25
|
+
email:
|
26
|
+
- ruby-pg@j-davis.com
|
27
|
+
- ged@FaerieMUD.org
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions:
|
31
|
+
- ext/extconf.rb
|
32
|
+
extra_rdoc_files:
|
33
|
+
- ChangeLog
|
34
|
+
- README
|
35
|
+
- README.ja
|
36
|
+
- README.OS_X
|
37
|
+
- README.windows
|
38
|
+
- LICENSE
|
39
|
+
files:
|
40
|
+
- Rakefile
|
41
|
+
- ChangeLog
|
42
|
+
- README
|
43
|
+
- README.ja
|
44
|
+
- README.OS_X
|
45
|
+
- README.windows
|
46
|
+
- LICENSE
|
47
|
+
- spec/m17n_spec.rb
|
48
|
+
- spec/pgconn_spec.rb
|
49
|
+
- spec/pgresult_spec.rb
|
50
|
+
- spec/lib/helpers.rb
|
51
|
+
- lib/pg.rb
|
52
|
+
- ext/compat.c
|
53
|
+
- ext/pg.c
|
54
|
+
- ext/compat.h
|
55
|
+
- ext/pg.h
|
56
|
+
- ext/extconf.rb
|
57
|
+
- rake/191_compat.rb
|
58
|
+
- rake/dependencies.rb
|
59
|
+
- rake/documentation.rb
|
60
|
+
- rake/helpers.rb
|
61
|
+
- rake/hg.rb
|
62
|
+
- rake/manual.rb
|
63
|
+
- rake/packaging.rb
|
64
|
+
- rake/publishing.rb
|
65
|
+
- rake/style.rb
|
66
|
+
- rake/svn.rb
|
67
|
+
- rake/testing.rb
|
68
|
+
- rake/verifytask.rb
|
69
|
+
- ./README.ja
|
70
|
+
- ./README.OS_X
|
71
|
+
- ./README.windows
|
72
|
+
- ./GPL
|
73
|
+
- ./BSD
|
74
|
+
- ./Contributors
|
75
|
+
- Rakefile.local
|
76
|
+
- spec/data/expected_trace.out
|
77
|
+
- spec/data/random_binary_data
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://bitbucket.org/ged/ruby-pg/
|
80
|
+
licenses:
|
81
|
+
- Ruby
|
82
|
+
- GPL
|
83
|
+
- BSD
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options:
|
86
|
+
- --tab-width=4
|
87
|
+
- --show-hash
|
88
|
+
- --include
|
89
|
+
- .
|
90
|
+
- --main=README
|
91
|
+
- --title=pg-ct
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
- ext
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 1
|
102
|
+
- 8
|
103
|
+
- 7
|
104
|
+
version: 1.8.7
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
requirements:
|
114
|
+
- PostgreSQL >=7.4
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.3.7
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A Ruby interface to the PostgreSQL RDBMS
|
120
|
+
test_files:
|
121
|
+
- spec/m17n_spec.rb
|
122
|
+
- spec/pgconn_spec.rb
|
123
|
+
- spec/pgresult_spec.rb
|
124
|
+
- spec/lib/helpers.rb
|
125
|
+
- spec/data/expected_trace.out
|
126
|
+
- spec/data/random_binary_data
|