Class: ActiveRecord::ConnectionAdapters::SQLiteAdapter::StatementPool

Inherits:
ActiveRecord::ConnectionAdapters::StatementPool show all
Defined in:
activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

Instance Method Summary collapse

Methods inherited from ActiveRecord::ConnectionAdapters::StatementPool

#delete

Methods included from Enumerable

#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum

Constructor Details

#initialize(connection, max) ⇒ StatementPool

Returns a new instance of StatementPool.



54
55
56
57
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 54

def initialize(connection, max)
  super
  @cache = Hash.new { |h,pid| h[pid] = {} }
end

Instance Method Details

#[](key) ⇒ Object



61
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 61

def [](key);      cache[key]; end

#[]=(sql, key) ⇒ Object



64
65
66
67
68
69
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 64

def []=(sql, key)
  while @max <= cache.size
    dealloc(cache.shift.last[:stmt])
  end
  cache[sql] = key
end

#clearObject



71
72
73
74
75
76
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 71

def clear
  cache.values.each do |hash|
    dealloc hash[:stmt]
  end
  cache.clear
end

#each(&block) ⇒ Object



59
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 59

def each(&block); cache.each(&block); end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


60
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 60

def key?(key);    cache.key?(key); end

#lengthObject



62
# File 'activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb', line 62

def length;       cache.length; end