Class: SQLite3::Driver::DL::Driver

Class SQLite3::Driver::DL::Driver |
In: | lib/sqlite3/driver/dl/driver.rb
Parent: | Object

Methods

- aggregate_context
- api_delegate
- bind_blob
- bind_text
- busy_handler
- column_blob
- column_decltype
- column_name
- column_text
- commit_hook
- complete?
- create_function
- errmsg
- open
- prepare
- progress_handler
- result_text
- set_authorizer
- trace
- value_blob
- value_text

Constants

STATIC | = | ::DL::PtrData.new(0)
TRANSIENT | = | ::DL::PtrData.new(-1)

Public Class methods
api_delegate( name )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 255
    255:     def self.api_delegate( name )
    256:       define_method( name ) { |*args| API.send( "sqlite3_#{name}", *args ) }
    257:     end

Public Instance methods
aggregate_context( context )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 218
    218:     def aggregate_context( context )
    219:       ptr = API.sqlite3_aggregate_context( context, 4 )
    220:       ptr.free = nil
    221:       obj = ( ptr ? ptr.to_object : nil )
    222:       if obj.nil?
    223:         obj = Hash.new
    224:         ptr.set_object obj
    225:       end
    226:       obj
    227:     end

bind_blob( stmt, index, value )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 229
    229:     def bind_blob( stmt, index, value )
    230:       s = value.to_s
    231:       API.sqlite3_bind_blob( stmt, index, s, s.length, TRANSIENT )
    232:     end

bind_text( stmt, index, value, utf16=false )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 234
    234:     def bind_text( stmt, index, value, utf16=false )
    235:       s = value.to_s
    236:       method = ( utf16 ? :sqlite3_bind_text16 : :sqlite3_bind_text )
    237:       API.send( method, stmt, index, s, s.length, TRANSIENT )
    238:     end

busy_handler( db, data=nil, &block )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 141
    141:     def busy_handler( db, data=nil, &block )
    142:       @busy_handler = block
    143:
    144:       unless @busy_handler_callback
    145:         @busy_handler_callback = ::DL.callback( "IPI" ) do |cookie, timeout|
    146:           @busy_handler.call( cookie, timeout ) || 0
    147:         end
    148:       end
    149:
    150:       API.sqlite3_busy_handler( db, block&&@busy_handler_callback, data )
    151:     end

column_blob( stmt, column )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 123
    123:     def column_blob( stmt, column )
    124:       blob = API.sqlite3_column_blob( stmt, column )
    125:       blob.free = nil
    126:       blob.to_s( API.sqlite3_column_bytes( stmt, column ) )
    127:     end

column_decltype( stmt, column )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 250
    250:     def column_decltype( stmt, column )
    251:       result = API.sqlite3_column_decltype( stmt, column )
    252:       result ? result.to_s : nil
    253:     end

column_name( stmt, column )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 245
    245:     def column_name( stmt, column )
    246:       result = API.sqlite3_column_name( stmt, column )
    247:       result ? result.to_s : nil
    248:     end

column_text( stmt, column )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 240
    240:     def column_text( stmt, column )
    241:       result = API.sqlite3_column_text( stmt, column )
    242:       result ? result.to_s : nil
    243:     end

commit_hook( db, data=nil, &block )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 307
    307:       def commit_hook( db, data=nil, &block )
    308:         @commit_hook_handler = block
    309:
    310:         unless @commit_hook_handler_callback
    311:           @commit_hook_handler_callback = ::DL.callback( "IP" ) do |cookie|
    312:             @commit_hook_handler.call( cookie )
    313:           end
    314:         end
    315:
    316:         API.sqlite3_commit_hook( db, block&&@commit_hook_handler_callback,
    317:           data )
    318:       end

complete?( sql, utf16=false )

[ show source ]

        # File lib/sqlite3/driver/dl/driver.rb, line 95
    95:     def complete?( sql, utf16=false )
    96:       API.send( utf16 ? :sqlite3_complete16 : :sqlite3_complete, sql+"\0" )
    97:     end

create_function( db, name, args, text, cookie, func, step, final )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 180
    180:     def create_function( db, name, args, text, cookie,
    181:       func, step, final )
    182:     # begin
    183:       if @func_handler_callback.nil? && func
    184:         @func_handler_callback = ::DL.callback( "0PIP" ) do |context,nargs,args|
    185:           args = args.to_s(nargs*4).unpack("L*").map {|i| ::DL::PtrData.new(i)}
    186:           data = API.sqlite3_user_data( context ).to_object
    187:           data[:func].call( context, *args )
    188:         end
    189:       end
    190:
    191:       if @step_handler_callback.nil? && step
    192:         @step_handler_callback = ::DL.callback( "0PIP" ) do |context,nargs,args|
    193:           args = args.to_s(nargs*4).unpack("L*").map {|i| ::DL::PtrData.new(i)}
    194:           data = API.sqlite3_user_data( context ).to_object
    195:           data[:step].call( context, *args )
    196:         end
    197:       end
    198:
    199:       if @final_handler_callback.nil? && final
    200:         @final_handler_callback = ::DL.callback( "0P" ) do |context|
    201:           data = API.sqlite3_user_data( context ).to_object
    202:           data[:final].call( context )
    203:         end
    204:       end
    205:
    206:       data = { :cookie => cookie,
    207:                :name => name,
    208:                :func => func,
    209:                :step => step,
    210:                :final => final }
    211:
    212:       API.sqlite3_create_function( db, name, args, text, data,
    213:         ( func ? @func_handler_callback : nil ),
    214:         ( step ? @step_handler_callback : nil ),
    215:         ( final ? @final_handler_callback : nil ) )
    216:     end

errmsg( db, utf16=false )

[ show source ]

        # File lib/sqlite3/driver/dl/driver.rb, line 72
    72:     def errmsg( db, utf16=false )
    73:       if utf16
    74:         msg = API.sqlite3_errmsg16( db )
    75:         msg.free = nil
    76:         msg.to_s(utf16_length(msg))
    77:       else
    78:         API.sqlite3_errmsg( db )
    79:       end
    80:     end

open( filename, utf16=false )

[ show source ]

        # File lib/sqlite3/driver/dl/driver.rb, line 65
    65:     def open( filename, utf16=false )
    66:       handle = ::DL::PtrData.new(0)
    67:       result = API.send( ( utf16 ? :sqlite3_open16 : :sqlite3_open ),
    68:         filename+"\0", handle.ref )
    69:       [ result, handle ]
    70:     end

prepare( db, sql, utf16=false )

[ show source ]

        # File lib/sqlite3/driver/dl/driver.rb, line 82
    82:     def prepare( db, sql, utf16=false )
    83:       handle = ::DL::PtrData.new(0)
    84:       remainder = ::DL::PtrData.new(0)
    85:
    86:       result = API.send( ( utf16 ? :sqlite3_prepare16 : :sqlite3_prepare ),
    87:          db, sql+"\0", sql.length, handle.ref, remainder.ref )
    88:
    89:       args = utf16 ? [ utf16_length(remainder) ] : []
    90:       remainder = remainder.to_s( *args )
    91:
    92:       [ result, handle, remainder ]
    93:     end

progress_handler( db, n, data=nil, &block )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 294
    294:       def progress_handler( db, n, data=nil, &block )
    295:         @progress_handler = block
    296:
    297:         unless @progress_handler_callback
    298:           @progress_handler_callback = ::DL.callback( "IP" ) do |cookie|
    299:             @progress_handler.call( cookie )
    300:           end
    301:         end
    302:
    303:         API.sqlite3_progress_handler( db, n, block&&@progress_handler_callback,
    304:           data )
    305:       end

result_text( func, text, utf16=false )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 129
    129:     def result_text( func, text, utf16=false )
    130:       method = case utf16
    131:         when false, nil then :sqlite3_result_text
    132:         when :le then :sqlite3_result_text16le
    133:         when :be then :sqlite3_result_text16be
    134:         else :sqlite3_result_text16
    135:       end
    136:
    137:       s = text.to_s
    138:       API.send( method, func, s, s.length, TRANSIENT )
    139:     end

set_authorizer( db, data=nil, &block )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 153
    153:     def set_authorizer( db, data=nil, &block )
    154:       @authorizer_handler = block
    155:
    156:       unless @authorizer_handler_callback
    157:         @authorizer_handler_callback = ::DL.callback( "IPIPPPP"
    158:         ) do |cookie,mode,a,b,c,d|
    159:           @authorizer_handler.call( cookie, mode,
    160:             a&&a.to_s, b&&b.to_s, c&&c.to_s, d&&d.to_s ) || 0
    161:         end
    162:       end
    163:
    164:       API.sqlite3_set_authorizer( db, block&&@authorizer_handler_callback,
    165:         data )
    166:     end

trace( db, data=nil, &block )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 168
    168:     def trace( db, data=nil, &block )
    169:       @trace_handler = block
    170:
    171:       unless @trace_handler_callback
    172:         @trace_handler_callback = ::DL.callback( "IPS" ) do |cookie,sql|
    173:           @trace_handler.call( cookie ? cookie.to_object : nil, sql ) || 0
    174:         end
    175:       end
    176:
    177:       API.sqlite3_trace( db, block&&@trace_handler_callback, data )
    178:     end

value_blob( value )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 99
     99:     def value_blob( value )
    100:       blob = API.sqlite3_value_blob( value )
    101:       blob.free = nil
    102:       blob.to_s( API.sqlite3_value_bytes( value ) )
    103:     end

value_text( value, utf16=false )

[ show source ]

         # File lib/sqlite3/driver/dl/driver.rb, line 105
    105:     def value_text( value, utf16=false )
    106:       method = case utf16
    107:         when nil, false then :sqlite3_value_text
    108:         when :le then :sqlite3_value_text16le
    109:         when :be then :sqlite3_value_text16be
    110:         else :sqlite3_value_text16
    111:       end
    112:
    113:       result = API.send( method, value )
    114:       if utf16
    115:         result.free = nil
    116:         size = API.sqlite3_value_bytes( value )
    117:         result = result.to_s( size )
    118:       end
    119:
    120:       result
    121:     end

[Validate]