Class | SQLite3::Driver::Native::Driver |
In: |
lib/sqlite3/driver/native/driver.rb
|
Parent: | Object |
# File lib/sqlite3/driver/native/driver.rb, line 193 193: def self.api_delegate( name ) 194: define_method( name ) { |*args| API.send( "sqlite3_#{name}", *args ) } 195: end
# File lib/sqlite3/driver/native/driver.rb, line 39 39: def initialize 40: @callback_data = Hash.new 41: @authorizer = Hash.new 42: @busy_handler = Hash.new 43: @trace = Hash.new 44: end
# File lib/sqlite3/driver/native/driver.rb, line 112 112: def bind_text( stmt, index, value, utf16=false ) 113: API.send( ( utf16 ? :sqlite3_bind_text16 : :sqlite3_bind_text ), 114: stmt, index, value.to_s ) 115: end
# File lib/sqlite3/driver/native/driver.rb, line 50 50: def busy_handler( db, data=nil, &block ) 51: if block 52: cb = API::CallbackData.new 53: cb.proc = block 54: cb.data = data 55: result = API.sqlite3_busy_handler( db, API::Sqlite3_ruby_busy_handler, cb ) 56: # Reference the Callback object so that 57: # it is not deleted by the GC 58: @busy_handler[db] = cb 59: else 60: # Unreference the callback *after* having removed it 61: # from sqlite 62: result = API.sqlite3_busy_handler( db, nil, nil ) 63: @busy_handler.delete(db) 64: end 65: 66: result 67: end
# File lib/sqlite3/driver/native/driver.rb, line 122 122: def column_decltype( stmt, index, utf16=false ) 123: API.send( 124: ( utf16 ? :sqlite3_column_decltype16 : :sqlite3_column_decltype ), 125: stmt, index ) 126: end
# File lib/sqlite3/driver/native/driver.rb, line 117 117: def column_name( stmt, index, utf16=false ) 118: API.send( ( utf16 ? :sqlite3_column_name16 : :sqlite3_column_name ), 119: stmt, index ) 120: end
# File lib/sqlite3/driver/native/driver.rb, line 128 128: def column_text( stmt, index, utf16=false ) 129: API.send( ( utf16 ? :sqlite3_column_text16 : :sqlite3_column_text ), 130: stmt, index ) 131: end
# File lib/sqlite3/driver/native/driver.rb, line 46 46: def complete?( sql, utf16=false ) 47: API.send( utf16 ? :sqlite3_complete16 : :sqlite3_complete, sql ) != 0 48: end
# File lib/sqlite3/driver/native/driver.rb, line 133 133: def create_function( db, name, args, text, cookie, func, step, final ) 134: if func || ( step && final ) 135: cb = API::CallbackData.new 136: cb.proc = cb.proc2 = nil 137: cb.data = cookie 138: end 139: 140: if func 141: cb.proc = func 142: 143: func = API::Sqlite3_ruby_function_step 144: step = final = nil 145: elsif step && final 146: cb.proc = step 147: cb.proc2 = final 148: 149: func = nil 150: step = API::Sqlite3_ruby_function_step 151: final = API::Sqlite3_ruby_function_final 152: end 153: 154: result = API.sqlite3_create_function( db, name, args, text, cb, func, step, final ) 155: 156: # see comments in busy_handler 157: if cb 158: @callback_data[ name ] = cb 159: else 160: @callback_data.delete( name ) 161: end 162: 163: return result 164: end
# File lib/sqlite3/driver/native/driver.rb, line 103 103: def errmsg( db, utf16=false ) 104: API.send( utf16 ? :sqlite3_errmsg16 : :sqlite3_errmsg, db ) 105: end
# File lib/sqlite3/driver/native/driver.rb, line 99 99: def open( filename, utf16=false ) 100: API.send( utf16 ? :sqlite3_open16 : :sqlite3_open, filename ) 101: end
# File lib/sqlite3/driver/native/driver.rb, line 107 107: def prepare( db, sql, utf16=false ) 108: API.send( ( utf16 ? :sqlite3_prepare16 : :sqlite3_prepare ), 109: db, sql ) 110: end
# File lib/sqlite3/driver/native/driver.rb, line 188 188: def result_error( context, value, utf16=false ) 189: API.send( ( utf16 ? :sqlite3_result_error16 : :sqlite3_result_error ), 190: context, value ) 191: end
# File lib/sqlite3/driver/native/driver.rb, line 177 177: def result_text( context, result, utf16=false ) 178: method = case utf16 179: when nil, false then :sqlite3_result_text 180: when :le then :sqlite3_result_text16le 181: when :be then :sqlite3_result_text16be 182: else :sqlite3_result_text16 183: end 184: 185: API.send( method, context, result.to_s ) 186: end
# File lib/sqlite3/driver/native/driver.rb, line 69 69: def set_authorizer( db, data=nil, &block ) 70: if block 71: cb = API::CallbackData.new 72: cb.proc = block 73: cb.data = data 74: result = API.sqlite3_set_authorizer( db, API::Sqlite3_ruby_authorizer, cb ) 75: @authorizer[db] = cb # see comments in busy_handler 76: else 77: result = API.sqlite3_set_authorizer( db, nil, nil ) 78: @authorizer.delete(db) # see comments in busy_handler 79: end 80: 81: result 82: end
# File lib/sqlite3/driver/native/driver.rb, line 84 84: def trace( db, data=nil, &block ) 85: if block 86: cb = API::CallbackData.new 87: cb.proc = block 88: cb.data = data 89: result = API.sqlite3_trace( db, API::Sqlite3_ruby_trace, cb ) 90: @trace[db] = cb # see comments in busy_handler 91: else 92: result = API.sqlite3_trace( db, nil, nil ) 93: @trace.delete(db) # see comments in busy_handler 94: end 95: 96: result 97: end
# File lib/sqlite3/driver/native/driver.rb, line 166 166: def value_text( value, utf16=false ) 167: method = case utf16 168: when nil, false then :sqlite3_value_text 169: when :le then :sqlite3_value_text16le 170: when :be then :sqlite3_value_text16be 171: else :sqlite3_value_text16 172: end 173: 174: API.send( method, value ) 175: end