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
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
@results_as_hash = options.fetch(:results_as_hash,false)
@type_translation = options.fetch(:type_translation,false)
@translator = nil
@transaction_active = false
end
# Return +true+ if the string is a valid (ie, parsable) SQL statement, and
@ -436,7 +437,7 @@ module SQLite3
# begin
if block
proxy = AggregateDefinitionProxy.new
proxy.instance_eval &block
proxy.instance_eval(&block)
step ||= proxy.step_callback
finalize ||= proxy.finalize_callback
end
@ -591,7 +592,7 @@ module SQLite3
abort = false
begin
yield self
rescue Exception
rescue ::Object
abort = true
raise
ensure

View file

@ -32,6 +32,10 @@
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
# Allows arbitrary objects to be passed as a pointer to functions.
# (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
@callback_data = Hash.new
@authorizer = Hash.new
@busy_handler = Hash.new
@trace = Hash.new
end
def complete?( sql, utf16=false )
@ -49,10 +52,18 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new
cb.proc = block
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
API.sqlite3_busy_handler( db,
block ? API::Sqlite3_ruby_busy_handler : nil, cb )
result
end
def set_authorizer( db, data=nil, &block )
@ -60,10 +71,14 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new
cb.proc = block
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
API.sqlite3_set_authorizer( db,
block ? API::Sqlite3_ruby_authorizer : nil, cb )
result
end
def trace( db, data=nil, &block )
@ -71,10 +86,14 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new
cb.proc = block
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
API.sqlite3_trace( db,
block ? API::Sqlite3_ruby_trace : nil, cb )
result
end
def open( filename, utf16=false )
@ -116,9 +135,6 @@ module SQLite3 ; module Driver ; module Native
cb = API::CallbackData.new
cb.proc = cb.proc2 = nil
cb.data = cookie
@callback_data[ name ] = cb
else
@callback_data.delete( name )
end
if func
@ -135,7 +151,16 @@ module SQLite3 ; module Driver ; module Native
final = API::Sqlite3_ruby_function_final
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
def value_text( value, utf16=false )

View file

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

View file

@ -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

View file

@ -66,6 +66,7 @@ module SQLite3
@db = db
@driver = @db.driver
@closed = false
@results = @columns = nil
result, @handle, @remainder = @driver.prepare( @db.handle, sql )
Error.check( result, @db )
end
@ -115,8 +116,11 @@ 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
@driver.bind_int64( @handle, param, value )
when Integer then
@driver.bind_int( @handle, param, value )
when Numeric then
@ -129,8 +133,9 @@ module SQLite3
@driver.bind_text( @handle, param, value )
end
else
index = @driver.bind_parameter_index(
@handle, param.to_s )
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
@ -152,9 +157,9 @@ 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?
bind_params(*bind_vars) unless bind_vars.empty?
@results = ResultSet.new( @db, self )
if block_given?
@ -191,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.

View file

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

View file

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