summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2007-01-13 21:09:22 +0000
committerJamis Buck <jamis@37signals.com>2007-01-13 21:09:22 +0000
commitc89ab08e95116ac464bb3cd8612f46dfdf080be3 (patch)
treeb9a1837f4cb681b234fee05e02052a5f213bce39 /lib
parentd6c84ceba976741e7a038151967c0587b8f22a16 (diff)
downloadthird_party-sqlite3-ruby-c89ab08e95116ac464bb3cd8612f46dfdf080be3.tar.gz
third_party-sqlite3-ruby-c89ab08e95116ac464bb3cd8612f46dfdf080be3.tar.xz
third_party-sqlite3-ruby-c89ab08e95116ac464bb3cd8612f46dfdf080be3.zip
reset the statement when binding new variables (thanks Mike Kusick, debian bug #405614)
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlite3/resultset.rb1
-rw-r--r--lib/sqlite3/statement.rb16
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlite3/resultset.rb b/lib/sqlite3/resultset.rb
index d90073c..ed2cb58 100644
--- a/lib/sqlite3/resultset.rb
+++ b/lib/sqlite3/resultset.rb
@@ -81,6 +81,7 @@ module SQLite3
# can be rewound and reiterated.
def reset( *bind_params )
@stmt.must_be_open!
+ @stmt.reset!(false)
@driver.reset( @stmt.handle )
@stmt.bind_params( *bind_params )
@eof = false
diff --git a/lib/sqlite3/statement.rb b/lib/sqlite3/statement.rb
index 54faf15..09f24d9 100644
--- a/lib/sqlite3/statement.rb
+++ b/lib/sqlite3/statement.rb
@@ -116,6 +116,7 @@ module SQLite3
# See also #bind_params.
def bind_param( param, value )
must_be_open!
+ reset! if active?
if Fixnum === param
case value
when Bignum then
@@ -156,7 +157,7 @@ module SQLite3
# See also #bind_params, #execute!.
def execute( *bind_vars )
must_be_open!
- @driver.reset( @handle ) if @results
+ reset! if active?
bind_params(*bind_vars) unless bind_vars.empty?
@results = ResultSet.new( @db, self )
@@ -195,6 +196,19 @@ module SQLite3
rows
end
+ # Resets the statement. This is typically done internally, though it might
+ # occassionally be necessary to manually reset the statement.
+ def reset!(clear_result=true)
+ @driver.reset(@handle)
+ @results = nil if clear_result
+ end
+
+ # Returns true if the statement is currently active, meaning it has an
+ # open result set.
+ def active?
+ not @results.nil?
+ end
+
# Return an array of the column names for this statement. Note that this
# may execute the statement in order to obtain the metadata; this makes it
# a (potentially) expensive operation.