dbd-pg 0.3.6 → 0.3.7
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 +3 -2
- data/lib/dbd/pg/tuples.rb +3 -2
- data/test/dbd/general/test_database.rb +12 -10
- data/test/dbd/postgresql/down.sql +4 -0
- data/test/dbd/postgresql/testdbipg.rb +14 -0
- data/test/dbd/postgresql/up.sql +4 -0
- metadata +73 -64
data/lib/dbd/Pg.rb
CHANGED
data/lib/dbd/pg/database.rb
CHANGED
@@ -74,7 +74,7 @@ class DBI::DBD::Pg::Database < DBI::BaseDatabase
|
|
74
74
|
@attr.each { |k,v| self[k] = v}
|
75
75
|
@attr["pg_native_binding"] = true unless @attr.has_key? "pg_native_binding"
|
76
76
|
|
77
|
-
|
77
|
+
load_type_map
|
78
78
|
|
79
79
|
self['AutoCommit'] = true # Postgres starts in unchained mode (AutoCommit=on) by default
|
80
80
|
|
@@ -340,6 +340,7 @@ class DBI::DBD::Pg::Database < DBI::BaseDatabase
|
|
340
340
|
when 'date' then DBI::Type::Timestamp
|
341
341
|
when 'decimal', 'numeric' then DBI::Type::Decimal
|
342
342
|
when 'bytea' then DBI::DBD::Pg::Type::ByteA
|
343
|
+
when 'enum' then DBI::Type::Varchar
|
343
344
|
end
|
344
345
|
end
|
345
346
|
|
@@ -350,7 +351,7 @@ class DBI::DBD::Pg::Database < DBI::BaseDatabase
|
|
350
351
|
def load_type_map
|
351
352
|
@type_map = Hash.new
|
352
353
|
|
353
|
-
res = _exec("SELECT oid, typname, typelem FROM pg_type WHERE typtype
|
354
|
+
res = _exec("SELECT oid, typname, typelem FROM pg_type WHERE typtype IN ('b', 'e')")
|
354
355
|
|
355
356
|
res.each do |row|
|
356
357
|
rowtype = parse_type_name(row["typname"])
|
data/lib/dbd/pg/tuples.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
#
|
9
9
|
class DBI::DBD::Pg::Tuples
|
10
10
|
|
11
|
-
def initialize(db,pg_result)
|
11
|
+
def initialize(db, pg_result)
|
12
12
|
@db = db
|
13
13
|
@pg_result = pg_result
|
14
14
|
@index = -1
|
@@ -37,7 +37,8 @@ class DBI::DBD::Pg::Tuples
|
|
37
37
|
typeinfo = DBI::DBD::Pg.parse_type(res[0].values[0])
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
map = @db.type_map[@pg_result.ftype(i)] || { }
|
41
|
+
h = { "name" => str }.merge(map)
|
41
42
|
|
42
43
|
if typeinfo
|
43
44
|
h["precision"] = typeinfo[:size]
|
@@ -41,7 +41,7 @@
|
|
41
41
|
end
|
42
42
|
|
43
43
|
assert_equal(
|
44
|
-
DBI::Type::Varchar.object_id,
|
44
|
+
DBI::Type::Varchar.object_id,
|
45
45
|
DBI::TypeUtil.type_name_to_module(cols[0]["type_name"]).object_id
|
46
46
|
)
|
47
47
|
|
@@ -51,9 +51,9 @@
|
|
51
51
|
assert(cols[1]["nullable"])
|
52
52
|
assert_equal(1, cols[2]["scale"])
|
53
53
|
assert_equal(2, cols[2]["precision"])
|
54
|
-
|
54
|
+
|
55
55
|
assert_equal(
|
56
|
-
DBI::Type::Integer.object_id,
|
56
|
+
DBI::Type::Integer.object_id,
|
57
57
|
DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
|
58
58
|
)
|
59
59
|
|
@@ -64,7 +64,7 @@
|
|
64
64
|
assert_equal(1, cols[2]["scale"])
|
65
65
|
assert_equal(2, cols[2]["precision"])
|
66
66
|
assert_equal(
|
67
|
-
DBI::Type::Decimal.object_id,
|
67
|
+
DBI::Type::Decimal.object_id,
|
68
68
|
DBI::TypeUtil.type_name_to_module(cols[2]["type_name"]).object_id
|
69
69
|
)
|
70
70
|
|
@@ -75,7 +75,7 @@
|
|
75
75
|
assert_equal(6, cols[3]["scale"])
|
76
76
|
assert_equal(30, cols[3]["precision"])
|
77
77
|
assert_equal(
|
78
|
-
DBI::Type::Decimal.object_id,
|
78
|
+
DBI::Type::Decimal.object_id,
|
79
79
|
DBI::TypeUtil.type_name_to_module(cols[3]["type_name"]).object_id
|
80
80
|
)
|
81
81
|
|
@@ -157,11 +157,13 @@
|
|
157
157
|
"views"
|
158
158
|
]
|
159
159
|
end
|
160
|
-
|
161
|
-
case dbtype
|
160
|
+
|
161
|
+
case dbtype
|
162
162
|
when "postgresql"
|
163
163
|
tables.reject! { |x| x =~ /^pg_/ }
|
164
|
-
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
|
164
|
+
assert_equal %w(array_test bit_test blob_test boolean_test bytea_test db_specific_types_test enum_type_test field_types_test names precision_test time_test timestamp_test view_names), tables
|
165
|
+
when 'sqlite3'
|
166
|
+
assert_equal %w(bit_test blob_test boolean_test db_specific_types_test field_types_test names names_defined_with_spaces precision_test time_test timestamp_test view_names), tables
|
165
167
|
else
|
166
168
|
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
|
167
169
|
end
|
@@ -176,13 +178,13 @@
|
|
176
178
|
assert !@dbh["AutoCommit"]
|
177
179
|
|
178
180
|
# test committing an outstanding transaction
|
179
|
-
|
181
|
+
|
180
182
|
@sth = @dbh.prepare("insert into names (name, age) values (?, ?)")
|
181
183
|
@sth.execute("Billy", 22)
|
182
184
|
@sth.finish
|
183
185
|
|
184
186
|
assert @dbh["AutoCommit"] = true # should commit at this point
|
185
|
-
|
187
|
+
|
186
188
|
@sth = @dbh.prepare("select * from names where name = ?")
|
187
189
|
@sth.execute("Billy")
|
188
190
|
assert_equal [ "Billy", 22 ], @sth.fetch
|
@@ -25,6 +25,20 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_enum_type
|
29
|
+
assert_nothing_raised do
|
30
|
+
assert(@dbh.convert_types)
|
31
|
+
@sth = @dbh.prepare("insert into enum_type_test values (?)")
|
32
|
+
@sth.execute("one")
|
33
|
+
@sth.finish
|
34
|
+
|
35
|
+
@sth = @dbh.prepare("select foo from enum_type_test")
|
36
|
+
@sth.execute
|
37
|
+
assert_equal(@sth.fetch, ['one'])
|
38
|
+
@sth.finish
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
def test_statement_finish_deallocates_sth
|
29
43
|
assert_nothing_raised do
|
30
44
|
@sth = @dbh.prepare("select * from names")
|
data/test/dbd/postgresql/up.sql
CHANGED
@@ -30,6 +30,10 @@ 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 type enum_test as ENUM ('one', 'two', 'three');
|
34
|
+
---
|
35
|
+
create table enum_type_test (foo enum_test);
|
36
|
+
---
|
33
37
|
create table db_specific_types_test (foo integer);
|
34
38
|
---
|
35
39
|
create table array_test (foo integer[], bar integer[3], baz integer[3][3], quux varchar[2]);
|
metadata
CHANGED
@@ -1,90 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: dbd-pg
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2008-11-28 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:
|
4
|
+
version: 0.3.7
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Erik Hollensbe
|
31
8
|
- Christopher Maujean
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-12-15 00:00:00 -08: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
|
32
46
|
files:
|
33
|
-
- test/dbd/general/test_database.rb
|
34
|
-
- test/dbd/general/test_statement.rb
|
35
47
|
- test/dbd/general/test_types.rb
|
36
|
-
- test/dbd/
|
37
|
-
- test/dbd/
|
48
|
+
- test/dbd/general/test_statement.rb
|
49
|
+
- test/dbd/general/test_database.rb
|
50
|
+
- test/dbd/postgresql/test_ping.rb
|
38
51
|
- test/dbd/postgresql/base.rb
|
39
|
-
- test/dbd/postgresql/
|
40
|
-
- test/dbd/postgresql/
|
41
|
-
- test/dbd/postgresql/test_async.rb
|
52
|
+
- test/dbd/postgresql/test_timestamp.rb
|
53
|
+
- test/dbd/postgresql/base.rb.new
|
42
54
|
- test/dbd/postgresql/test_blob.rb
|
55
|
+
- test/dbd/postgresql/test_async.rb
|
56
|
+
- test/dbd/postgresql/down.sql
|
43
57
|
- test/dbd/postgresql/test_transactions.rb
|
44
|
-
- test/dbd/postgresql/base.rb.new
|
45
|
-
- test/dbd/postgresql/testdbipg.rb
|
46
58
|
- test/dbd/postgresql/up.sql
|
47
|
-
- test/dbd/postgresql/
|
59
|
+
- test/dbd/postgresql/test_arrays.rb
|
60
|
+
- test/dbd/postgresql/testdbipg.rb
|
61
|
+
- test/dbd/postgresql/test_bytea.rb
|
48
62
|
- lib/dbd/Pg.rb
|
49
63
|
- lib/dbd/pg/database.rb
|
50
64
|
- lib/dbd/pg/tuples.rb
|
65
|
+
- lib/dbd/pg/statement.rb
|
51
66
|
- lib/dbd/pg/exec.rb
|
52
67
|
- lib/dbd/pg/type.rb
|
53
|
-
- lib/dbd/pg/statement.rb
|
54
68
|
- test/DBD_TESTS
|
55
69
|
- README
|
56
70
|
- LICENSE
|
57
71
|
- ChangeLog
|
58
|
-
|
59
|
-
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://www.rubyforge.org/projects/ruby-dbi
|
74
|
+
post_install_message:
|
60
75
|
rdoc_options: []
|
61
76
|
|
62
|
-
|
63
|
-
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.8.0
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
70
91
|
requirements: []
|
71
92
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 0.4.0
|
81
|
-
version:
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: pg
|
84
|
-
version_requirement:
|
85
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.0
|
90
|
-
version:
|
93
|
+
rubyforge_project: ruby-dbi
|
94
|
+
rubygems_version: 1.3.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: PostgreSQL DBI DBD
|
98
|
+
test_files:
|
99
|
+
- test/ts_dbd.rb
|