pg 0.8.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $LOAD_PATH.unshift('ext')
5
+ require 'pg'
6
+
7
+ describe PGconn do
8
+
9
+ before( :all ) do
10
+ puts "====== TESTING PGresult ======"
11
+ @test_directory = File.join(Dir.getwd, "tmp_test_#{rand}")
12
+ @test_pgdata = File.join(@test_directory, 'data')
13
+ if File.exists?(@test_directory) then
14
+ raise "test directory exists!"
15
+ end
16
+ @port = 54321
17
+ @conninfo = "host=localhost port=#{@port} dbname=test"
18
+ Dir.mkdir(@test_directory)
19
+ Dir.mkdir(@test_pgdata)
20
+ cmds = []
21
+ cmds << "initdb -D \"#{@test_pgdata}\""
22
+ cmds << "pg_ctl -o \"-p #{@port}\" -D \"#{@test_pgdata}\" start"
23
+ cmds << "sleep 5"
24
+ cmds << "createdb -p #{@port} test"
25
+
26
+ cmds.each do |cmd|
27
+ if not system(cmd) then
28
+ raise "Error executing cmd: #{cmd}: #{$?}"
29
+ end
30
+ end
31
+ puts "\n\n"
32
+ @conn = PGconn.connect(@conninfo)
33
+ end
34
+
35
+ it "should act as an array of hashes" do
36
+ res = @conn.exec("SELECT 1 AS a, 2 AS b")
37
+ res[0]['a'].should== '1'
38
+ res[0]['b'].should== '2'
39
+ end
40
+
41
+ it "should insert nil AS NULL and return NULL as nil" do
42
+ res = @conn.exec("SELECT $1::int AS n", [nil])
43
+ res[0]['n'].should == nil
44
+ end
45
+
46
+ it "should detect division by zero as SQLSTATE 22012" do
47
+ sqlstate = nil
48
+ begin
49
+ res = @conn.exec("SELECT 1/0")
50
+ rescue PGError => e
51
+ sqlstate = e.result.result_error_field(
52
+ PGresult::PG_DIAG_SQLSTATE).to_i
53
+ end
54
+ sqlstate.should == 22012
55
+ end
56
+
57
+ it "should return the same bytes in binary format that are sent in binary format" do
58
+ binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
59
+ bytes = File.open(binary_file, 'rb').read
60
+ res = @conn.exec('VALUES ($1::bytea)',
61
+ [ { :value => bytes, :format => 1 } ], 1)
62
+ res[0]['column1'].should== bytes
63
+ end
64
+
65
+ it "should return the same bytes in binary format that are sent as inline text" do
66
+ binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
67
+ in_bytes = File.open(binary_file, 'rb').read
68
+ out_bytes = nil
69
+ @conn.transaction do |conn|
70
+ conn.exec("SET standard_conforming_strings=on")
71
+ res = conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 1)
72
+ out_bytes = res[0]['column1']
73
+ end
74
+ out_bytes.should== in_bytes
75
+ end
76
+
77
+ it "should return the same bytes in text format that are sent in binary format" do
78
+ binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
79
+ bytes = File.open(binary_file, 'rb').read
80
+ res = @conn.exec('VALUES ($1::bytea)',
81
+ [ { :value => bytes, :format => 1 } ])
82
+ PGconn.unescape_bytea(res[0]['column1']).should== bytes
83
+ end
84
+
85
+ it "should return the same bytes in text format that are sent as inline text" do
86
+ binary_file = File.join(Dir.pwd, 'spec/data', 'random_binary_data')
87
+ in_bytes = File.open(binary_file, 'rb').read
88
+
89
+ out_bytes = nil
90
+ @conn.transaction do |conn|
91
+ conn.exec("SET standard_conforming_strings=on")
92
+ res = conn.exec("VALUES ('#{PGconn.escape_bytea(in_bytes)}'::bytea)", [], 0)
93
+ out_bytes = PGconn.unescape_bytea(res[0]['column1'])
94
+ end
95
+ out_bytes.should== in_bytes
96
+ end
97
+
98
+ after( :all ) do
99
+ puts ""
100
+ @conn.finish
101
+ cmds = []
102
+ cmds << "pg_ctl -D \"#{@test_pgdata}\" stop"
103
+ cmds << "rm -rf \"#{@test_directory}\""
104
+ cmds.each do |cmd|
105
+ if not system(cmd) then
106
+ raise "Error executing cmd: #{cmd}: #{$?}"
107
+ end
108
+ end
109
+ puts "====== COMPLETED TESTING PGresult ======"
110
+ puts ""
111
+ end
112
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: x86-mswin32-60
6
+ authors:
7
+ - Yukihiro Matsumoto
8
+ - Eiji Matsumoto
9
+ - Noboru Saitou
10
+ - Dave Lee
11
+ - Jeff Davis
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2009-03-28 00:00:00 -06:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description:
21
+ email: ruby-pg@j-davis.com
22
+ executables: []
23
+
24
+ extensions:
25
+ - ext/mingw/Rakefile
26
+ extra_rdoc_files:
27
+ - ext/pg.c
28
+ files:
29
+ - Rakefile
30
+ - README
31
+ - LICENSE
32
+ - COPYING.txt
33
+ - ChangeLog
34
+ - Contributors
35
+ - GPL
36
+ - BSD
37
+ - doc/postgres.html
38
+ - doc/postgres.jp.html
39
+ - ext/compat.c
40
+ - ext/compat.h
41
+ - ext/extconf.rb
42
+ - ext/mingw
43
+ - ext/mkrf_config.rb
44
+ - ext/pg.c
45
+ - ext/pg.h
46
+ - ext/vc
47
+ - ext/mingw/Rakefile
48
+ - ext/mingw/build.rake
49
+ - ext/vc/pg.sln
50
+ - sample/losample.rb
51
+ - sample/psql.rb
52
+ - sample/psqlHelp.rb
53
+ - sample/test1.rb
54
+ - sample/test2.rb
55
+ - sample/test4.rb
56
+ - spec/data
57
+ - spec/data/expected_trace.out
58
+ - spec/data/random_binary_data
59
+ - spec/pgconn_spec.rb
60
+ - spec/pgresult_spec.rb
61
+ - ext/mingw/pg.so
62
+ has_rdoc: true
63
+ homepage: http://rubyforge.org/projects/ruby-pg
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.8.4
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements:
82
+ - PostgreSQL libpq library and headers
83
+ rubyforge_project: ruby-pg
84
+ rubygems_version: 1.3.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Ruby extension library providing an API to PostgreSQL
88
+ test_files: []
89
+