dbd-pg 0.3.5 → 0.3.6

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.
@@ -49,7 +49,7 @@ module DBI
49
49
  # Only things that extend DBI's results are documented.
50
50
  #
51
51
  module Pg
52
- VERSION = "0.3.5"
52
+ VERSION = "0.3.6"
53
53
  DESCRIPTION = "PostgreSQL DBI DBD"
54
54
 
55
55
  #
@@ -172,9 +172,11 @@ pg = DBI::DBD::Pg
172
172
  DBI::TypeUtil.register_conversion(pg.driver_name) do |obj|
173
173
  newobj = case obj
174
174
  when ::DateTime
175
- obj.strftime("%m/%d/%Y %H:%M:%S.%N")
176
- when ::Time, ::Date
177
- ::DateTime.parse(obj.to_s).strftime("%m/%d/%Y %H:%M:%S.%N")
175
+ obj.strftime("%Y-%m-%dT%H:%M:%S.%N")
176
+ when ::Time
177
+ ::DateTime.parse(obj.to_s).strftime("%H:%M:%S.%N")
178
+ when ::Date
179
+ obj.strftime("%Y-%m-%d")
178
180
  when ::Array
179
181
  pg.generate_array(obj)
180
182
  when DBI::DBD::Pg::Type::ByteA
@@ -125,10 +125,7 @@ class DBI::DBD::Pg::Statement < DBI::BaseStatement
125
125
  # finish the statement at a lower level
126
126
  def internal_finish
127
127
  @result.finish if @result
128
- statement_exists = @db._exec("select * from pg_prepared_statements where name='#{@stmt_name}'")
129
- if statement_exists.num_tuples > 0
130
- @db._exec("DEALLOCATE \"#{@stmt_name}\"")
131
- end
128
+ @db._exec("DEALLOCATE \"#{@stmt_name}\"") if @prepared rescue nil
132
129
  end
133
130
 
134
131
  # prepare the statement at a lower level.
@@ -2,6 +2,8 @@
2
2
  Using DBD tests
3
3
  ================================================================================
4
4
 
5
+ Before you do anything, read the TESTING file.
6
+
5
7
  Create a YAML file named .ruby-dbi.test-config.yaml in your home directory.
6
8
 
7
9
  This file is a hash of keys that determine what you want to test and how you
@@ -1,4 +1,15 @@
1
1
  @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+
3
+ def test_empty_query
4
+ ["", " ", "\t"].each do |str|
5
+ [:do, :prepare, :execute, :select_one, :select_all].each do |call|
6
+ assert_raises(DBI::InterfaceError) do
7
+ @dbh.send(call, str)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
2
13
  def test_ping
3
14
  assert @dbh.ping
4
15
  # XXX if it isn't obvious, this should be tested better. Not sure what
@@ -40,6 +51,7 @@
40
51
  assert(cols[1]["nullable"])
41
52
  assert_equal(1, cols[2]["scale"])
42
53
  assert_equal(2, cols[2]["precision"])
54
+
43
55
  assert_equal(
44
56
  DBI::Type::Integer.object_id,
45
57
  DBI::TypeUtil.type_name_to_module(cols[1]["type_name"]).object_id
@@ -1,4 +1,50 @@
1
1
  @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+
3
+ def prep_status_statement
4
+ @sth.finish if (@sth and !@sth.finished?)
5
+ @sth = @dbh.prepare("select * from names order by age")
6
+ @sth.raise_error = true
7
+ end
8
+
9
+ def test_status
10
+ names_rc = 3
11
+
12
+ [:fetch, :fetch_hash, :each, :fetch_all].each do |call|
13
+ assert_raise(DBI::InterfaceError, DBI::NotSupportedError) do
14
+ prep_status_statement
15
+ @sth.send(call)
16
+ end
17
+ end
18
+
19
+ # for these next three, it doesn't really matter what the args are, it should fail
20
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
21
+ prep_status_statement
22
+ @sth.fetch_many(1)
23
+ end
24
+
25
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
26
+ prep_status_statement
27
+ @sth.fetch_scroll(0, 0)
28
+ end
29
+
30
+ assert_raises(DBI::InterfaceError, DBI::NotSupportedError) do
31
+ prep_status_statement
32
+ @sth.each { |x| }
33
+ end
34
+
35
+ assert_raises(DBI::InterfaceError) do
36
+ prep_status_statement
37
+ @sth.execute
38
+ 2.times { @sth.fetch_all }
39
+ end
40
+
41
+ assert_raises(DBI::InterfaceError) do
42
+ prep_status_statement
43
+ @sth.execute
44
+ # XXX fetch_many won't know it can't fetch anything until the third time around.
45
+ 3.times { @sth.fetch_many(names_rc) }
46
+ end
47
+ end
2
48
 
3
49
  def test_execute
4
50
  assert_nothing_raised do
@@ -90,9 +90,9 @@
90
90
  @sth = @dbh.prepare("select name, age from names order by age")
91
91
 
92
92
  # can't bind_coltype before execute
93
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
93
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(1, DBI::Type::Float) }
94
94
  # can't index < 1
95
- assert_raise(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
95
+ assert_raises(DBI::InterfaceError) { @sth.bind_coltype(0, DBI::Type::Float) }
96
96
  end
97
97
 
98
98
  def test_noconv
@@ -1,4 +1,3 @@
1
- require 'test/unit'
2
1
  require 'fileutils'
3
2
 
4
3
  DBDConfig.set_testbase(:postgresql, Class.new(Test::Unit::TestCase) do
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+
4
+ DBDConfig.set_testbase(:postgresql, Class.new(Test::Unit::TestCase) do
5
+
6
+ def dbtype
7
+ "postgresql"
8
+ end
9
+
10
+ def test_base
11
+ assert_equal(@dbh.driver_name, "Pg")
12
+ assert_kind_of(DBI::DBD::Pg::Database, @dbh.instance_variable_get(:@handle))
13
+ end
14
+
15
+ def set_base_dbh
16
+ config = DBDConfig.get_config['postgresql']
17
+ @dbh = DBI.connect("dbi:Pg:#{config['dbname']}", config['username'], config['password'])
18
+ end
19
+
20
+ def setup
21
+ set_base_dbh
22
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/postgresql/up.sql")
23
+ end
24
+
25
+ def teardown
26
+ @sth.finish if @sth && !@sth.finished?
27
+ config = DBDConfig.get_config['postgresql']
28
+ DBDConfig.inject_sql(@dbh, dbtype, "dbd/postgresql/down.sql")
29
+ @dbh.disconnect
30
+ end
31
+ end
32
+ )
@@ -138,11 +138,11 @@ class TestPostgresArray < DBDConfig.testbase(:postgresql)
138
138
  sth.execute('{1,2,3}')
139
139
  end
140
140
 
141
- assert_raise(DBI::ProgrammingError) do
141
+ assert_raises(DBI::ProgrammingError) do
142
142
  sth.execute('{{1,2,3,4}, {1,2,3}}')
143
143
  end
144
144
 
145
- assert_raise(DBI::ProgrammingError) do
145
+ assert_raises(DBI::ProgrammingError) do
146
146
  sth.execute('{{1,2,3}, {1,2,3,4}}')
147
147
  end
148
148
 
@@ -25,7 +25,7 @@ class TestPostgresBlob < DBDConfig.testbase(:postgresql)
25
25
  index += 1
26
26
  assert_equal DATA, @dbh.func(:blob_read, data, DATA.length)
27
27
  @dbh.func(:blob_export, data, '/tmp/pg_dbi_read_test')
28
- assert_equal DATA, File.readlines('/tmp/pg_dbi_read_test').to_s
28
+ assert_equal DATA, File.read('/tmp/pg_dbi_read_test')
29
29
  end
30
30
 
31
31
  assert_equal 3, index
@@ -5,6 +5,6 @@ class TestPostgresPing < DBDConfig.testbase(:postgresql)
5
5
  assert dbh
6
6
  assert dbh.ping
7
7
  dbh.disconnect
8
- assert_raise(DBI::InterfaceError) { dbh.ping }
8
+ assert_raises(DBI::InterfaceError) { dbh.ping }
9
9
  end
10
10
  end
@@ -50,7 +50,7 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
50
50
  def test_binding
51
51
  assert(@dbh["pg_native_binding"])
52
52
 
53
- assert_raise(DBI::ProgrammingError) do
53
+ assert_raises(DBI::ProgrammingError) do
54
54
  @sth = @dbh.prepare("select * from names where age IS NOT ?")
55
55
  @sth.execute("NULL")
56
56
  @sth.finish
@@ -153,15 +153,15 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
153
153
 
154
154
  def test_connect_errors
155
155
  dbd = nil
156
- ex = assert_raise(DBI::OperationalError) {
156
+ ex = assert_raises(DBI::OperationalError) {
157
157
  dbd = DBI::DBD::Pg::Database.new('rubytest:1234', 'jim', nil, {})
158
158
  }
159
- ex = assert_raise(DBI::OperationalError) {
159
+ ex = assert_raises(DBI::OperationalError) {
160
160
  dbd = DBI::DBD::Pg::Database.new('bad_db_name', 'jim', nil, {})
161
161
  }
162
162
 
163
163
  # this corresponds to the test_parse_url_expected_errors test in tc_dbi.rb
164
- assert_raise(DBI::InterfaceError) do
164
+ assert_raises(DBI::InterfaceError) do
165
165
  DBI.connect("dbi:Pg").disconnect
166
166
  end
167
167
 
@@ -197,7 +197,7 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
197
197
 
198
198
  def test_bad_command
199
199
  dbd = get_dbd
200
- assert_raise(DBI::ProgrammingError) {
200
+ assert_raises(DBI::ProgrammingError) {
201
201
  dbd.do("INSERT INTO bad_table (name, age) VALUES('Dave', 12)")
202
202
  }
203
203
  ensure
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+ gem 'test-unit'
1
3
  # figure out what tests to run
2
4
  require 'yaml'
3
5
  require 'test/unit/testsuite'
@@ -17,6 +19,16 @@ module Test::Unit::Assertions
17
19
  end
18
20
  end
19
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
+
20
32
  module DBDConfig
21
33
  @testbase = { }
22
34
  @current_dbtype = nil
@@ -68,6 +80,7 @@ module DBDConfig
68
80
 
69
81
  def self.set_testbase(klass_name, klass)
70
82
  @testbase[klass_name] = klass
83
+ klass.name = klass_name.to_s
71
84
  end
72
85
 
73
86
  def self.suite
@@ -110,7 +123,7 @@ if __FILE__ == $0
110
123
  Dir["dbd/#{dbtype}/test*.rb"].each { |file| require file }
111
124
  # run the general tests
112
125
  DBDConfig.current_dbtype = dbtype.to_sym
113
- Dir["dbd/general/test*.rb"].each { |file| load file; DBDConfig.suite << @class }
126
+ Dir["dbd/general/test*.rb"].each { |file| load file; @class.name = file; DBDConfig.suite << @class }
114
127
  end
115
128
  elsif !config["dbtypes"]
116
129
  warn "Please see test/DBD_TESTS for information on configuring DBD tests."
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: dbd-pg
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.5
7
- date: 2008-11-09 00:00:00 -08:00
6
+ version: 0.3.6
7
+ date: 2008-11-28 00:00:00 -08:00
8
8
  summary: PostgreSQL DBI DBD
9
9
  require_paths:
10
10
  - lib
@@ -41,6 +41,7 @@ files:
41
41
  - test/dbd/postgresql/test_async.rb
42
42
  - test/dbd/postgresql/test_blob.rb
43
43
  - test/dbd/postgresql/test_transactions.rb
44
+ - test/dbd/postgresql/base.rb.new
44
45
  - test/dbd/postgresql/testdbipg.rb
45
46
  - test/dbd/postgresql/up.sql
46
47
  - test/dbd/postgresql/test_ping.rb