kamk-pg 0.8.0 → 0.8.0.3

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.
@@ -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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamk-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
@@ -26,7 +26,39 @@ extensions:
26
26
  extra_rdoc_files:
27
27
  - ext/pg.c
28
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-m17n3.patch
29
45
  - ext/pg.c
46
+ - ext/pg.h
47
+ - ext/vc
48
+ - ext/mingw/Rakefile
49
+ - ext/mingw/build.rake
50
+ - ext/vc/pg.sln
51
+ - sample/losample.rb
52
+ - sample/psql.rb
53
+ - sample/psqlHelp.rb
54
+ - sample/test1.rb
55
+ - sample/test2.rb
56
+ - sample/test4.rb
57
+ - spec/data
58
+ - spec/data/expected_trace.out
59
+ - spec/data/random_binary_data
60
+ - spec/pgconn_spec.rb
61
+ - spec/pgresult_spec.rb
30
62
  has_rdoc: true
31
63
  homepage: http://rubyforge.org/projects/ruby-pg
32
64
  post_install_message: