lib/sqlite3/statement.rb in sqlite3-0.0.2 vs lib/sqlite3/statement.rb in sqlite3-0.0.3
- old
+ new
@@ -1,20 +1,7 @@
-require "sqlite3/errors"
-require "sqlite3/resultset"
-
-class String
- def to_blob
- SQLite3::Blob.new(self)
- end
-end
-
module SQLite3
- # A class for differentiating between strings and blobs, when binding them
- # into statements.
- class Blob < String; end
-
# A statement represents a prepared-but-unexecuted SQL query. It will rarely
# (if ever) be instantiated directly by a client, and is most often obtained
# via the Database#prepare method.
class Statement
@@ -28,16 +15,17 @@
# Create a new statement attached to the given Database instance, and which
# encapsulates the given SQL text. If the text contains more than one
# statement (i.e., separated by semicolons), then the #remainder property
# will be set to the trailing text.
- def initialize(db, sql, utf16 = false)
+ def initialize(db, sql, utf_16 = false)
raise ArgumentError, "nil argument passed as sql text" unless sql
@db = db
@driver = @db.driver
@closed = false
@results = @columns = nil
+ @utf_16 = utf_16
result, @handle, @remainder = @driver.prepare(@db.handle, sql)
Error.check(result, @db)
end
# Closes the statement by finalizing the underlying statement
@@ -96,16 +84,14 @@
else
@driver.bind_int(@handle, param, value)
end
when Numeric then
@driver.bind_double(@handle, param, value.to_f)
- when Blob then
- @driver.bind_blob(@handle, param, value)
when nil then
@driver.bind_null(@handle, param)
else
- @driver.bind_text(@handle, param, value)
+ @driver.bind_string(@handle, param, value.to_s)
end
else
param = param.to_s
param = ":#{param}" unless param[0] == ?:
index = @driver.bind_parameter_index(@handle, param)
@@ -131,10 +117,10 @@
def execute(*bind_vars)
must_be_open!
reset! if active?
bind_params(*bind_vars) unless bind_vars.empty?
- @results = ResultSet.new(@db, self)
+ @results = ResultSet.new(@db, self, @utf_16)
if block_given?
yield @results
else
return @results