Module: SQLite3::Pragmas

Included in:
Database
Defined in:
lib/sqlite3/pragmas.rb

Overview

This module is intended for inclusion solely by the Database class. It defines convenience methods for the various pragmas supported by SQLite3.

For a detailed description of these pragmas, see the SQLite3 documentation at sqlite.org/pragma.html.

Instance Method Summary collapse

Instance Method Details

#table_info(table, &block) ⇒ Object

:yields: row



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sqlite3/pragmas.rb', line 10

def table_info(table, &block) # :yields: row
  columns, *rows = execute2("PRAGMA table_info(#{table})")

  needs_tweak_default = version_compare(driver.libversion, "3.3.7") > 0

  result = [] unless block_given?
  rows.each do |row|
    new_row = {}
    columns.each_with_index do |name, index|
      new_row[name] = row[index]
    end

    tweak_default(new_row) if needs_tweak_default

    if block_given?
      yield new_row
    else
      result << new_row
    end
  end

  result
end