Module: TableRenamable::ConnectionAdapters::SQLite3Adapter

Extended by:
ActiveSupport::Concern
Defined in:
lib/table_renamable/connection_adapters/sqlite3_adapter.rb

Instance Method Summary collapse

Instance Method Details

#exec_query_with_table_renamable(*args, &block) ⇒ Object



14
15
16
17
18
# File 'lib/table_renamable/connection_adapters/sqlite3_adapter.rb', line 14

def exec_query_with_table_renamable(*args, &block)
  self.with_retry do
    self.exec_query_without_table_renamable(*args, &block)
  end
end

#execute_with_table_renamable(*args, &block) ⇒ type

Override execute to reload database info

Parameters:

  • *args (Array<Mixed>)

    Just here so we can call super

Returns:

  • (type)
    description


25
26
27
28
29
# File 'lib/table_renamable/connection_adapters/sqlite3_adapter.rb', line 25

def execute_with_table_renamable(*args, &block)
  self.with_retry do
    self.execute_without_table_renamable(*args, &block)
  end
end

#table_structure_with_table_renamable(table_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/table_renamable/connection_adapters/sqlite3_adapter.rb', line 31

def table_structure_with_table_renamable(table_name)
  self.with_retry do
    # get the correct table name to check - otherwise this will fail
    # on retry
    current_table_name = TableRenamable::Model.get_current_table_name(
      table_name
    )
    self.table_structure_without_table_renamable(current_table_name)
  end
end

#with_retry(&block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/table_renamable/connection_adapters/sqlite3_adapter.rb', line 43

def with_retry(&block)
  # set up tries so we don't keep retrying
  tries = 0
  begin
    tries += 1
    # call the actual execute behavior
    yield
  rescue ActiveRecord::StatementInvalid => e
    # only try once
    raise e if tries > 1
    # re-raise if it's not an error we care about
    raise e unless e.message =~ /Could not find table/
    # otherwise we reload and retry
    TableRenamable::Model.reload_tables
    retry
  end
end