Module: Lich::SQLiteBusyWait::Statement

Defined in:
documented/common/sqlite_connection.rb

Overview

Prepended to SQLite3::Statement. Only statements on marked connections change behaviour.

Instance Method Summary collapse

Instance Method Details

#close ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Closes the statement and removes it from its connection's open statement tracking.



264
265
266
267
268
# File 'documented/common/sqlite_connection.rb', line 264

def close
  super
ensure
  @connection.__send__(:release_open_statement, self) if @connection.is_a?(Connection)
end

#initialize(db, *args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares a statement with interrupts deferred and registers it for tracking. If the connection is a SerializedDatabase, preparation runs under its Monitor. Only connections marked with the Connection module go through this wrapper; unmarked connections skip it.

Parameters:

  • db (SQLite3::Database) —

    the connection to prepare the statement on

  • args (Array) —

    arguments passed to the wrapped initialize method



237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'documented/common/sqlite_connection.rb', line 237

def initialize(db, *args)
  unless db.is_a?(Connection)
    super
    return
  end

  monitor = db.instance_variable_get(:@lich_monitor) if db.is_a?(SerializedDatabase)
  if monitor
    monitor.synchronize { prepare_on_connection(db, monitor) { super } }
  else
    prepare_on_connection(db, nil) { super }
  end
end

#step ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Steps the statement with interrupts deferred to prevent GVL deadlock during lock waits. Only statements on connections marked with the Connection module defer interrupts; others pass through unchanged.



255
256
257
258
259
# File 'documented/common/sqlite_connection.rb', line 255

def step
  return super unless @connection.is_a?(Connection)

  SQLiteBusyWait.wait_uninterrupted { super }
end