updated packaged sqlite3-ruby to 1.2.0

This commit is contained in:
Matthias Tarasiewicz 2007-01-16 07:13:14 +00:00
parent 4481c8bdf6
commit d7508a34ab
8 changed files with 69 additions and 19 deletions

View file

@ -109,12 +109,13 @@ module SQLite3
@statement_factory = options[:statement_factory] || Statement @statement_factory = options[:statement_factory] || Statement
result, @handle = @driver.open( file_name, utf16 ) result, @handle = @driver.open( file_name, utf16 )
Error.check( result, nil, "could not open database" ) Error.check( result, self, "could not open database" )
@closed = false @closed = false
@results_as_hash = options.fetch(:results_as_hash,false) @results_as_hash = options.fetch(:results_as_hash,false)
@type_translation = options.fetch(:type_translation,false) @type_translation = options.fetch(:type_translation,false)
@translator = nil @translator = nil
@transaction_active = false
end end
# Return +true+ if the string is a valid (ie, parsable) SQL statement, and # Return +true+ if the string is a valid (ie, parsable) SQL statement, and
@ -436,7 +437,7 @@ module SQLite3
# begin # begin
if block if block
proxy = AggregateDefinitionProxy.new proxy = AggregateDefinitionProxy.new
proxy.instance_eval &block proxy.instance_eval(&block)
step ||= proxy.step_callback step ||= proxy.step_callback
finalize ||= proxy.finalize_callback finalize ||= proxy.finalize_callback
end end
@ -591,7 +592,7 @@ module SQLite3
abort = false abort = false
begin begin
yield self yield self
rescue Exception rescue ::Object
abort = true abort = true
raise raise
ensure ensure

View file

@ -32,6 +32,10 @@
require 'sqlite3/driver/dl/api' require 'sqlite3/driver/dl/api'
warn "The DL driver for sqlite3-ruby is deprecated and will be removed"
warn "in a future release. Please update your installation to use the"
warn "Native driver."
module Kernel module Kernel
# Allows arbitrary objects to be passed as a pointer to functions. # Allows arbitrary objects to be passed as a pointer to functions.
# (Probably not very GC safe, but by encapsulating it like this we # (Probably not very GC safe, but by encapsulating it like this we

View file

@ -38,6 +38,9 @@ module SQLite3 ; module Driver ; module Native
def initialize def initialize
@callback_data = Hash.new @callback_data = Hash.new
@authorizer = Hash.new
@busy_handler = Hash.new
@trace = Hash.new
end end
def complete?( sql, utf16=false ) def complete?( sql, utf16=false )
@ -49,10 +52,18 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new cb = API::CallbackData.new
cb.proc = block cb.proc = block
cb.data = data cb.data = data
result = API.sqlite3_busy_handler( db, API::Sqlite3_ruby_busy_handler, cb )
# Reference the Callback object so that
# it is not deleted by the GC
@busy_handler[db] = cb
else
# Unreference the callback *after* having removed it
# from sqlite
result = API.sqlite3_busy_handler( db, nil, nil )
@busy_handler.delete(db)
end end
API.sqlite3_busy_handler( db, result
block ? API::Sqlite3_ruby_busy_handler : nil, cb )
end end
def set_authorizer( db, data=nil, &block ) def set_authorizer( db, data=nil, &block )
@ -60,10 +71,14 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new cb = API::CallbackData.new
cb.proc = block cb.proc = block
cb.data = data cb.data = data
result = API.sqlite3_set_authorizer( db, API::Sqlite3_ruby_authorizer, cb )
@authorizer[db] = cb # see comments in busy_handler
else
result = API.sqlite3_set_authorizer( db, nil, nil )
@authorizer.delete(db) # see comments in busy_handler
end end
API.sqlite3_set_authorizer( db, result
block ? API::Sqlite3_ruby_authorizer : nil, cb )
end end
def trace( db, data=nil, &block ) def trace( db, data=nil, &block )
@ -71,10 +86,14 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new cb = API::CallbackData.new
cb.proc = block cb.proc = block
cb.data = data cb.data = data
result = API.sqlite3_trace( db, API::Sqlite3_ruby_trace, cb )
@trace[db] = cb # see comments in busy_handler
else
result = API.sqlite3_trace( db, nil, nil )
@trace.delete(db) # see comments in busy_handler
end end
API.sqlite3_trace( db, result
block ? API::Sqlite3_ruby_trace : nil, cb )
end end
def open( filename, utf16=false ) def open( filename, utf16=false )
@ -116,9 +135,6 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new cb = API::CallbackData.new
cb.proc = cb.proc2 = nil cb.proc = cb.proc2 = nil
cb.data = cookie cb.data = cookie
@callback_data[ name ] = cb
else
@callback_data.delete( name )
end end
if func if func
@ -135,7 +151,16 @@ module SQLite3 ; module Driver ; module Native
final = API::Sqlite3_ruby_function_final final = API::Sqlite3_ruby_function_final
end end
API.sqlite3_create_function( db, name, args, text, cb, func, step, final ) result = API.sqlite3_create_function( db, name, args, text, cb, func, step, final )
# see comments in busy_handler
if cb
@callback_data[ name ] = cb
else
@callback_data.delete( name )
end
return result
end end
def value_text( value, utf16=false ) def value_text( value, utf16=false )

View file

@ -91,7 +91,7 @@ module SQLite3
def check( result, db=nil, msg=nil ) def check( result, db=nil, msg=nil )
unless result == Constants::ErrorCode::OK unless result == Constants::ErrorCode::OK
msg = ( msg ? msg + ": " : "" ) + db.errmsg if db msg = ( msg ? msg + ": " : "" ) + db.errmsg if db
raise ( EXCEPTIONS[result] || SQLite3::Exception ), msg raise(( EXCEPTIONS[result] || SQLite3::Exception ), msg)
end end
end end
module_function :check module_function :check

View file

@ -81,6 +81,7 @@ module SQLite3
# can be rewound and reiterated. # can be rewound and reiterated.
def reset( *bind_params ) def reset( *bind_params )
@stmt.must_be_open! @stmt.must_be_open!
@stmt.reset!(false)
@driver.reset( @stmt.handle ) @driver.reset( @stmt.handle )
@stmt.bind_params( *bind_params ) @stmt.bind_params( *bind_params )
@eof = false @eof = false

View file

@ -66,6 +66,7 @@ module SQLite3
@db = db @db = db
@driver = @db.driver @driver = @db.driver
@closed = false @closed = false
@results = @columns = nil
result, @handle, @remainder = @driver.prepare( @db.handle, sql ) result, @handle, @remainder = @driver.prepare( @db.handle, sql )
Error.check( result, @db ) Error.check( result, @db )
end end
@ -115,8 +116,11 @@ module SQLite3
# See also #bind_params. # See also #bind_params.
def bind_param( param, value ) def bind_param( param, value )
must_be_open! must_be_open!
reset! if active?
if Fixnum === param if Fixnum === param
case value case value
when Bignum then
@driver.bind_int64( @handle, param, value )
when Integer then when Integer then
@driver.bind_int( @handle, param, value ) @driver.bind_int( @handle, param, value )
when Numeric then when Numeric then
@ -129,8 +133,9 @@ module SQLite3
@driver.bind_text( @handle, param, value ) @driver.bind_text( @handle, param, value )
end end
else else
index = @driver.bind_parameter_index( param = param.to_s
@handle, 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 raise Exception, "no such bind parameter '#{param}'" if index == 0
bind_param index, value bind_param index, value
end end
@ -152,9 +157,9 @@ module SQLite3
# See also #bind_params, #execute!. # See also #bind_params, #execute!.
def execute( *bind_vars ) def execute( *bind_vars )
must_be_open! must_be_open!
@driver.reset( @handle ) if @results reset! if active?
bind_params *bind_vars unless bind_vars.empty? bind_params(*bind_vars) unless bind_vars.empty?
@results = ResultSet.new( @db, self ) @results = ResultSet.new( @db, self )
if block_given? if block_given?
@ -191,6 +196,19 @@ module SQLite3
rows rows
end 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 # 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 # may execute the statement in order to obtain the metadata; this makes it
# a (potentially) expensive operation. # a (potentially) expensive operation.

View file

@ -81,6 +81,7 @@ module SQLite3
# A convenience method for working with type names. This returns the "base" # A convenience method for working with type names. This returns the "base"
# type name, without any parenthetical data. # type name, without any parenthetical data.
def type_name( type ) def type_name( type )
return "" if type.nil?
type = $1 if type =~ /^(.*?)\(/ type = $1 if type =~ /^(.*?)\(/
type.upcase type.upcase
end end

View file

@ -35,7 +35,7 @@ module SQLite3
module Version module Version
MAJOR = 1 MAJOR = 1
MINOR = 1 MINOR = 2
TINY = 0 TINY = 0
STRING = [ MAJOR, MINOR, TINY ].join( "." ) STRING = [ MAJOR, MINOR, TINY ].join( "." )