ydbd-pg 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ChangeLog +3703 -0
- data/LICENSE +25 -0
- data/lib/dbd/Pg.rb +188 -0
- data/lib/dbd/pg/database.rb +516 -0
- data/lib/dbd/pg/exec.rb +47 -0
- data/lib/dbd/pg/statement.rb +160 -0
- data/lib/dbd/pg/tuples.rb +121 -0
- data/lib/dbd/pg/type.rb +209 -0
- data/readme.md +274 -0
- data/test/DBD_TESTS +50 -0
- data/test/dbd/general/test_database.rb +206 -0
- data/test/dbd/general/test_statement.rb +326 -0
- data/test/dbd/general/test_types.rb +296 -0
- data/test/dbd/postgresql/base.rb +31 -0
- data/test/dbd/postgresql/down.sql +31 -0
- data/test/dbd/postgresql/test_arrays.rb +179 -0
- data/test/dbd/postgresql/test_async.rb +121 -0
- data/test/dbd/postgresql/test_blob.rb +36 -0
- data/test/dbd/postgresql/test_bytea.rb +87 -0
- data/test/dbd/postgresql/test_ping.rb +10 -0
- data/test/dbd/postgresql/test_timestamp.rb +77 -0
- data/test/dbd/postgresql/test_transactions.rb +58 -0
- data/test/dbd/postgresql/testdbipg.rb +307 -0
- data/test/dbd/postgresql/up.sql +60 -0
- data/test/ts_dbd.rb +131 -0
- metadata +100 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
create table names (
|
2
|
+
name varchar(255),
|
3
|
+
age integer
|
4
|
+
);
|
5
|
+
---
|
6
|
+
insert into names (name, age) values ('Joe', 19);
|
7
|
+
---
|
8
|
+
insert into names (name, age) values ('Jim', 30);
|
9
|
+
---
|
10
|
+
insert into names (name, age) values ('Bob', 21);
|
11
|
+
---
|
12
|
+
create table precision_test (text_field varchar(20) primary key not null, integer_field integer, decimal_field decimal(2,1), numeric_field numeric(30,6));
|
13
|
+
---
|
14
|
+
CREATE TABLE blob_test (name VARCHAR(30), data OID);
|
15
|
+
---
|
16
|
+
create view view_names as select * from names;
|
17
|
+
---
|
18
|
+
create or replace function test_insert (varchar(255), integer)
|
19
|
+
returns integer
|
20
|
+
language sql
|
21
|
+
as 'insert into names (name, age) values ($1, $2); select age from names where name = $1';
|
22
|
+
---
|
23
|
+
create table boolean_test (num integer, mybool boolean);
|
24
|
+
---
|
25
|
+
create table time_test (mytime time);
|
26
|
+
---
|
27
|
+
create table timestamp_test (mytimestamp timestamp);
|
28
|
+
---
|
29
|
+
create table bit_test (mybit bit);
|
30
|
+
---
|
31
|
+
create table field_types_test (foo integer not null primary key default 1);
|
32
|
+
---
|
33
|
+
create type enum_test as ENUM ('one', 'two', 'three');
|
34
|
+
---
|
35
|
+
create table enum_type_test (foo enum_test);
|
36
|
+
---
|
37
|
+
create table db_specific_types_test (foo integer);
|
38
|
+
---
|
39
|
+
create table array_test (foo integer[], bar integer[3], baz integer[3][3], quux varchar[2]);
|
40
|
+
---
|
41
|
+
create table bytea_test (foo bytea);
|
42
|
+
---
|
43
|
+
create schema schema1;
|
44
|
+
---
|
45
|
+
create schema schema2;
|
46
|
+
---
|
47
|
+
create table schema1.tbl (foo integer);
|
48
|
+
---
|
49
|
+
create table schema2.tbl (bar integer);
|
50
|
+
---
|
51
|
+
create or replace function
|
52
|
+
select_subproperty(value names.age%TYPE, sub names.age%TYPE, out retval names.age%TYPE)
|
53
|
+
as $$
|
54
|
+
select
|
55
|
+
case
|
56
|
+
when $2 is not null
|
57
|
+
then $1
|
58
|
+
else null
|
59
|
+
end
|
60
|
+
$$ language sql;
|
data/test/ts_dbd.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'test-unit'
|
3
|
+
# figure out what tests to run
|
4
|
+
require 'yaml'
|
5
|
+
require 'test/unit/testsuite'
|
6
|
+
require 'test/unit/ui/console/testrunner'
|
7
|
+
|
8
|
+
if File.basename(Dir.pwd) == "test"
|
9
|
+
$:.unshift('../lib')
|
10
|
+
else
|
11
|
+
$:.unshift('lib')
|
12
|
+
end
|
13
|
+
|
14
|
+
module Test::Unit::Assertions
|
15
|
+
def build_message(head, template=nil, *arguments)
|
16
|
+
template += "\n" + "DATABASE: " + dbtype
|
17
|
+
template &&= template.chomp
|
18
|
+
return AssertionMessage.new(head, template, arguments)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Class
|
23
|
+
def name=(klass_name)
|
24
|
+
@name = klass_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
return @name || super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module DBDConfig
|
33
|
+
@testbase = { }
|
34
|
+
@current_dbtype = nil
|
35
|
+
|
36
|
+
def self.get_config
|
37
|
+
config = nil
|
38
|
+
|
39
|
+
begin
|
40
|
+
config = YAML.load_file(File.join(ENV["HOME"], ".ruby-dbi.test-config.yaml"))
|
41
|
+
rescue Exception => e
|
42
|
+
config = { }
|
43
|
+
config["dbtypes"] = [ ]
|
44
|
+
end
|
45
|
+
|
46
|
+
return config
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.inject_sql(dbh, dbtype, file)
|
50
|
+
# splits by --- in the file, strips newlines and the semicolons.
|
51
|
+
# this way we can still manually import the file, but use it with our
|
52
|
+
# drivers for client-independent injection.
|
53
|
+
File.open(file).read.split(/\n*---\n*/, -1).collect { |x| x.gsub!(/\n/, ''); x.sub(/;\z/, '') }.each do |stmt|
|
54
|
+
tmp = STDERR.dup
|
55
|
+
STDERR.reopen('sql.log', 'a')
|
56
|
+
begin
|
57
|
+
dbh.commit rescue nil
|
58
|
+
dbh["AutoCommit"] = true rescue nil
|
59
|
+
dbh.do(stmt)
|
60
|
+
dbh.commit unless dbtype == 'sqlite3'
|
61
|
+
rescue Exception => e
|
62
|
+
tmp.puts "Error injecting '#{stmt}' for db #{dbtype}"
|
63
|
+
tmp.puts "Error: #{e.message}"
|
64
|
+
end
|
65
|
+
STDERR.reopen(tmp)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.current_dbtype
|
70
|
+
@current_dbtype
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.current_dbtype=(setting)
|
74
|
+
@current_dbtype = setting
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.testbase(klass_name)
|
78
|
+
return @testbase[klass_name]
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.set_testbase(klass_name, klass)
|
82
|
+
@testbase[klass_name] = klass
|
83
|
+
klass.name = klass_name.to_s
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.suite
|
87
|
+
@suite ||= []
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if __FILE__ == $0
|
92
|
+
Dir.chdir("..") if File.basename(Dir.pwd) == "test"
|
93
|
+
$LOAD_PATH.unshift(File.join(Dir.pwd, "lib"))
|
94
|
+
Dir.chdir("test") rescue nil
|
95
|
+
|
96
|
+
begin
|
97
|
+
require 'dbi'
|
98
|
+
rescue LoadError => e
|
99
|
+
begin
|
100
|
+
require 'rubygems'
|
101
|
+
gem 'dbi'
|
102
|
+
require 'dbi'
|
103
|
+
rescue LoadError => e
|
104
|
+
abort "DBI must already be installed or must come with this package for tests to work."
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
Deprecate.set_action(proc { })
|
109
|
+
|
110
|
+
config = DBDConfig.get_config
|
111
|
+
|
112
|
+
config["dbtypes"] = ENV["DBTYPES"].split(/\s+/) if ENV["DBTYPES"]
|
113
|
+
|
114
|
+
if config and config["dbtypes"]
|
115
|
+
config["dbtypes"].each do |dbtype|
|
116
|
+
unless config[dbtype]
|
117
|
+
warn "#{dbtype} is selected for testing but not configured; see test/DBD_TESTS"
|
118
|
+
next
|
119
|
+
end
|
120
|
+
|
121
|
+
# base.rb is special, see DBD_TESTS
|
122
|
+
require "dbd/#{dbtype}/base.rb"
|
123
|
+
Dir["dbd/#{dbtype}/test*.rb"].each { |file| require file }
|
124
|
+
# run the general tests
|
125
|
+
DBDConfig.current_dbtype = dbtype.to_sym
|
126
|
+
Dir["dbd/general/test*.rb"].each { |file| load file; @class.name = file; DBDConfig.suite << @class }
|
127
|
+
end
|
128
|
+
elsif !config["dbtypes"]
|
129
|
+
warn "Please see test/DBD_TESTS for information on configuring DBD tests."
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ydbd-pg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erik Hollensbe
|
8
|
+
- Christopher Maujean
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ydbi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.5.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.5.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: pg
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: PostgreSQL DBI DBD
|
43
|
+
email: zdavatz@ywesee.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- readme.md
|
48
|
+
- LICENSE
|
49
|
+
- ChangeLog
|
50
|
+
files:
|
51
|
+
- ChangeLog
|
52
|
+
- LICENSE
|
53
|
+
- lib/dbd/Pg.rb
|
54
|
+
- lib/dbd/pg/database.rb
|
55
|
+
- lib/dbd/pg/exec.rb
|
56
|
+
- lib/dbd/pg/statement.rb
|
57
|
+
- lib/dbd/pg/tuples.rb
|
58
|
+
- lib/dbd/pg/type.rb
|
59
|
+
- readme.md
|
60
|
+
- test/DBD_TESTS
|
61
|
+
- test/dbd/general/test_database.rb
|
62
|
+
- test/dbd/general/test_statement.rb
|
63
|
+
- test/dbd/general/test_types.rb
|
64
|
+
- test/dbd/postgresql/base.rb
|
65
|
+
- test/dbd/postgresql/down.sql
|
66
|
+
- test/dbd/postgresql/test_arrays.rb
|
67
|
+
- test/dbd/postgresql/test_async.rb
|
68
|
+
- test/dbd/postgresql/test_blob.rb
|
69
|
+
- test/dbd/postgresql/test_bytea.rb
|
70
|
+
- test/dbd/postgresql/test_ping.rb
|
71
|
+
- test/dbd/postgresql/test_timestamp.rb
|
72
|
+
- test/dbd/postgresql/test_transactions.rb
|
73
|
+
- test/dbd/postgresql/testdbipg.rb
|
74
|
+
- test/dbd/postgresql/up.sql
|
75
|
+
- test/ts_dbd.rb
|
76
|
+
homepage: https://github.com/zdavatz/ydbi
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.8.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: ydbi
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: PostgreSQL DBI DBD
|
99
|
+
test_files:
|
100
|
+
- test/ts_dbd.rb
|