Update vendored Sqlite3-ruby to 1.3.0

Also, some tweaks to Maruku.
This commit is contained in:
Jacques Distler 2010-06-10 22:42:33 -05:00
parent 9a80cacc34
commit 4f8759cdf3
55 changed files with 3071 additions and 8028 deletions

View file

@ -8,51 +8,17 @@ class String
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
include Enumerable
# This is any text that followed the first valid SQL statement in the text
# with which the statement was initialized. If there was no trailing text,
# this will be the empty string.
attr_reader :remainder
# The underlying opaque handle used to access the SQLite @driver.
attr_reader :handle
# 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 )
raise ArgumentError, "nil argument passed as sql text" unless sql
@db = db
@driver = @db.driver
@closed = false
@results = @columns = nil
result, @handle, @remainder = @driver.prepare( @db.handle, sql )
Error.check( result, @db )
end
# Closes the statement by finalizing the underlying statement
# handle. The statement must not be used after being closed.
def close
must_be_open!
@closed = true
@driver.finalize( @handle )
end
# Returns true if the underlying statement has been closed.
def closed?
@closed
end
# Binds the given variables to the corresponding placeholders in the SQL
# text.
#
@ -78,42 +44,6 @@ module SQLite3
end
end
# Binds value to the named (or positional) placeholder. If +param+ is a
# Fixnum, it is treated as an index for a positional placeholder.
# Otherwise it is used as the name of the placeholder to bind to.
#
# See also #bind_params.
def bind_param( param, value )
must_be_open!
reset! if active?
if Fixnum === param
case value
when Bignum then
@driver.bind_int64( @handle, param, value )
when Integer then
if value >= (2 ** 31)
@driver.bind_int64( @handle, param, value )
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 )
end
else
param = param.to_s
param = ":#{param}" unless param[0] == ?:
index = @driver.bind_parameter_index( @handle, param )
raise Exception, "no such bind parameter '#{param}'" if index == 0
bind_param index, value
end
end
# Execute the statement. This creates a new ResultSet object for the
# statement's virtual machine. If a block was given, the new ResultSet will
# be yielded to it; otherwise, the ResultSet will be returned.
@ -129,17 +59,13 @@ module SQLite3
#
# See also #bind_params, #execute!.
def execute( *bind_vars )
must_be_open!
reset! if active?
reset! if active? || done?
bind_params(*bind_vars) unless bind_vars.empty?
@results = ResultSet.new( @db, self )
@results = ResultSet.new(@connection, self)
if block_given?
yield @results
else
return @results
end
yield @results if block_given?
@results
end
# Execute the statement. If no block was given, this returns an array of
@ -156,30 +82,15 @@ module SQLite3
# end
#
# See also #bind_params, #execute.
def execute!( *bind_vars )
result = execute( *bind_vars )
rows = [] unless block_given?
while row = result.next
if block_given?
yield row
else
rows << row
end
end
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
def execute!( *bind_vars, &block )
execute(*bind_vars)
block_given? ? each(&block) : to_a
end
# Returns true if the statement is currently active, meaning it has an
# open result set.
def active?
not @results.nil?
!done?
end
# Return an array of the column names for this statement. Note that this
@ -190,11 +101,20 @@ module SQLite3
return @columns
end
def each
loop do
val = step
break self if done?
yield val
end
end
# Return an array of the data types for each column in this statement. Note
# that this may execute the statement in order to obtain the metadata; this
# makes it a (potentially) expensive operation.
def types
get_metadata unless defined?(@types)
must_be_open!
get_metadata unless @types
@types
end
@ -202,15 +122,12 @@ module SQLite3
# that this will actually execute the SQL, which means it can be a
# (potentially) expensive operation.
def get_metadata
must_be_open!
@columns = []
@types = []
column_count = @driver.column_count( @handle )
column_count.times do |column|
@columns << @driver.column_name( @handle, column )
@types << @driver.column_decltype( @handle, column )
@columns << column_name(column)
@types << column_decltype(column)
end
@columns.freeze
@ -221,11 +138,9 @@ module SQLite3
# Performs a sanity check to ensure that the statement is not
# closed. If it is, an exception is raised.
def must_be_open! # :nodoc:
if @closed
if closed?
raise SQLite3::Exception, "cannot use a closed statement"
end
end
end
end