dbd-pg 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/dbd/Pg.rb CHANGED
@@ -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.3"
52
+ VERSION = "0.3.4"
53
53
  DESCRIPTION = "PostgreSQL DBI DBD"
54
54
 
55
55
  #
@@ -71,8 +71,7 @@ class DBI::DBD::Pg::Statement < DBI::BaseStatement
71
71
  end
72
72
 
73
73
  def finish
74
- @stmt.clear if @stmt
75
- @result.finish if @result
74
+ internal_finish
76
75
  @result = nil
77
76
  @db = nil
78
77
  end
@@ -123,6 +122,15 @@ class DBI::DBD::Pg::Statement < DBI::BaseStatement
123
122
  end
124
123
  end
125
124
 
125
+ # finish the statement at a lower level
126
+ def internal_finish
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
132
+ end
133
+
126
134
  # prepare the statement at a lower level.
127
135
  def internal_prepare
128
136
  if @db["pg_native_binding"]
@@ -130,7 +138,7 @@ class DBI::DBD::Pg::Statement < DBI::BaseStatement
130
138
  @stmt = @db._prepare(@stmt_name, translate_param_markers(@sql))
131
139
  end
132
140
  else
133
- @stmt.clear if @stmt
141
+ internal_finish
134
142
  @stmt = @db._prepare(@stmt_name, DBI::SQL::PreparedStatement.new(DBI::DBD::Pg, @sql).bind(@bindvars))
135
143
  end
136
144
  @prepared = true
@@ -1,4 +1,13 @@
1
1
  @class = Class.new(DBDConfig.testbase(DBDConfig.current_dbtype)) do
2
+
3
+ def test_execute
4
+ assert_nothing_raised do
5
+ @dbh.execute("select * from names order by age") do |sth|
6
+ assert_equal([["Joe", 19], ["Bob", 21], ["Jim", 30]], sth.fetch_all)
7
+ end
8
+ end
9
+ end
10
+
2
11
  def test_quoting # FIXME breaks sqlite-ruby to a segfault - research
3
12
  @sth = nil
4
13
 
@@ -114,7 +123,7 @@
114
123
  @sth.finish
115
124
  end
116
125
 
117
- def test_execute
126
+ def test_prepare_execute
118
127
  assert_nothing_raised do
119
128
  @sth = @dbh.prepare("select * from names")
120
129
  @sth.execute
@@ -134,7 +143,7 @@
134
143
  end
135
144
  end
136
145
 
137
- def test_execute_with_transactions
146
+ def test_prepare_execute_with_transactions
138
147
  @dbh["AutoCommit"] = false
139
148
  config = DBDConfig.get_config['sqlite3']
140
149
 
@@ -18,6 +18,35 @@ class TestDbdPostgres < DBDConfig.testbase(:postgresql)
18
18
  # dbd.disconnect if dbd
19
19
  # end
20
20
 
21
+ # this monkeypatch is used for the following test... NEVER integrate this into DBI proper.
22
+ class DBI::StatementHandle < DBI::Handle
23
+ def stmt_name
24
+ @handle.instance_variable_get(:@stmt_name)
25
+ end
26
+ end
27
+
28
+ def test_statement_finish_deallocates_sth
29
+ assert_nothing_raised do
30
+ @sth = @dbh.prepare("select * from names")
31
+ @sth.execute
32
+ sth_internal_name = @sth.stmt_name
33
+ assert(sth_internal_name)
34
+ assert(!sth_internal_name.empty?)
35
+ @sth.finish
36
+
37
+ # at this point, the statement name should no longer exist
38
+ #
39
+ # XXX this is a potentially horrible way of doing it since it'll
40
+ # create another prepared statement, but *at this time*, I don't
41
+ # see any drawbacks and the alternative is considerably uglier.
42
+
43
+ @sth = @dbh.prepare("select count(*) from pg_prepared_statements where name = ?")
44
+ @sth.execute(sth_internal_name)
45
+ assert_equal([0], @sth.fetch)
46
+ @sth.finish
47
+ end
48
+ end
49
+
21
50
  def test_binding
22
51
  assert(@dbh["pg_native_binding"])
23
52
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbd-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Hollensbe
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-23 00:00:00 -07:00
13
+ date: 2008-09-02 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency