Module | Sequel::SQLite::DatabaseMethods
In: | lib/sequel/adapters/shared/sqlite.rb

No matter how you connect to SQLite, the following Database options can be used to set PRAGMAs on connections in a thread-safe manner: :auto_vacuum, :foreign_keys, :synchronous, and :temp_store.

### Methods

auto_vacuum auto_vacuum= case_sensitive_like= database_type foreign_key_list foreign_keys foreign_keys= indexes pragma_get pragma_set set_integer_booleans sqlite_version supports_create_table_if_not_exists? supports_savepoints? synchronous synchronous= tables temp_store temp_store= use_timestamp_timezones? views

### Constants

AUTO_VACUUM | = | [:none, :full, :incremental].freeze
PRIMARY_KEY_INDEX_RE | = | /\Asqlite_autoindex_/.freeze
SYNCHRONOUS | = | [:off, :normal, :full].freeze
TABLES_FILTER | = | "type = 'table' AND NOT name = 'sqlite_sequence'".freeze
TEMP_STORE | = | [:default, :file, :memory].freeze
VIEWS_FILTER | = | "type = 'view'".freeze

### Attributes

integer_booleans | [RW] | Whether to use integers for booleans in the database. SQLite recommends booleans be stored as integers, but historically Sequel has used ‘t’/’f’.
use_timestamp_timezones | [W] | Override the default setting for whether to use timezones in timestamps. For backwards compatibility, it is set to `true` by default. Anyone wanting to use SQLite‘s datetime functions should set it to `false` using this method. It‘s possible that the default will change in a future version, so anyone relying on timezones in timestamps should set this to `true`.

### Public Instance methods

auto_vacuum()

A symbol signifying the value of the auto_vacuum PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 19
    19:       def auto_vacuum
    20:         AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
    21:       end

auto_vacuum=(value)

Set the auto_vacuum PRAGMA using the given symbol (:none, :full, or :incremental). See pragma_set. Consider using the :auto_vacuum Database option instead.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 26
    26:       def auto_vacuum=(value)
    27:         value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
    28:         pragma_set(:auto_vacuum, value)
    29:       end

case_sensitive_like=(value)

Set the case_sensitive_like PRAGMA using the given boolean value, if using SQLite 3.2.3+. If not using 3.2.3+, no error is raised. See pragma_set. Consider using the :case_sensitive_like Database option instead.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 34
    34:       def case_sensitive_like=(value)
    35:         pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
    36:       end

database_type()

SQLite uses the :sqlite database type.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 39
    39:       def database_type
    40:         :sqlite
    41:       end

foreign_key_list(table, opts={})

Return the array of foreign key info hashes using the foreign_key_list PRAGMA, including information for the :on_update and :on_delete entries.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 58
    58:       def foreign_key_list(table, opts={})
    59:         m = output_identifier_meth
    60:         h = {}
    61:         metadata_dataset.with_sql("PRAGMA foreign_key_list(?)", input_identifier_meth.call(table)).each do |row|
    62:           if r = h[row[:id]]
    63:             r[:columns] << m.call(row[:from])
    64:             r[:key] << m.call(row[:to]) if r[:key]
    65:           else
    66:             h[row[:id]] = {:columns=>[m.call(row[:from])], :table=>m.call(row[:table]), :key=>([m.call(row[:to])] if row[:to]), :on_update=>on_delete_sql_to_sym(row[:on_update]), :on_delete=>on_delete_sql_to_sym(row[:on_delete])}
    67:           end
    68:         end
    69:         h.values
    70:       end

foreign_keys()

Boolean signifying the value of the foreign_keys PRAGMA, or nil if not using SQLite 3.6.19+.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 45
    45:       def foreign_keys
    46:         pragma_get(:foreign_keys).to_i == 1 if sqlite_version >= 30619
    47:       end

foreign_keys=(value)

Set the foreign_keys PRAGMA using the given boolean value, if using SQLite 3.6.19+. If not using 3.6.19+, no error is raised. See pragma_set. Consider using the :foreign_keys Database option instead.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 52
    52:       def foreign_keys=(value)
    53:         pragma_set(:foreign_keys, !!value ? 'on' : 'off') if sqlite_version >= 30619
    54:       end

indexes(table, opts={})

Use the index_list and index_info PRAGMAs to determine the indexes on the table.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 73
    73:       def indexes(table, opts={})
    74:         m = output_identifier_meth
    75:         im = input_identifier_meth
    76:         indexes = {}
    77:         metadata_dataset.with_sql("PRAGMA index_list(?)", im.call(table)).each do |r|
    78:           next if r[:name] =~ PRIMARY_KEY_INDEX_RE
    79:           indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1}
    80:         end
    81:         indexes.each do |k, v|
    82:           v[:columns] = metadata_dataset.with_sql("PRAGMA index_info(?)", im.call(k)).map(:name).map{|x| m.call(x)}
    83:         end
    84:         indexes
    85:       end

pragma_get(name)

Get the value of the given PRAGMA.

[Source]

        # File lib/sequel/adapters/shared/sqlite.rb, line 88
    88:       def pragma_get(name)
    89:         self["PRAGMA #{name}"].single_value
    90:       end

pragma_set(name, value)

Set the value of the given PRAGMA to value.

This method is not thread safe, and will not work correctly if there are multiple connections in the Database‘s connection pool. PRAGMA modifications should be done when the connection is created, using an option provided when creating the Database object.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 98
     98:       def pragma_set(name, value)
     99:         execute_ddl("PRAGMA #{name} = #{value}")
    100:       end

set_integer_booleans()

Set the integer_booleans option using the passed in :integer_boolean option.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 103
    103:       def set_integer_booleans
    104:         @integer_booleans = typecast_value_boolean(@opts[:integer_booleans])
    105:       end

sqlite_version()

The version of the server as an integer, where 3.6.19 = 30619. If the server version can‘t be determined, 0 is used.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 109
    109:       def sqlite_version
    110:         return @sqlite_version if defined?(@sqlite_version)
    111:         @sqlite_version = begin
    112:           v = get{sqlite_version{}}
    113:           [10000, 100, 1].zip(v.split('.')).inject(0){|a, m| a + m[0] * Integer(m[1])}
    114:         rescue
    115:           0
    116:         end
    117:       end

supports_create_table_if_not_exists?()

SQLite supports CREATE TABLE IF NOT EXISTS syntax since 3.3.0.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 120
    120:       def supports_create_table_if_not_exists?
    121:         sqlite_version >= 30300
    122:       end

supports_savepoints?()

SQLite 3.6.8+ supports savepoints.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 125
    125:       def supports_savepoints?
    126:         sqlite_version >= 30608
    127:       end

synchronous()

A symbol signifying the value of the synchronous PRAGMA.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 143
    143:       def synchronous
    144:         SYNCHRONOUS[pragma_get(:synchronous).to_i]
    145:       end

synchronous=(value)

Set the synchronous PRAGMA using the given symbol (:off, :normal, or :full). See pragma_set. Consider using the :synchronous Database option instead.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 149
    149:       def synchronous=(value)
    150:         value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
    151:         pragma_set(:synchronous, value)
    152:       end

tables(opts={})

Array of symbols specifying the table names in the current database.

Options:

- :server - Set the server to use.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 158
    158:       def tables(opts={})
    159:         tables_and_views(TABLES_FILTER, opts)
    160:       end

temp_store()

A symbol signifying the value of the temp_store PRAGMA.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 163
    163:       def temp_store
    164:         TEMP_STORE[pragma_get(:temp_store).to_i]
    165:       end

temp_store=(value)

Set the temp_store PRAGMA using the given symbol (:default, :file, or :memory). See pragma_set. Consider using the :temp_store Database option instead.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 169
    169:       def temp_store=(value)
    170:         value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
    171:         pragma_set(:temp_store, value)
    172:       end

use_timestamp_timezones?()

SQLite supports timezones in timestamps, since it just stores them as strings, but it breaks the usage of SQLite‘s datetime functions.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 138
    138:       def use_timestamp_timezones?
    139:         defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = true)
    140:       end

views(opts={})

Array of symbols specifying the view names in the current database.

Options:

- :server - Set the server to use.

[Source]

         # File lib/sequel/adapters/shared/sqlite.rb, line 178
    178:       def views(opts={})
    179:         tables_and_views(VIEWS_FILTER, opts)
    180:       end

[Validate]