dbd-pg 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dbd/Pg.rb +1 -1
- data/lib/dbd/pg/database.rb +1 -0
- data/test/dbd/general/test_database.rb +31 -9
- data/test/dbd/general/test_statement.rb +38 -7
- data/test/dbd/general/test_types.rb +28 -0
- data/test/dbd/postgresql/down.sql +2 -0
- data/test/dbd/postgresql/testdbipg.rb +0 -17
- data/test/dbd/postgresql/up.sql +3 -1
- metadata +63 -72
data/lib/dbd/Pg.rb
CHANGED
data/lib/dbd/pg/database.rb
CHANGED
@@ -338,6 +338,7 @@ class DBI::DBD::Pg::Database < DBI::BaseDatabase
|
|
338
338
|
when 'time', 'timetz' then DBI::Type::Timestamp
|
339
339
|
when 'timestamp', 'timestamptz' then DBI::Type::Timestamp
|
340
340
|
when 'date' then DBI::Type::Timestamp
|
341
|
+
when 'decimal', 'numeric' then DBI::Type::Decimal
|
341
342
|
when 'bytea' then DBI::DBD::Pg::Type::ByteA
|
342
343
|
end
|
343
344
|
end
|
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
assert(cols)
|
13
13
|
assert_kind_of(Array, cols)
|
14
|
-
assert_equal(
|
14
|
+
assert_equal(4, cols.length)
|
15
15
|
|
16
16
|
# the first column should always be "text_field" and have the following
|
17
17
|
# properties:
|
@@ -30,19 +30,41 @@
|
|
30
30
|
end
|
31
31
|
|
32
32
|
assert_equal(
|
33
|
-
DBI::Type::Varchar,
|
34
|
-
DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
|
33
|
+
DBI::Type::Varchar.object_id,
|
34
|
+
DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
|
35
35
|
)
|
36
36
|
|
37
37
|
# the second column should always be "integer_field" and have the following
|
38
38
|
# properties:
|
39
39
|
assert_equal("integer_field", cols[1]["name"])
|
40
40
|
assert(cols[1]["nullable"])
|
41
|
-
assert_equal(1, cols[
|
42
|
-
assert_equal(2, cols[
|
41
|
+
assert_equal(1, cols[2]["scale"])
|
42
|
+
assert_equal(2, cols[2]["precision"])
|
43
43
|
assert_equal(
|
44
|
-
DBI::Type::
|
45
|
-
DBI::TypeUtil.type_name_to_module(cols[1]["type_name"])
|
44
|
+
DBI::Type::Integer.object_id,
|
45
|
+
DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
|
46
|
+
)
|
47
|
+
|
48
|
+
# the second column should always be "integer_field" and have the following
|
49
|
+
# properties:
|
50
|
+
assert_equal("decimal_field", cols[2]["name"])
|
51
|
+
assert(cols[2]["nullable"])
|
52
|
+
assert_equal(1, cols[2]["scale"])
|
53
|
+
assert_equal(2, cols[2]["precision"])
|
54
|
+
assert_equal(
|
55
|
+
DBI::Type::Decimal.object_id,
|
56
|
+
DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
|
57
|
+
)
|
58
|
+
|
59
|
+
# the second column should always be "numeric_field" and have the following
|
60
|
+
# properties:
|
61
|
+
assert_equal("numeric_field", cols[3]["name"])
|
62
|
+
assert(cols[3]["nullable"])
|
63
|
+
assert_equal(6, cols[3]["scale"])
|
64
|
+
assert_equal(30, cols[3]["precision"])
|
65
|
+
assert_equal(
|
66
|
+
DBI::Type::Decimal.object_id,
|
67
|
+
DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
|
46
68
|
)
|
47
69
|
|
48
70
|
# finally, we ensure that every column in the array is a ColumnInfo
|
@@ -127,9 +149,9 @@
|
|
127
149
|
case dbtype
|
128
150
|
when "postgresql"
|
129
151
|
tables.reject! { |x| x =~ /^pg_/ }
|
130
|
-
assert_equal %w(array_test bit_test blob_test boolean_test bytea_test field_types_test names precision_test time_test timestamp_test view_names), tables
|
152
|
+
assert_equal %w(array_test bit_test blob_test boolean_test bytea_test db_specific_types_test field_types_test names precision_test time_test timestamp_test view_names), tables
|
131
153
|
else
|
132
|
-
assert_equal %w(bit_test blob_test boolean_test field_types_test names precision_test time_test timestamp_test view_names), tables
|
154
|
+
assert_equal %w(bit_test blob_test boolean_test db_specific_types_test field_types_test names precision_test time_test timestamp_test view_names), tables
|
133
155
|
end
|
134
156
|
end
|
135
157
|
|
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
assert(cols)
|
46
46
|
assert_kind_of(Array, cols)
|
47
|
-
assert_equal(
|
47
|
+
assert_equal(4, cols.length)
|
48
48
|
|
49
49
|
# the first column should always be "text_field" and have the following
|
50
50
|
# properties:
|
@@ -61,18 +61,49 @@
|
|
61
61
|
end
|
62
62
|
|
63
63
|
assert_equal(
|
64
|
-
DBI::Type::Varchar,
|
65
|
-
DBI::TypeUtil.type_name_to_module(cols[0]["type_name"])
|
64
|
+
DBI::Type::Varchar.object_id,
|
65
|
+
DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
|
66
66
|
)
|
67
67
|
|
68
68
|
# the second column should always be "integer_field" and have the following
|
69
69
|
# properties:
|
70
70
|
assert_equal("integer_field", cols[1]["name"])
|
71
|
-
|
72
|
-
|
71
|
+
# if these aren't set on the field, they should not exist
|
72
|
+
# FIXME mysql does not follow this rule, neither does ODBC
|
73
|
+
if dbtype == "mysql"
|
74
|
+
assert_equal(0, cols[1]["scale"])
|
75
|
+
assert_equal(11, cols[1]["precision"])
|
76
|
+
elsif dbtype == "odbc"
|
77
|
+
assert_equal(0, cols[1]["scale"])
|
78
|
+
assert_equal(10, cols[1]["precision"])
|
79
|
+
else
|
80
|
+
assert(!cols[1]["scale"])
|
81
|
+
assert(!cols[1]["precision"])
|
82
|
+
end
|
83
|
+
|
84
|
+
assert_equal(
|
85
|
+
DBI::Type::Integer.object_id,
|
86
|
+
DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
|
87
|
+
)
|
88
|
+
|
89
|
+
# the second column should always be "integer_field" and have the following
|
90
|
+
# properties:
|
91
|
+
assert_equal("decimal_field", cols[2]["name"])
|
92
|
+
assert_equal(1, cols[2]["scale"])
|
93
|
+
assert_equal(2, cols[2]["precision"])
|
94
|
+
assert_equal(
|
95
|
+
DBI::Type::Decimal.object_id,
|
96
|
+
DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
|
97
|
+
)
|
98
|
+
|
99
|
+
# the second column should always be "numeric_field" and have the following
|
100
|
+
# properties:
|
101
|
+
assert_equal("numeric_field", cols[3]["name"])
|
102
|
+
assert_equal(6, cols[3]["scale"])
|
103
|
+
assert_equal(30, cols[3]["precision"])
|
73
104
|
assert_equal(
|
74
|
-
DBI::Type::Decimal,
|
75
|
-
DBI::TypeUtil.type_name_to_module(cols[
|
105
|
+
DBI::Type::Decimal.object_id,
|
106
|
+
DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
|
76
107
|
)
|
77
108
|
|
78
109
|
cols.each { |col| assert_kind_of(DBI::ColumnInfo, col) }
|
@@ -25,6 +25,34 @@
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_numeric_types
|
29
|
+
assert(@dbh.convert_types)
|
30
|
+
|
31
|
+
@sth = @dbh.prepare("insert into precision_test (text_field, integer_field, decimal_field, numeric_field) values (?, ?, ?, ?)")
|
32
|
+
assert(@sth.convert_types)
|
33
|
+
1.step(5) do |x|
|
34
|
+
@sth.execute("poop#{x}", x, x + 0.123, x + 0.234)
|
35
|
+
end
|
36
|
+
|
37
|
+
@sth.finish
|
38
|
+
|
39
|
+
@sth = @dbh.prepare("select integer_field, decimal_field, numeric_field from precision_test")
|
40
|
+
@sth.execute
|
41
|
+
col_info = @sth.column_info
|
42
|
+
1.step(5) do |x|
|
43
|
+
row = @sth.fetch
|
44
|
+
|
45
|
+
assert_kind_of(Integer, row[0])
|
46
|
+
assert_kind_of(BigDecimal, row[1])
|
47
|
+
assert_kind_of(BigDecimal, row[2])
|
48
|
+
|
49
|
+
# FIXME BigDecimal requires a string and some databases will pad
|
50
|
+
# decimal/numeric with constrained precision. We should account for
|
51
|
+
# this, but I'm not quite sure how yet.
|
52
|
+
end
|
53
|
+
@sth.finish
|
54
|
+
end
|
55
|
+
|
28
56
|
# FIXME
|
29
57
|
# Ideally, this test should be split across the DBI tests and DBD, but for
|
30
58
|
# now testing against the DBDs really doesn't cost us anything other than
|
@@ -91,23 +91,6 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
|
|
91
91
|
@sth.finish
|
92
92
|
end
|
93
93
|
|
94
|
-
def test_tables
|
95
|
-
assert_equal(
|
96
|
-
[
|
97
|
-
"array_test",
|
98
|
-
"bit_test",
|
99
|
-
"blob_test",
|
100
|
-
"boolean_test",
|
101
|
-
"bytea_test",
|
102
|
-
"field_types_test",
|
103
|
-
"names",
|
104
|
-
"precision_test",
|
105
|
-
"time_test",
|
106
|
-
"timestamp_test",
|
107
|
-
"view_names"
|
108
|
-
], @dbh.tables.reject { |x| x =~ /^pg_/ }.sort)
|
109
|
-
end
|
110
|
-
|
111
94
|
def test_columns
|
112
95
|
assert_equal(
|
113
96
|
[
|
data/test/dbd/postgresql/up.sql
CHANGED
@@ -9,7 +9,7 @@ insert into names (name, age) values ('Jim', 30);
|
|
9
9
|
---
|
10
10
|
insert into names (name, age) values ('Bob', 21);
|
11
11
|
---
|
12
|
-
create table precision_test (text_field varchar(20) primary key not null, integer_field decimal(2,1));
|
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
13
|
---
|
14
14
|
CREATE TABLE blob_test (name VARCHAR(30), data OID);
|
15
15
|
---
|
@@ -30,6 +30,8 @@ create table bit_test (mybit bit);
|
|
30
30
|
---
|
31
31
|
create table field_types_test (foo integer not null primary key default 1);
|
32
32
|
---
|
33
|
+
create table db_specific_types_test (foo integer);
|
34
|
+
---
|
33
35
|
create table array_test (foo integer[], bar integer[3], baz integer[3][3], quux varchar[2]);
|
34
36
|
---
|
35
37
|
create table bytea_test (foo bytea);
|
metadata
CHANGED
@@ -1,98 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
2
4
|
name: dbd-pg
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
6
|
+
version: 0.3.5
|
7
|
+
date: 2008-11-09 00:00:00 -08:00
|
8
|
+
summary: PostgreSQL DBI DBD
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ruby-dbi-users@rubyforge.org
|
12
|
+
homepage: http://www.rubyforge.org/projects/ruby-dbi
|
13
|
+
rubyforge_project: ruby-dbi
|
14
|
+
description: PostgreSQL DBI DBD
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.0
|
24
|
+
version:
|
5
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
6
29
|
authors:
|
7
30
|
- Erik Hollensbe
|
8
31
|
- Christopher Maujean
|
9
|
-
autorequire:
|
10
|
-
bindir: bin
|
11
|
-
cert_chain: []
|
12
|
-
|
13
|
-
date: 2008-09-02 00:00:00 -07:00
|
14
|
-
default_executable:
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: dbi
|
18
|
-
type: :runtime
|
19
|
-
version_requirement:
|
20
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">="
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.4.0
|
25
|
-
version:
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: pg
|
28
|
-
type: :runtime
|
29
|
-
version_requirement:
|
30
|
-
version_requirements: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: "0"
|
35
|
-
version:
|
36
|
-
description: PostgreSQL DBI DBD
|
37
|
-
email: ruby-dbi-users@rubyforge.org
|
38
|
-
executables: []
|
39
|
-
|
40
|
-
extensions: []
|
41
|
-
|
42
|
-
extra_rdoc_files:
|
43
|
-
- README
|
44
|
-
- LICENSE
|
45
|
-
- ChangeLog
|
46
32
|
files:
|
47
|
-
- test/dbd/general/test_types.rb
|
48
33
|
- test/dbd/general/test_database.rb
|
49
34
|
- test/dbd/general/test_statement.rb
|
50
|
-
- test/dbd/
|
51
|
-
- test/dbd/postgresql/
|
52
|
-
- test/dbd/postgresql/test_ping.rb
|
53
|
-
- test/dbd/postgresql/down.sql
|
35
|
+
- test/dbd/general/test_types.rb
|
36
|
+
- test/dbd/postgresql/test_timestamp.rb
|
54
37
|
- test/dbd/postgresql/test_arrays.rb
|
55
|
-
- test/dbd/postgresql/testdbipg.rb
|
56
|
-
- test/dbd/postgresql/up.sql
|
57
38
|
- test/dbd/postgresql/base.rb
|
58
|
-
- test/dbd/postgresql/
|
39
|
+
- test/dbd/postgresql/down.sql
|
40
|
+
- test/dbd/postgresql/test_bytea.rb
|
59
41
|
- test/dbd/postgresql/test_async.rb
|
60
42
|
- test/dbd/postgresql/test_blob.rb
|
43
|
+
- test/dbd/postgresql/test_transactions.rb
|
44
|
+
- test/dbd/postgresql/testdbipg.rb
|
45
|
+
- test/dbd/postgresql/up.sql
|
46
|
+
- test/dbd/postgresql/test_ping.rb
|
61
47
|
- lib/dbd/Pg.rb
|
62
|
-
- lib/dbd/pg/
|
48
|
+
- lib/dbd/pg/database.rb
|
63
49
|
- lib/dbd/pg/tuples.rb
|
50
|
+
- lib/dbd/pg/exec.rb
|
64
51
|
- lib/dbd/pg/type.rb
|
65
|
-
- lib/dbd/pg/database.rb
|
66
52
|
- lib/dbd/pg/statement.rb
|
67
53
|
- test/DBD_TESTS
|
68
54
|
- README
|
69
55
|
- LICENSE
|
70
56
|
- ChangeLog
|
71
|
-
|
72
|
-
|
73
|
-
post_install_message:
|
57
|
+
test_files:
|
58
|
+
- test/ts_dbd.rb
|
74
59
|
rdoc_options: []
|
75
60
|
|
76
|
-
|
77
|
-
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: "0"
|
89
|
-
version:
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README
|
63
|
+
- LICENSE
|
64
|
+
- ChangeLog
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
90
69
|
requirements: []
|
91
70
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
-
|
71
|
+
dependencies:
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: dbi
|
74
|
+
version_requirement:
|
75
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.4.0
|
80
|
+
version:
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: pg
|
83
|
+
version_requirement:
|
84
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.0.0
|
89
|
+
version:
|