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

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

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

A symbol signifying the value of the auto_vacuum PRAGMA.

[Source]

    # File lib/sequel/adapters/shared/sqlite.rb, line 15
15:       def auto_vacuum
16:         AUTO_VACUUM[pragma_get(:auto_vacuum).to_i]
17:       end

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 22
22:       def auto_vacuum=(value)
23:         value = AUTO_VACUUM.index(value) || (raise Error, "Invalid value for auto_vacuum option. Please specify one of :none, :full, :incremental.")
24:         pragma_set(:auto_vacuum, value)
25:       end

Boolean signifying the value of the case_sensitive_likePRAGMA, or nil if not using SQLite 3.2.3+.

[Source]

    # File lib/sequel/adapters/shared/sqlite.rb, line 29
29:       def case_sensitive_like
30:         pragma_get(:case_sensitive_like).to_i == 1 if sqlite_version >= 30203
31:       end

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 36
36:       def case_sensitive_like=(value)
37:         pragma_set(:case_sensitive_like, !!value ? 'on' : 'off') if sqlite_version >= 30203
38:       end

SQLite uses the :sqlite database type.

[Source]

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

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 47
47:       def foreign_keys
48:         pragma_get(:foreign_keys).to_i == 1 if sqlite_version >= 30619
49:       end

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 54
54:       def foreign_keys=(value)
55:         pragma_set(:foreign_keys, !!value ? 'on' : 'off') if sqlite_version >= 30619
56:       end

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

[Source]

    # File lib/sequel/adapters/shared/sqlite.rb, line 59
59:       def indexes(table, opts={})
60:         m = output_identifier_meth
61:         im = input_identifier_meth
62:         indexes = {}
63:         begin
64:           metadata_dataset.with_sql("PRAGMA index_list(?)", im.call(table)).each do |r|
65:             next if r[:name] =~ PRIMARY_KEY_INDEX_RE
66:             indexes[m.call(r[:name])] = {:unique=>r[:unique].to_i==1}
67:           end
68:         rescue Sequel::DatabaseError
69:           nil
70:         else
71:           indexes.each do |k, v|
72:             v[:columns] = metadata_dataset.with_sql("PRAGMA index_info(?)", im.call(k)).map(:name).map{|x| m.call(x)}
73:           end
74:         end
75:         indexes
76:       end

Get the value of the given PRAGMA.

[Source]

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

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 89
89:       def pragma_set(name, value)
90:         execute_ddl("PRAGMA #{name} = #{value}")
91:       end

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 95
 95:       def sqlite_version
 96:         return @sqlite_version if defined?(@sqlite_version)
 97:         @sqlite_version = begin
 98:           v = get{sqlite_version{}}
 99:           [10000, 100, 1].zip(v.split('.')).inject(0){|a, m| a + m[0] * Integer(m[1])}
100:         rescue
101:           0
102:         end
103:       end

SQLite supports CREATE TABLE IF NOT EXISTS syntax since 3.3.0.

[Source]

     # File lib/sequel/adapters/shared/sqlite.rb, line 106
106:       def supports_create_table_if_not_exists?
107:         sqlite_version >= 30300
108:       end

SQLite 3.6.8+ supports savepoints.

[Source]

     # File lib/sequel/adapters/shared/sqlite.rb, line 111
111:       def supports_savepoints?
112:         sqlite_version >= 30608
113:       end

A symbol signifying the value of the synchronous PRAGMA.

[Source]

     # File lib/sequel/adapters/shared/sqlite.rb, line 129
129:       def synchronous
130:         SYNCHRONOUS[pragma_get(:synchronous).to_i]
131:       end

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 135
135:       def synchronous=(value)
136:         value = SYNCHRONOUS.index(value) || (raise Error, "Invalid value for synchronous option. Please specify one of :off, :normal, :full.")
137:         pragma_set(:synchronous, value)
138:       end

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 144
144:       def tables(opts={})
145:         tables_and_views(TABLES_FILTER, opts)
146:       end

A symbol signifying the value of the temp_store PRAGMA.

[Source]

     # File lib/sequel/adapters/shared/sqlite.rb, line 149
149:       def temp_store
150:         TEMP_STORE[pragma_get(:temp_store).to_i]
151:       end

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 155
155:       def temp_store=(value)
156:         value = TEMP_STORE.index(value) || (raise Error, "Invalid value for temp_store option. Please specify one of :default, :file, :memory.")
157:         pragma_set(:temp_store, value)
158:       end

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 124
124:       def use_timestamp_timezones?
125:         defined?(@use_timestamp_timezones) ? @use_timestamp_timezones : (@use_timestamp_timezones = true)
126:       end

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 164
164:       def views(opts={})
165:         tables_and_views(VIEWS_FILTER, opts)
166:       end

[Validate]