Class: RDBI::Driver::SQLite3::Statement

Inherits:
Statement
  • Object
show all
Extended by:
MethLab
Defined in:
lib/rdbi/driver/sqlite3.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, dbh) ⇒ Statement

Returns a new instance of Statement.



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/rdbi/driver/sqlite3.rb', line 229

def initialize(query, dbh)
  super

  ep = Epoxy.new(query)
  @index_map = ep.indexed_binds 

  # sanitizes the query of named binds so we can use SQLite3's native
  # binder with our extended syntax. @index_map makes a reappearance in
  # new_execution().
  query = ep.quote(@index_map.compact.inject({}) { |x,y| x.merge({ y => nil }) }) { '?' }

  @handle = check_exception { dbh.handle.prepare(query) }
  @input_type_map  = self.class.input_type_map 
  @output_type_map = self.class.output_type_map

  prep_finalizer { @handle.close unless @handle.closed? }
end

Instance Attribute Details

#handleObject

Returns the value of attribute handle.



217
218
219
# File 'lib/rdbi/driver/sqlite3.rb', line 217

def handle
  @handle
end

Class Method Details

.input_type_mapObject



220
221
222
# File 'lib/rdbi/driver/sqlite3.rb', line 220

def input_type_map  
  @input_type_map  ||= RDBI::Type.create_type_hash(RDBI::Type::In)
end

.output_type_mapObject



224
225
226
# File 'lib/rdbi/driver/sqlite3.rb', line 224

def output_type_map
  @output_type_map ||= RDBI::Type.create_type_hash(RDBI::Type::Out)
end

Instance Method Details

#new_execution(*binds) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/rdbi/driver/sqlite3.rb', line 255

def new_execution(*binds)
  binds = RDBI::Util.index_binds(binds, @index_map)

  rs = check_exception { @handle.execute(*binds) }

  # FIXME type management
  columns = rs.columns.zip(rs.types)
  columns.collect! do |col|
    newcol = RDBI::Column.new
    newcol.name = col[0].to_sym
    newcol.type = col[1]
    newcol.ruby_type = (col[1].to_sym rescue nil)
    newcol
  end

  this_schema = RDBI::Schema.new
  this_schema.columns = columns

  return Cursor.new(rs), this_schema, @output_type_map
end

#new_modification(*binds) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/rdbi/driver/sqlite3.rb', line 247

def new_modification(*binds)
  binds = RDBI::Util.index_binds(binds, @index_map) 

  rs = check_exception { @handle.execute(*binds) }

  return 0
end