qoobaa-pg 0.8.1

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 ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qoobaa-pg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
5
+ platform: ruby
6
+ authors:
7
+ - "Jakub Ku\xC5\xBAma"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: qoobaa@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
23
+ - ChangeLog
24
+ - LICENSE
25
+ - README
26
+ files:
27
+ - .document
28
+ - .gitignore
29
+ - BSD
30
+ - ChangeLog
31
+ - Contributors
32
+ - GPL
33
+ - LICENSE
34
+ - README
35
+ - Rakefile
36
+ - VERSION
37
+ - doc/postgres.html
38
+ - doc/postgres.jp.html
39
+ - ext/compat.c
40
+ - ext/compat.h
41
+ - ext/extconf.rb
42
+ - ext/mingw/Rakefile
43
+ - ext/mingw/build.rake
44
+ - ext/mkmf.log
45
+ - ext/mkrf_config.rb
46
+ - ext/pg.c
47
+ - ext/pg.h
48
+ - ext/vc/pg.sln
49
+ - ext/vc/pg_18/pg.vcproj
50
+ - ext/vc/pg_19/pg_19.vcproj
51
+ - pg.gemspec
52
+ - sample/losample.rb
53
+ - sample/psql.rb
54
+ - sample/psqlHelp.rb
55
+ - sample/test1.rb
56
+ - sample/test2.rb
57
+ - sample/test4.rb
58
+ - spec/data/expected_trace.out
59
+ - spec/data/random_binary_data
60
+ - spec/pgconn_spec.rb
61
+ - spec/pgresult_spec.rb
62
+ has_rdoc: false
63
+ homepage: http://github.com/qoobaa/pg
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
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
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: provides the module "pg", a Ruby interface to the PostgreSQL
88
+ test_files:
89
+ - spec/pgconn_spec.rb
90
+ - spec/pgresult_spec.rb