Class: SQLite3::Driver::Native::Driver

Inherits:
Object
  • Object
show all
Includes:
CS_SQLite3
Defined in:
lib/sqlite3/driver/native/driver.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDriver

Returns a new instance of Driver.



12
13
14
15
16
17
# File 'lib/sqlite3/driver/native/driver.rb', line 12

def initialize
  @callback_data = Hash.new
  @authorizer = Hash.new
  @busy_handler = Hash.new
  @trace = Hash.new
end

Class Method Details

.api_delegate(name) ⇒ Object



121
122
123
# File 'lib/sqlite3/driver/native/driver.rb', line 121

def self.api_delegate( name )
  eval "def #{name} (*args) ; CSSQLite.sqlite3_#{name}( *args ) ; end"
end

Instance Method Details

#aggregate_context(context, n = 0) ⇒ Object



113
114
115
# File 'lib/sqlite3/driver/native/driver.rb', line 113

def aggregate_context( context, n = 0)
  CSSQLite.sqlite3_aggregate_context( context, n ).to_a
end

#bind_text(stmt, index, value, utf16 = false) ⇒ Object



31
32
33
# File 'lib/sqlite3/driver/native/driver.rb', line 31

def bind_text( stmt, index, value, utf16=false )
  CSSQLite.sqlite3_bind_text( stmt, index, value.to_s, -1, nil )
end

#complete?(sql, utf16 = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/sqlite3/driver/native/driver.rb', line 19

def complete?( sql, utf16=false )
  CSSQLite.sqlite3_complete(sql) != 0
end

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

def busy_handler( db, data=nil, &block )

if block
  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

result

end

def set_authorizer( db, data=nil, &block )

if block
  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

result

end

def trace( db, data=nil, &block )

if block
  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

result

end



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sqlite3/driver/native/driver.rb', line 84

def create_function( db, name, args, text, cookie, func, step, final )
  if func || ( step && final )
    cb = CallbackData.new
    cb.proc = cb.proc2 = nil
    cb.data = cookie
  end

  if func
    cb.proc = func
    step = final = nil
  elsif step && final
    cb.proc = step
    cb.proc2 = final

    func = nil
  end

  result = CSSQLite.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

#open(filename) ⇒ Object



23
24
25
# File 'lib/sqlite3/driver/native/driver.rb', line 23

def open(filename)
  CSSQLite.sqlite3_open( filename, nil )
end

#prepare(db, sql) ⇒ Object



27
28
29
# File 'lib/sqlite3/driver/native/driver.rb', line 27

def prepare(db, sql)
  CSSQLite.sqlite3_prepare( db, sql, -1, nil, nil )
end

#result_text(context, result, utf16 = false) ⇒ Object



117
118
119
# File 'lib/sqlite3/driver/native/driver.rb', line 117

def result_text( context, result, utf16=false )
  CSSQLite.sqlite3_result_text( context, result.to_s, -1, nil )
end