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.
Constant Summary collapse
- SYNCHRONOUS_MODES =
The enumeration of valid synchronous modes.
[ [ "full", 2 ], [ "normal", 1 ], [ "off", 0 ] ]
- TEMP_STORE_MODES =
The enumeration of valid temp store modes.
[ [ "default", 0 ], [ "file", 1 ], [ "memory", 2 ] ]
Instance Method Summary collapse
- #auto_vacuum ⇒ Object
- #auto_vacuum=(mode) ⇒ Object
- #cache_size ⇒ Object
- #cache_size=(size) ⇒ Object
-
#database_list(&block) ⇒ Object
:yields: row.
- #default_cache_size ⇒ Object
- #default_cache_size=(size) ⇒ Object
- #default_synchronous ⇒ Object
- #default_synchronous=(mode) ⇒ Object
- #default_temp_store ⇒ Object
- #default_temp_store=(mode) ⇒ Object
-
#foreign_key_list(table, &block) ⇒ Object
:yields: row.
- #full_column_names ⇒ Object
- #full_column_names=(mode) ⇒ Object
-
#index_info(index, &block) ⇒ Object
:yields: row.
-
#index_list(table, &block) ⇒ Object
:yields: row.
-
#integrity_check ⇒ Object
Does an integrity check on the database.
- #parser_trace ⇒ Object
- #parser_trace=(mode) ⇒ Object
- #schema_cookie ⇒ Object
- #schema_cookie=(cookie) ⇒ Object
- #synchronous ⇒ Object
- #synchronous=(mode) ⇒ Object
-
#table_info(table, &block) ⇒ Object
:yields: row.
- #temp_store ⇒ Object
- #temp_store=(mode) ⇒ Object
- #user_cookie ⇒ Object
- #user_cookie=(cookie) ⇒ Object
- #vdbe_trace ⇒ Object
- #vdbe_trace=(mode) ⇒ Object
Instance Method Details
#auto_vacuum ⇒ Object
103 104 105 |
# File 'lib/sqlite3/pragmas.rb', line 103 def auto_vacuum get_boolean_pragma "auto_vacuum" end |
#auto_vacuum=(mode) ⇒ Object
107 108 109 |
# File 'lib/sqlite3/pragmas.rb', line 107 def auto_vacuum=(mode) set_boolean_pragma "auto_vacuum", mode end |
#cache_size ⇒ Object
127 128 129 |
# File 'lib/sqlite3/pragmas.rb', line 127 def cache_size get_int_pragma "cache_size" end |
#cache_size=(size) ⇒ Object
131 132 133 |
# File 'lib/sqlite3/pragmas.rb', line 131 def cache_size=(size) set_int_pragma "cache_size", size end |
#database_list(&block) ⇒ Object
:yields: row
199 200 201 |
# File 'lib/sqlite3/pragmas.rb', line 199 def database_list(&block) # :yields: row get_query_pragma "database_list", &block end |
#default_cache_size ⇒ Object
135 136 137 |
# File 'lib/sqlite3/pragmas.rb', line 135 def default_cache_size get_int_pragma "default_cache_size" end |
#default_cache_size=(size) ⇒ Object
139 140 141 |
# File 'lib/sqlite3/pragmas.rb', line 139 def default_cache_size=(size) set_int_pragma "default_cache_size", size end |
#default_synchronous ⇒ Object
143 144 145 |
# File 'lib/sqlite3/pragmas.rb', line 143 def default_synchronous get_enum_pragma "default_synchronous" end |
#default_synchronous=(mode) ⇒ Object
147 148 149 |
# File 'lib/sqlite3/pragmas.rb', line 147 def default_synchronous=(mode) set_enum_pragma "default_synchronous", mode, SYNCHRONOUS_MODES end |
#default_temp_store ⇒ Object
159 160 161 |
# File 'lib/sqlite3/pragmas.rb', line 159 def default_temp_store get_enum_pragma "default_temp_store" end |
#default_temp_store=(mode) ⇒ Object
163 164 165 |
# File 'lib/sqlite3/pragmas.rb', line 163 def default_temp_store=(mode) set_enum_pragma "default_temp_store", mode, TEMP_STORE_MODES end |
#foreign_key_list(table, &block) ⇒ Object
:yields: row
203 204 205 |
# File 'lib/sqlite3/pragmas.rb', line 203 def foreign_key_list(table, &block) # :yields: row get_query_pragma "foreign_key_list", table, &block end |
#full_column_names ⇒ Object
175 176 177 |
# File 'lib/sqlite3/pragmas.rb', line 175 def full_column_names get_boolean_pragma "full_column_names" end |
#full_column_names=(mode) ⇒ Object
179 180 181 |
# File 'lib/sqlite3/pragmas.rb', line 179 def full_column_names=(mode) set_boolean_pragma "full_column_names", mode end |
#index_info(index, &block) ⇒ Object
:yields: row
207 208 209 |
# File 'lib/sqlite3/pragmas.rb', line 207 def index_info(index, &block) # :yields: row get_query_pragma "index_info", index, &block end |
#index_list(table, &block) ⇒ Object
:yields: row
211 212 213 |
# File 'lib/sqlite3/pragmas.rb', line 211 def index_list(table, &block) # :yields: row get_query_pragma "index_list", table, &block end |
#integrity_check ⇒ Object
Does an integrity check on the database. If the check fails, a SQLite3::Exception will be raised. Otherwise it returns silently.
97 98 99 100 101 |
# File 'lib/sqlite3/pragmas.rb', line 97 def integrity_check execute("PRAGMA integrity_check") do |row| raise Exception, row[0] if row[0] != "ok" end end |
#parser_trace ⇒ Object
183 184 185 |
# File 'lib/sqlite3/pragmas.rb', line 183 def parser_trace get_boolean_pragma "parser_trace" end |
#parser_trace=(mode) ⇒ Object
187 188 189 |
# File 'lib/sqlite3/pragmas.rb', line 187 def parser_trace=(mode) set_boolean_pragma "parser_trace", mode end |
#schema_cookie ⇒ Object
111 112 113 |
# File 'lib/sqlite3/pragmas.rb', line 111 def get_int_pragma "schema_cookie" end |
#schema_cookie=(cookie) ⇒ Object
115 116 117 |
# File 'lib/sqlite3/pragmas.rb', line 115 def () set_int_pragma "schema_cookie", end |
#synchronous ⇒ Object
151 152 153 |
# File 'lib/sqlite3/pragmas.rb', line 151 def synchronous get_enum_pragma "synchronous" end |
#synchronous=(mode) ⇒ Object
155 156 157 |
# File 'lib/sqlite3/pragmas.rb', line 155 def synchronous=(mode) set_enum_pragma "synchronous", mode, SYNCHRONOUS_MODES end |
#table_info(table, &block) ⇒ Object
:yields: row
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/sqlite3/pragmas.rb', line 215 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 |
#temp_store ⇒ Object
167 168 169 |
# File 'lib/sqlite3/pragmas.rb', line 167 def temp_store get_enum_pragma "temp_store" end |
#temp_store=(mode) ⇒ Object
171 172 173 |
# File 'lib/sqlite3/pragmas.rb', line 171 def temp_store=(mode) set_enum_pragma "temp_store", mode, TEMP_STORE_MODES end |
#user_cookie ⇒ Object
119 120 121 |
# File 'lib/sqlite3/pragmas.rb', line 119 def get_int_pragma "user_cookie" end |
#user_cookie=(cookie) ⇒ Object
123 124 125 |
# File 'lib/sqlite3/pragmas.rb', line 123 def () set_int_pragma "user_cookie", end |
#vdbe_trace ⇒ Object
191 192 193 |
# File 'lib/sqlite3/pragmas.rb', line 191 def vdbe_trace get_boolean_pragma "vdbe_trace" end |
#vdbe_trace=(mode) ⇒ Object
195 196 197 |
# File 'lib/sqlite3/pragmas.rb', line 195 def vdbe_trace=(mode) set_boolean_pragma "vdbe_trace", mode end |